0

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)
oled.show()

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)
odog
  • 1
  • 2
  • 1
    (1) Hardware questions are better suited to [raspberrypi.se]. (2) Enough information to answer your question or learn from an answer needs to be included **in the question itself**. – Charles Duffy Dec 02 '22 at 17:51
  • See [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/a/285557/14122) for background on why screenshots don't count towards meeting [mre] requirements. – Charles Duffy Dec 02 '22 at 17:51
  • As for what EIO means, that's in general specific to the hardware driver that's implementing a given syscall. I haven't seen your code (since it's not included in the question itself), so can't provide more feedback than that. – Charles Duffy Dec 02 '22 at 17:53

1 Answers1

0

Thank you, odog, your error helped me track mine down. This simple example now works for me:

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)

devices = i2c.scan()
try:
    oled = SSD1306_I2C(128, 64, i2c,addr=devices[0])
    oled.text("hello world", 0, 0)
    oled.show()
except Exception as err:
    print(f"Unable to initialize oled: {err}")

Since yours stopped responding to the address you found, I'm not sure if it will help you.