Pico ssd1306 notes

Rpi pico micropython ssd1306 OSError: 5

Ask QuestionAsked todayActive todayViewed 28 times1

I have .91inch 128×32 pixel oled display. here

im following Tom’s Hardware tutorial here

I’m using Thonny on windows 10

ive basically copy and pasted from Tom’s hardware

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)

oled.text("Tom's Hardware", 0, 0)

I named the file “main.py”

I have the ssd1306 micropython package. when i try to run it i get the following message

Traceback (most recent call last):
  File "<stdin>", line 17, in <module>
  File "/lib/ssd1306.py", line 110, in __init__
  File "/lib/ssd1306.py", line 36, in __init__
  File "/lib/ssd1306.py", line 71, in init_display
  File "/lib/ssd1306.py", line 115, in write_cmd
OSError: 5

I honestly dont know what this is trying to say. i googled “OSError 5” and the only solutions that i could find were to add a delay between the initiation and the first write to the i2c device. that didnt work.

this is an image of the ssd1306 that i chose in thonny

does anyone know how to fix this error?

thank you.i2cpi-picomicropythonShareEditFollowCloseFlagedited 4 hours agoasked 11 hours agoZeno1122 bronze badges New contributor

  • #Zeno, Welcome and nice to meet you. Ah, let me see. Please let everybody know which SSD1306 you are testing, and which tutorial you are following. Two links would help a lot. Cheers. – tlfong01 5 hours ago    
  • I searched my old files and found a setup record, as shown in Appendix A below. Please confirm your device is exactly the same as mine. So I would tailor my answer accordingly. – tlfong01 5 hours ago   
  • I have added a couple of references to my answer. I would suggest you to skim them and perhaps also listed some references in your answer. This shows the research work you have done, and other readers would upvote you. At least you should show that you are reading Tom’s Hardware columns and give the link in your answer. – tlfong01 5 hours ago   

Add a comment

1 Answer



How can Rpi Pico Micropython Talk To I2C LCD SSD1306?

/ to continue, …


/ to continue, …


(1) Solomon OLED Display Catalog – Solomon Tech

(2) Solomon OLED Driver IC Product Sheet – Solomon Tech

(3) Solomon SSD1306 Product Sheet – Solomon Tech

(4) SSD1306 OLED Display Module Product Spec – Denstron/Farnell

(5) SSD1306 Tutorial – Components101

(6) How to Use an OLED Display With Raspberry Pi Pico – Les Pounder, Tom’s Hardware, 2021feb28

(7) Luma.OLED API Doc for SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331, SSD1351 and SH1106API OLED

(8) Rpi3B SSD1306 OLED I2C Interface Problem (with debugged Hello World program) – tlfong01 Rpi.SE Asked 2019dec21, Viewed 799 times

/ to continue, …


Appendix A – Old SSD1306 Setup Record

ssd1306 test 01

Appendix B – Installing Rpi Pico MicroPython OLED SSD1306 Library – Tom’s Hardware

(6) How to Use an OLED Display With Raspberry Pi Pico – Les Pounder, Tom’s Hardware, 2021feb28

  1. Click on Tools > Manage Packages to open Thonny’s package manager for Python libraries.
  2. Type “ssd1306” in the search bar and click “Search on PyPI”.
  3. Click on “micropython-ssd1306” in the returned results and then click on Install. This will copy the library to a folder, lib on the Pico.
  4. Click Close to return to the main interface.

Note – Only partial installed, with error code 1

ssd1306 install error 1

Update 2021apr03hkt1528

I installed ssd1308 second time and had good luck.

ssd1306 install ok

Appendix C – Pico version of Rpi4B OS buster’s command “i2cdetect -y 1”


I am using the Pico Thonny Python function to detect and list the I2C devices on I2C bus 1 and 2. The following sample output show two i2c pcf8574 devices are detected.

Note – The Thonny sample is badly formatted in RpiSE here. So I am going to use PenZu to write a better formatted file (to be include in next Appendix D).

MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040

Type “help()” for more information.

%Run -c $EDITOR_CONTENT Begin scanI2cBuses(), tlfong01 2021apr03hkt1431, …

Begin testPcf8574(), … >>>>>>>>>>

*** Set up I2C bus list [i2cBus0, i2cBus1] ***

*** I2C Bus List Config *** I2C Bus Num = 0 Bus nick name = Amy Frequency = 100 kHz sdaPin = 0 sclPin = 1
I2C Bus Num = 1 Bus nick name = Betty Frequency = 400 kHz sdaPin = 2 sclPin = 3

*** I2c Device Dict *** i2cDevNum = 0 DeviceName = PCF8574 #1 NickName = Connie I2cBusNum = 0 I2cDevAddr = 0x23 i2cDevNum = 1 DeviceName = PCF8574 #2 NickName = Daisy I2cBusNum = 1 I2cDevAddr = 0x24 i2cDevNum = 2 DeviceName = LCD2004 #1 NickName = Emily I2cBusNum = 0 I2cDevAddr = 0x27 i2cDevNum = 3 DeviceName = LCD1602 #1 NickName = Fanny I2cBusNum = 1 I2cDevAddr = 0x22

*** Scan and print I2C devices I2C bus list [i2cBus0, i2cBus1] *** I2C Bus Num = 0 I2cDeviceList = 0x23
I2C Bus Num = 1 I2cDeviceList = 0x24

End testPcf8574(). >>>>>>>>>>

End scanI2cBuses(), tlfong01 2021apr03hkt1431, …

/ to continue, …

Appendix D – Full program listing of I2C Bus Scan program discussed in Appendix C above.

Pico I2C Bus Scan Program v0.1

Appendix E – MicroPython ssd1306.py Listing v0.1

MicroPython ssd1306.py Listing v0.1


  1. Windows 10 Thonny Program and Data Folder Locations:Program Folder = c: > user > AppData > Local > Programs > Thonny > Lib > site-packages > thonnyData Folder = c: > user > AppData > Roaming > Thonny
  2. This ssd130.6py is only 150 python statement long, and contains two classes, one for I2C, an another for SPI.

Appendix F – Rpi4B Python Hello World Program for SSD1306

(8) Rpi3B SSD1306 OLED I2C Interface Problem (with debugged Hello World program) – tlfong01 Rpi.SE Asked 2019dec21, Viewed 799 times

ssd1306 hello world 01

ShareEditDeleteFlagedited 26 secs agoanswered 6 hours agotlfong013,62133 gold badges77 silver badges2222 bronze badges

  • yes, I have the same OLED as you. 128×32 pixels I2C… – Zeno 5 hours ago
  • It appears that you have a rasp pi 4, I am doing this on windows with thonny, and this is the tutorial (one of many tutorials that i have tried to get the oled working) tomshardware.com/how-to/oled-display-raspberry-pi-pico – Zeno 5 hours ago
  • perhaps, i should also mention that I have gotten the oled to work on a pro micro which is a copy of adafruit’s pro micro – Zeno 5 hours ago
  • Ah, some misunderstanding here. As I said, the setup I showed was 2 years ago on Rpi4B Thonny. I am showing this for your reference and also to refresh my memory. I am glad that you are using Windows Thonny Micro Python and not ESP32 or AdaFruit Circuit Python. I am using both Rpi4B and Windows Thonny. So I will try to use Windows for you to compare and contrast, to troublsshoot. – tlfong01 5 hours ago   
  • here is one of the websites discussing adding a small delay that i mentioned earlier forum.micropython.org/viewtopic.php?t=4746 – Zeno 5 hours ago
  • Ah, your successful testing on AdaFruit Pro Micro is very useful to our troubleshooting. So I won’t guess your OLED is bad. – tlfong01 5 hours ago   
  • Just to confirm, so you have already installed the SSD1306 micropython library in your Pico? – tlfong01 4 hours ago   
  • 1yes, i have selected micropython ssd1306 and not circuitpythonand not ssd1327. the website suggests taking this to chat. should we? – Zeno 4 hours ago
  • 1i added a picture that might help you see what i chose, just in case. – Zeno 4 hours ago
  • Ha, your pic shows you have a long and thin SSD1306. But mine is a short, fat guy. I forgot the details of what I did two years ago. So I need to refresh my memory. Ah locking down lunch time. I need to go and eat. See you later. PS – And let us move to chat room – tlfong01 4 hours ago    
  • Let us continue this discussion in chat. – Zeno 4 hours ago

Please avoid extended discussions in comments. Would you like to automatically move this discussion to chat?Add a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.