How To Drive OLED with Raspberry Pi with a python script

Most of us will be familiar with 16×2 dot-matrix LCDs, which are used to display some information to users in most projects. However, these liquid crystal displays have many limitations. In this tutorial, we will learn about OLED displays and how to use them with Raspberry Pi. There are many types of OLED displays on the market, and there are many ways to make them work. We have used a 4-pin OLED with Arduino.

Required hardware:

OLED Display

The term OLED stands for “organic light emitting diode” and it uses the same technology used by most of our television sets, but with fewer pixels.

Connecting these cool display modules to the Raspberry Pi is really fun because it will make our project look cool. We have covered here a complete article on OLED displays and their types. Here we are using a monochrome 4-pin SSD1306 0.96″ OLED display. The LCD can only work in I2C mode.

Follow these steps for installing libraries

Connect OLED to Raspberry Pi:

OLED Pin

RPI Pin

VCC

3.3v

GND

GND

SDA

SDA (Physical pin 3)

SCL

SCL (Physical pin 5)

The RPI community has provided us with a lot of libraries that can be used directly to make this easier. I tried several libraries and found that the Adafruit_SSD1306 OLED library is very easy to use and has a few graphics options, so we will use them in this tutorial.

Enable I2C Communication

Before installing the Adafruit SSD1306 library, we need to enable I2C communication in the Raspberry Pi.

Do this in the Raspberry Pi console:

Sudo raspi-config

Then a blue screen will appear. Now select interface options

After that, we need to restart the Raspberry Pi with the following command:

Sodo restart

Find the OLED I2C Address and Update It

Then we need to use the given command to find the OLED I2C address and you will see a hexadecimal address.

Sudo i2cdetect -y 1

Then update the Raspberry Pi with the given command:

Sudo apt-get update

Install python-pip and GPIO libraries

After this, we need to install pip with the given command:

Sudo apt-get install build-essential python-dev python-pip

And install Raspberry Pi GPIO library

Sudo pip installs RPi.GPIO

Install Python Imaging Library and smbus Library

Finally, we need to install the Python Imaging Library and the smbus library on the Raspberry Pi using the given command: