Product Overview
This product is a 2.42inch display expansion module, compatible with Raspberry Pi series boards, Arduino, STM32, ESP32 and more. We offer Raspberry Pi example codes in both C and Python, as well as Arduino, STM32 and ESP32 example codes. These codes enable drawing of points, lines, rectangles, and circles, and also support displaying alphanumeric characters and images.
Product parameters
Pixels | 128 x 64 |
Display Color | Black and White/Black and Yellow/ Black and Blue/Black and Green |
Voltage Translator | TXS0108EPWR |
Signal interface | SPI / I2C |
Supply voltage | 3.3V/5V |
OLED display area | 55.01mm (W) x 27.49mm (H) |
Driver chip | SSD1309 |
Size | Style A:63mm(Length) x 42.4mm(width) Style B:62.1mm(Length) x 39.2mm(width) |
Weight | Style A:23g Style B:21g |
Usage
All examples provided with this product are based on SPI mode, so the default position of the switch on the back of the board is set to "SPI". If you want to use I2C mode, please switch the selector on the back of the board to "I2C" and change `use_mode 1` to `use_mode 0` in the `oled.h` file.
This product has two optional I2C addresses, controlled by the high or low level of the D/C pin in I2C mode. If you want to change the I2C address, please modify the `ADDR` and D/C pin levels in the `oled.h` and `oled.c` files to the corresponding parameters.
Module Resource Profile
Module Resource Profile is shown in the figure below:
1. SPI/I2C selector switch
2. OLED screen connector
3. Voltage Translator TXS0108
4. SPI/I2C control interface 2.54mm pitch connector
5. SPI/I2C control interface 2.54mm pitch pin header
Raspberry Pi Demo Codes Usage
Since the bookworm system no longer supports the wiringpi library, the example program for this system uses the lgpio library, and for the bullseye system, the wiringpi library version of the example program can be used.
Raspberry Pi Platform Interface Definition
The bullseye system example program for the Raspberry Pi uses the pin definitions number in wiringPi, and the bookworm system uses the pin definition of the BCM number. The definition of the wiring with the Raspberry Pi motherboard is shown in the following table:
OLED display | WiringPi number | BCM number |
---|---|---|
VCC | 3.3V | |
GND | GND | |
DIN | SPI:P12 / I2C:P8 | SPI:D10 / I2C:D2 |
CLK | SPI:P14 / I2C:P9 | SPI:D11 / I2C:D3 |
CS | P10 | D8 |
D/C | P6 | D25 |
RST | P0 | D17 |
WiringPi library installation
C:
sudo apt-get install wiringpi
wget https://project-downloads.drogon.net/wiringpi-latest.deb # Raspberry Pi 4B version upgrade
sudo dpkg -i wiringpi-latest.deb
gpio -v # If version 2.52 appears, the installation is successful
#For Python 2. x version
pip install wiringpi
#For Python version 3. X
pip3 install wiringpi
Note: If the installation fails, you can try the following compilation and installation:
git clone --recursive https://github.com/WiringPi/WiringPi-Python.git
Note: The -- recursive option can automatically pull the submodule, otherwise you need to download it manually.
Enter the WiringPi Python folder you just downloaded, enter the following command, compile and install:
#For Python 2. x version
sudo python setup.py install
#For Python version 3. X
sudo python3 setup.py install
If the following error occurs:
At this time, enter the command sudo apt install swig to install swig. After that, compile and install sudo python3 setup.py install. If a message similar to the following appears, the installation is successful.
Lgpio library installation
wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
make
sudo make install
Open SPI interface
sudo raspi-config
Enable SPI interface:
Interfacing Options->SPI->Yes
To view enabled SPI devices:
ls /dev/spi*
The following will be printed: "/dev/spidev0.0" and "/dev/spidev0.1"
Open I2C interface
sudo raspi-config
Enable I2C interface:
Interfacing Options->SPI->Yes
Run the command to check whether I2C is started:
lsmod
If i2c_bcm2835 are displayed, it means I2C module is started.
Install the i2c-tools tool to confirm:
sudo apt-get install i2c-tools
View connected I2C devices:
i2cdetect -y 1
If the display address is 0x3d or 0x3c, it indicates that the OLED is successfully connected to the Raspberry Pi.
Installation of python library
The demo codes uses the python 3 environment. To run the python demo codes, you need to install the pil, numpy, and spiderv libraries. Enter the following commands in order to install:
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo apt-get install python3-pip
sudo apt-get install spidev
sudo pip3 install smbus
C version demo codes
Open \***\raspberry_pi\c directory
sudo make clean
sudo make
sudo ./main
After entering the above command, you can observe the OLED display.
Python version demo codes
Open \***\raspberry_pi\python directory
python3 gui_demo.py
After entering the above command, you can observe the OLED display.
Arduino Demo Codes Usage
Hardware interface configuration description
Table 2-2 is the wiring definition between Arduino Mega and OLED display:
OLED display | Arduino Mega |
---|---|
VCC | 5V |
GND | GND |
DIN | SPI:D51 / I2C:SDA1 |
CLK | SPI:D52 / I2C:SCL1 |
CS | D10 |
D/C | D9 |
RST | D8 |
Table 2-3 is the wiring definition between Arduino Uno and OLED display:
OLED display | Arduino Uno |
---|---|
VCC | 5V |
GND | GND |
DIN | SPI:D11 / I2C:SDA |
CLK | SPI:D13 / I2C:SCL |
CS | D10 |
D/C | D9 |
RST | D8 |
Demo Codes Usage
Open the \***\Arduino_MEGA_2.42\Arduino_MEGA_2.42.ino or \***\Arduino_UNO_2.42\Arduino_UNO_2.42.ino with Arduino IDE Click Verify to verify the project file, and then transfer it to the module to observe the OLED display.
STM32 Demo Codes Usage
The STM32 module used in this example program is STM32F103C8T6.
Hardware interface configuration description
OLED display | STM32 |
---|---|
VCC | 3.3V |
GND | GND |
DIN | SPI / I2C:PA7 |
CLK | SPI / I2C:PA5 |
CS | PB4 |
D/C | PA3 |
RST | PA2 |
Demo Codes Usage
Open the demo codes in directory \***\STM32 with Keil uVision5 software, compile it correctly, download it to the module, and observe the OLED display.
ESP32 Demo Codes Usage
The ESP32 module used in this example program is ESP32-WROOM-32E.
Hardware interface configuration description
OLED display | ESP32 |
---|---|
VCC | 3.3V |
GND | GND |
DIN | SPI:IO23/ I2C:IO21 |
CLK | SPI:IO18/ I2C:IO22 |
CS | IO25 |
DC | IO26 |
RST | IO33 |
Demo Codes Usage
Open the demo codes in directory \***\Arduino_ESP32_2.42 with Arduino IDE Click Verify to verify the project file, and then transfer it to the module to observe the OLED display.
Image Creation and Modeling Instructions
Image Creation
Create the images you want to display as pure black and white images with a resolution of 128 x 64. Save them as BMP or JPG files (BMP format is recommended).
Modeling
Bitmap creation can be done using the "image2lcd" software, which is provided in the package. Taking the example of achieving the effect shown in Figure 2-3, the parameter settings interface for bitmap creation is shown in Figure 2-4:
1. Open the image that needs to be modeled.
2. Output data type: Select "C Language Array (*.c)".
3. Scanning method: Choose "Vertical scanning".
4. Output grayscale: Select "Monochrome".
5. Maximum width and height: Choose "128" "64". After selection, click the arrow next to it to confirm.
6. Do not check any of the 5 items as shown in the figure below.
7. Color Inversion: Check to display the original image; uncheck for color inversion.
8. Click "Save" to save the converted array to a file with the extension ".c".
9. Finally, use the array in the ".c" file to replace the corresponding array in the program.
Data Resources
Data Sheet
Related Links
Python Imaging Library
If users need to implement additional functionality, they can visit the official website to learn more: https://pillow.readthedocs.io/en/latest/handbook/index.html