How to use an OLED display with CircuitPython

How to use an OLED display with CircuitPython
OLED display with Raspberry Pi Pico

In this simple guide we will be using a widely available SSD1306 OLED display with the Raspberry Pi Pico to display some basic shapes. For this guide we will use CircuitPython and Adafruit helper libraries.

Code is licensed under the Open Source MIT License

What you need

  • Raspberry Pi Pico or compatible board with CircuitPython installed
  • SSD1306 OLED display
  • Breadboard and 4 jumper wires


Connect OLED display power in to existing 3v3 OUT and ground to any ground pin on Raspberry Pi Pico. Now connect SCL from OLED to Pin GP17 and SDA to Pin GP16 on the Raspberry Pi Pico.

Connect the Raspberry Pi Pico to USB and we are now ready to program.

Raspberry Pi Pico, SSD1306 circuit diagram


Download the following Adafruit CircuitPython libraries for SSD1306, unzip and place copy the files to your board. This Zip contains adafruit_framebuf and adafruit_ssd1306 CircuitPython scripts.

These libraries are licensed under the Open Source MIT License

The code

Finally the fun part! let's try to create simple eyes using the existing shape helpers defined in the libraries. Once you know the basics, you can take it far.

Create a new file and name it Now import the required libraries and define connection and display objects, see the inline comments for details. adafruit_ssd1306 depends on adafruit_framebuf so you must have both scripts copied to your board.

import time
import board
import busio # to communicate over I2C

# Helper print to see whats available on the connected board

# Import the SSD1306 module, see the lib downloads on this page
import adafruit_ssd1306

# Create the I2C interface for OLED, use any pins you like, we are going with GP0 (SDA) & GP1 (SCL)
# busio.I2C(SCL, SDA)
i2c = busio.I2C(board.GP17, board.GP16)
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)

Save the code to the board and run to check for error, if there are any errors check to make sure if you are running CircuitPython and have downloaded the mentioned libraries.

We are now ready to draw shapes. Let's define a method 'eyes' which takes a single argument and display circles at different positions and type based on the argument.

# Eyes graphic type

def eyes(type):
    display.fill(0) # clear
    if type == EYES_NORMAL:, 30, 10, 1), 30, 10, 1)
    elif type == EYES_AFRAID:, 64, 10, 1), 64, 10, 1)
    elif type == EYES_SPINNING:, 30, 4, 1), 30, 7, 1), 30, 10, 1), 30, 13, 1), 30, 4, 1), 30, 7, 1), 30, 10, 1), 30, 13, 1)
    elif type == EYES_BLINK:, 30, 10, 1) # show

Now we have all imports and methods ready and we can start displaying some simple but really cool eyes.

while True:

Save everything to the board and run - If everything is connected properly, you should now see your OLED display come to life.


Since we have named our script, whenever you will connect the Raspberry Pi Pico to the power it will automatically run.

File defines many different shapes which you can explore and display pretty much anything. Use the pixel method to display complex shapes.

Hope you have learned something new today. Ohh, before we go, now that you know how to display graphics, how about combining it with a simple motion detector? Here is a handy guide for you - Tilt ball switch as a vibration sensor.