2.42inch OLED Display 128 X 64 Pixels Black and Green Supports SPI/ I2C Communication

Figure 1-1 Style A Product Image
Figure 1-1 Style A Product Image
Figure 1-2 Style B Product Image
Figure 1-2 Style B Product Image

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

Pixels128 x 64
Display Color

Black and White/Black and Yellow/

Black and Blue/Black and Green

Voltage TranslatorTXS0108EPWR
Signal interfaceSPI / I2C
Supply voltage3.3V/5V
OLED display area55.01mm (W) x 27.49mm (H)
Driver chipSSD1309
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

Figure1-3 2.42inch OLED Display size diagram
Figure1-3 2.42inch OLED Display size diagram
Figure1-4 2.42inch OLED Display BW(B) size diagram
Figure1-4 2.42inch OLED Display BW(B) size diagram

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:

Figure 2-1 2.42inch OLED Display BW(A) Resource Overview
Figure 2-1 2.42inch OLED Display BW(A) Resource Overview

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:

Table2-1 Definition of OLED display and Raspberry Pi pin
OLED displayWiringPi numberBCM number
VCC3.3V
GNDGND
DINSPI:P12 / I2C:P8SPI:D10 / I2C:D2
CLKSPI:P14 / I2C:P9SPI:D11 / I2C:D3
CSP10D8
D/CP6D25
RSTP0D17

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:

Table 2-2 Pin definition of OLED display and Arduino Mega
OLED displayArduino Mega
VCC5V
GNDGND
DINSPI:D51 / I2C:SDA1
CLKSPI:D52 / I2C:SCL1
CSD10
D/CD9
RSTD8

Table 2-3 is the wiring definition between Arduino Uno and OLED display:

Table 2-3 Pin definition of OLED display and Arduino Uno
OLED displayArduino Uno
VCC5V
GNDGND
DINSPI:D11 / I2C:SDA
CLKSPI:D13 / I2C:SCL
CSD10
D/CD9
RSTD8

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 displaySTM32
VCC3.3V
GNDGND
DINSPI / I2C:PA7
CLKSPI / I2C:PA5
CSPB4
D/CPA3
RSTPA2

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 displayESP32
VCC3.3V
GNDGND
DINSPI:IO23/ I2C:IO21
CLKSPI:IO18/ I2C:IO22
CSIO25
DCIO26
RSTIO33

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.

Image 2-3
Image 2-3
Figure 2-4 Image modeling
Figure 2-4 Image modeling

Data Resources

Schematic

demo codes

Data Sheet

TXS0108E

SSD1309

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

Technical Support

Technical Support and Product Notes