SSD1306 OLED Display

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 17
Joined: Thu Mar 25, 2021 4:19 am

SSD1306 OLED Display

Post by seaside_motors » Mon May 17, 2021 3:45 pm

Hello all, just been playing with my Pi Pico and going through some tutorials and am struggling with getting my little
Adafruit SSD1306 OLED display working. Specifically 0.91" 128x32

I have looked through the code example that are listed on the adafruit website and they are for circuit python or python3. Micropython is neither of these and does not appear to be cross compatible from my struggles. Lets just start with where I am at and what I have tried to do to get it to work.

I have the board wired up on a bread board to the Pi Pico using GPIO pin1 (GP0) for SDA, Pin2(GP1) for SCL, pin19(GP14) for reset, pin36 for 3.3v for Vin and pin38 is ground.
The panel board power led come on green, no display light up.
Used the following code example from page 119 of 'The Official Raspberry Pi Pico Guide'

Code: Select all

  1 import machine
  3 sda=machine.Pin(0)
  4 scl=machine.Pin(1)
  5 i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
  7 print(i2c.scan())    
Using rshell I can upload the program, going to the repl and importing the program it returns a [60], so this tells me it is seeing the device and returning an address on the i2c bus.
but this is as far as I can go with the included code due to the examples they are using are specific to the SerLCD from SparkFun. I downloaded the Adafruit 1306 library for python but it downloads into my python3 directories and is of no use as a module for micropython.

Anyways this is where my show stops until I get some outside intervention.

Here is the rest of the example code that will pull the data from the onboard temp sensor and display it to the LCD, perhaps someone can help me navigate a way to accomplish the same outcome using the SSD1306 with micropython on Pico.

Code: Select all

import machine
import utime
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
adc = machine.ADC(4)
conversion_factor = 3.3 / (65535)
while True:
reading = adc.read_u16() * conversion_factor
temperature = 25 - (reading - 0.706)/0.001721
i2c.writeto(114, '\x7C')
i2c.writeto(114, '\x2D')
out_string = "Temp: " + str(temperature)
i2c.writeto([b]114, out_string)
The 114 in the i2c.writeto() lines refers to the address of the I2C device, in my case that would change to 60 as that is the address I was given when doing the i2c bus scan.
The next bits that may look a little odd are the \x7C and \x2D commands that are written. Each
I2C device requires data sent in a specific format. There’s no standard for this, so you’ll have to
refer to the documentation for whatever I2C device you’re setting up. The \x at the start of each
of these tells MicroPython that we’re sending a hexadecimal string (see ‘Hexadecimal’ box)
which is a common way of ensuring you’re sending the exact data you want. For our LCD, 7C
enters command mode and 2D blanks the LCD and sets the cursor to the beginning.
Now this is where things get tricky because obviously the SSD1306 has its own nomenclature requirements and these code example where specifically written for the Spark Fun SerLCD.

Anyways, here we are, hoping I can get some help getting this up and running.

Here is product page for display:

Adafruit tutorial page:

I have cross posted this to the Adafruit forum as well, but so far no response.

I appreciate the help, Thanks,

User avatar
Posts: 1386
Joined: Thu May 28, 2015 5:54 pm

Re: SSD1306 OLED Display

Post by deshipu » Tue May 18, 2021 8:58 am

I think you are mixing up several different devices here — you have a pixel-based display, and the code you tried is for a character-based display.

In any case, I wrote an article about how to display things on such OLED displays, it might be interesting to you: ... s-directly

Otherwise I would recommend to just get a library for SSD1306 display and use that.

User avatar
Posts: 5205
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: SSD1306 OLED Display

Post by pythoncoder » Tue May 18, 2021 10:56 am

deshipu wrote:
Tue May 18, 2021 8:58 am
Otherwise I would recommend to just get a library for SSD1306 display and use that.
@seaside_motors Specifically the official driver. MicroPython is different from Adafruit's CircuitPython; Adafruit drivers won't work with MicroPython. So, if you're running MicroPython you need the official driver. This works fine.
Peter Hinch

Posts: 17
Joined: Thu Mar 25, 2021 4:19 am

Re: SSD1306 OLED Display

Post by seaside_motors » Tue Jun 01, 2021 6:15 am

Howdy all,

After much wrangling around and getting some valuable help I was able to conquer the little oled display to display a simple temp output from the Pi Pico's internal temp sensor.

Some notable accomplishments: (for me anyways)
Converted Celsius to Fahrenheit
Update ONLY temp output as opposed the entire screen.
Explicitly display only 2 decimal places.

Special Thanks
Tony Goodhew (adafruit forums)
Dave Hyland (micropython forums)

Final Code:

Code: Select all

# Display Image & text on I2C driven ssd1306 OLED display 
import machine
from ssd1306 import SSD1306_I2C
import utime

# Define Hardware Parameters
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
oled=SSD1306_I2C(128,32, i2c)

# Defining Display Parameters
def blk():

# Define Temperature Output and Display
oled.text("Temp: ",6,12,1)
while True:
    oled.fill_rect(50,12,50,10,0) # Overwrite number
    oled.text("{:.2f}".format(tempF),50,12)   # Update number
PicoTemp1306.jpg (133.37 KiB) Viewed 289 times

Post Reply