I managed to find my I2C OLED display when I was cleaning up my place. As I currently have a S3 storage cluster project ongoing, I figured now would be a great time to get it working so I can attach an OLED display to each of the Raspberry Pis so I can get their status on a glance.

Below are the steps I used to get it working on Rasbian Lite. The steps should be the same for other distros.

Below is the wiring of the OLED to a Raspberry Pi

Connect the pins as shown in the diagram and using the description below.

OLED Pin Raspberry Pi GPIO Description
Vcc 1 Make sure to connect the OLED to the 3.3V power out ONLY.
SDA 3 I2C SDA1
SCL 5 I2C SCL1
Gnd 6 Ground pin.

Enabling I2C on the Raspberry Pi

Using raspi-config

  1. On Raspbian, type sudo raspi-config to enter the configuration options.
  2. Select Interfacing Options which will present further options.
  3. Select I2C and press ENTER to activate it.
  4. Install the I2C tools
sudo apt install python-smbus i2c-tools -y
  1. Reboot the Raspberry Pi to enable I2C.

Editing /boot/config.txt

  1. An alternative way to enable I2C is to edit the /boot/config.txt file and add the following
dtparam=i2c_arm=on
  1. Add the following to /etc/modules and check to make sure nothing related to I2C is blacklisted
i2c-dev
  1. Install the I2C tools
sudo apt install python-smbus i2c-tools -y
  1. Reboot the Raspberry Pi to enable I2C.

Check if Raspberry Pi detected the OLED

If everything went well, the Raspberry Pi should have detected the OLED. Verify it by entering the following command

i2cdetect -y 1

Something like the following will be shown

Notice the 3C. This is the hex address of the OLED. If something similar to this is shown, it means the OLED is detected and we can start using it.

Showing something on the OLED

To verify the display was still functional, I decided to use the Adafruit OLED library to test it out. I did the following to get it working.

  1. Install the necessary libraries and tools
sudo apt install git python3-dev python3-setuptools python3-rpi.gpio python3-pil
  1. Clone the Adafruit OLED Library and switch to the directory
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
cd Adafruit_Python_SSD1306
  1. Install the library for Python3
sudo python3 setup.py install
  1. Once the setup is done, run the examples to make sure your OLED display is functional
cd examples
python3 stats.py
  1. If everything went well, you can now view the IP address and some other statistics on the OLED.

My next step is to use Golang to develop an application that will display information on the Raspberry Pi for my S3 cluster.

Until then, I hope this helps anyone looking to connect an OLED to their Raspberry Pi. Cheers!

Note: I do not own the rights nor do I take credit for the images used in this post.