I've been trying to use an ssd1306 oled display with a raspberry pi pico but every time I run the code it returns an error. I don't know what the error means and can't really find anything online for it. I was able to "fix" it yesterday by changing the address in the library file it uses, but although it worked, the issue came back for no apparent reason, despite me not even changing any of the code.

this is the code that I am trying to use

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("hello world", 0, 0)

this is the error

Traceback (most recent call last):
File "<stdin>", line 11, 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: [Errno 5] EIO

and the 'addr=0x3D' was originally 0x3C which is 60 in hex but since my i2c.scan returned 61, I changed it to 0x3D, which fixed it for a little bit but it stopped working again for some reason

class SSD1306_I2C(SSD1306):
def __init__(self, width, height, i2c, addr=0x3D, external_vcc=False):
    self.i2c = i2c
    self.addr = addr
    self.temp = bytearray(2)
    self.write_list = [b"\x40", None]  # Co=0, D/C#=1
    super().__init__(width, height, external_vcc)

2 Answers 2


EIO is an Input/Output error. Presumably the I2C call is failing.

This is normally a wiring problem. Loose wires.

The address changing (0x3C to 0x3D) may suggest you have not set the I2C address of the device properly. Perhaps there is a jumper to set the address which needs to be pulled high or low.


This error mostly occurs for me in Thonny, in the situation where I have pressed "Ctrl/C" to stop a program executing, and then tried to load/execute another program which wants to use another I2C device, with the error occuring just at the start when executing the new program.

Disconnecting and reconnecting USB power, and pressing the red "stop/Restart" button in Thonny usually works with the "EIO" error no longer happening thereafter.

Of course, if you load/execute yet another program which uses yet another I2C device, it seems you have to repeat this annoying workaround fix. However, there is a situation where even this workaround may not work, and that is if the PICO W has a "main.py" which is already using an I2C device, that you are not wanting to use in your program.

Removing "main.py" from your PICO W ensures that the PICO W will always boot up empty with regard to I2C devices. Once you have deleted "main.py", disconnect and reconnect power to the PICO W (i.e. pull out and push back in the USB cable) and restart the backend in Thonny (press the red "Stop/Restart" button in the menu bar) and you should be OK.

The main thing is, until you have fully developed your program, don't create a "main.py", and only create a "main.py" when you have finished attaching your I2C devices

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.