Circuit Python tutorials in Robotics II
View the Project on GitHub MrPrattASH/Robotics-II-Circuit-Python
This tutorial was originaly taken from ADAFruit here and has since been modified to include documentation for only the Metro M4 Express board.
Before beginning, you will need 3 relevant libraries that will do a lot of the heavy lifting for us. Install these to your M4 lib folder They are located in the folders/files above. Be sure to download the entire folder contents for the bottom 2, not just the .mpy files.

It’s easy to use OLEDs with Python and the Adafruit CircuitPython DisplayIO SSD1306 module. This module allows you to easily write Python code to control the display.
To demonstrate the usage, we’ll initialize the library and use Python code to control the OLED from the board’s Python REPL.
import board
import displayio
import terminalio
import time
from i2cdisplaybus import I2CDisplayBus
import adafruit_displayio_ssd1306
#releases current displays if any were initialized before setup
displayio.release_displays()
# Use for I2C
i2c = board.I2C()
display_bus = I2CDisplayBus(i2c, device_address=0x3d) # or 0x3d
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
for i in range(5):
print("index:", i)
time.sleep(1)
Let’s take a look at the sections of code one by one. We start by importing the board so that we can initialize SPI, displayio,terminalio for the font, a label, and the adafruit_displayio_ssd1306 driver.
import board
import displayio
import terminalio
import time
from i2cdisplaybus import I2CDisplayBus
import adafruit_displayio_ssd1306
Next we release any previously used displays. This is important because if the microprocessor is reset, the display pins are not automatically released and this makes them available for use again.
displayio.release_displays()
# Use for I2C
i2c = board.I2C()
display_bus = I2CDisplayBus(i2c, device_address=0x3d) # or 0x3d
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
In order to make it easy to change display sizes, we’ll define a few variables in one spot here. We have the display width, the display height and the border size, which we will explain a little further below. If your display is something different than these numbers, change them to the correct setting.
for i in range(5):
print("index:", i)
time.sleep(1)
We now put in a simple for loop to be able to see our screen up and running. Now we have a far more useful debugging console build directly into our robot!
want to do more advanced things with this OLED? Check out this page here