Monday, May 05, 2025

Raspberry Pi Zero 2W + 0.91 inch OLED (SSD1306)

Playing with this cheap OLED display:
Size: 0.91 inch
Resolution: 128 x 32 pixels
Interface: I2C
Operating voltage: 3.3 V~5V
 
Update the system once:

$ sudo apt update
$ sudo apt upgrade -y

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm

$ uname -a
Linux pizero2w 6.12.25+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.25-1+rpt1 (2025-04-30) aarch64 GNU/Linux

Setup I2C for Raspi

$ sudo raspi-config → then enable I2C communication from "Interface Options" menu
$ sudo reboot

Install I2C utilities

$ sudo apt install i2c-tools

Connect the display to raspi

Display GND →  Raspi GND pin no.5
Display VCC →  Raspi 3V pin no.1
Display SDA  →  Raspi pin no.2
Display SCK  →  Raspi pin no.3

Check if Raspi can detect the display 

$ i2cdetect -y 1 → this command should show "0x3C" address


Install the following packages for python environment:

$ sudo apt install python3-pip
$ sudo apt install python3-venv

Create python virtual environment

$ mkdir $HOME/ws_py
$ cd $HOME/ws_py && python -m venv .venv

Activate python virtual environment (current working directory is $HOME/ws_py)

$ . .venv/bin/activate
(.venv) ~/ws_py $

After python virtual environment is activated, install python packages using pip

$ pip install Pillow
$ pip install RPi.GPIO
$ pip install adafruit-circuitpython-ssd1306
$ pip install adafruit-blinka

Check if the display is working properly using example code from Adafruit

$ cd $HOME/ws_py
$ git clone https://github.com/adafruit/Adafruit_CircuitPython_SSD1306.git
$ cd examples
$ python ssd1306_stats.py

The display should show the IP address, CPU, memory and disk info of the raspberry pi after this step




No comments: