I have .91inch 128x32 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.

  • #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 Apr 4 at 3:40
  • 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 Apr 4 at 3:44
  • 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 Apr 4 at 4:12


How can Rpi Pico Micropython Talk To I2C LCD SSD1306?

/ to continue, ...


Update 2021apr08hkt1233

I found the 0.91" OLED a bit tricky to detect. I need to make the the wiring short, not to load two or more devices. I also found I2C Bus 1 better than Bus 1. Anyway, I used Tom's Hardware's short program and found it OK, though not stable.

oled 091 1

Short Answer

  1. It is pretty likely that Pico Thonny Python's error message "OSError: 5" is similar to Rpi Os's "OSError: [Errno 121] Remote I/O error"

  2. Errno 121 usually occurs when running an I2C python program with the following situation:

    2.1 The hardware wiring connection is bad, eg,

    2.1.1 Forget to plug/connect the cable,

    2.1.2 Too long cabling, eg, over 30cm,

    2.1.2 I2C frequency too high, over 400kHz,

    2.1.3 I2C device, eg. I2C I2C MCP23017, which is sensitive to noise,

    2.1.4 I2C bus overloaded, with more than 4 devices, causing bus capacitance over 400pF.

/ to continue, ...

Long Answer

/ 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

(9) Raspberry Pi Pico + 128x64 I2C SSD1306 OLED (MicroPython) Youtube

(10) Raspberry Pi Pico + 128x64 I2C SSD1306 OLED (MicroPython) Tutorial

(11) SSD1306 OLED Display Module Catalog - AliExpress

/ 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 > thonny

    Data 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

  • yes, I have the same OLED as you. 128x32 pixels I2C... – Zeno Apr 4 at 4:17
  • 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 Apr 4 at 4:25
  • 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 Apr 4 at 4:28
  • 1
    yes, i have selected micropython ssd1306 and not circuitpythonand not ssd1327. the website suggests taking this to chat. should we? – Zeno Apr 4 at 4:43
  • 1
    i added a picture that might help you see what i chose, just in case. – Zeno Apr 4 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.