OLED display

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
rlm85704
Posts: 2
Joined: Sun Apr 03, 2022 3:22 pm

OLED display

Post by rlm85704 » Sun Apr 03, 2022 3:35 pm

Having trouble getting a simple OLED ssd1306 driven device to work. I'm using the sample code from
https://datasheets.raspberrypi.com/pico ... on-sdk.pdf

IDE is Thonny on MacOS

the relevant segment of my code is

print("I2C Address : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c)) # Display I2C config
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) # Init oled display


the output is

I2C Address : 0X27
I2C Configuration: I2C(0, freq=200000, scl=9, sda=8)
Traceback (most recent call last):
File "<stdin>", line 21, 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

Thanks for insights.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OLED display

Post by Roberthh » Sun Apr 03, 2022 4:07 pm

According to the data sheet, the I2C address of a ssd1306 is 0x3c or 0x3d. The driver uses 0x3c as default. If your display uses a different address, you have to specify it in the constructor, e.g.

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x27) # Init oled display

Or do you have other devices connected to the I2C bus as well? What is the result of:

print(i2c.scan())

rlm85704
Posts: 2
Joined: Sun Apr 03, 2022 3:22 pm

Re: OLED display

Post by rlm85704 » Sun Apr 03, 2022 4:23 pm

Thanks for the fast reply ...

code now reads:
i2c = I2C(0) # Init I2C using I2C0 defaults, SCL=Pin(GP9), SDA=Pin(GP8), freq=400000
print("I2C Address : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c)) # Display I2C config
print(i2c.scan())

output is
I2C Configuration: I2C(0, freq=399361, scl=9, sda=8)
[39]

Unsure how to interpret this ...

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OLED display

Post by Roberthh » Sun Apr 03, 2022 4:34 pm

The scan returns a single device on the bus, with I2C address decimal 39 or 0x27 hex. As told, 0x27 is not the usual address of a SSD1306 display. Are you sure, that it is a SSD1306 model?

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: OLED display

Post by scruss » Sun Apr 03, 2022 6:54 pm

rlm85704 wrote:
Sun Apr 03, 2022 3:35 pm
the output is

I2C Address : 0X27
That's typically what you'd see from a character LCD (a 1602, 2002 or 2004 - 16x2, 20x2 or 20x4 characters respectively). What does your display look like?

kaotic
Posts: 1
Joined: Mon May 09, 2022 5:00 am

Re: OLED display

Post by kaotic » Mon May 09, 2022 5:17 am

The thread seemed to end with potential for the wrong module being used, but I get the same error and as far as I know, I am using a ssd1306. It is 0.91 inch OLED 128x32.
The screen has (apparently) random pixels lit, but nothing resembling what I was trying for.
Any suggestions?

Shell output below:
I2C Address : 0X3C
I2C Configuration: I2C(0, freq=250000, scl=5, sda=4)
Traceback (most recent call last):
File "<stdin>", line 19, in <module>
File "ssd1306.py", line 110, in __init__
File "ssd1306.py", line 36, in __init__
File "ssd1306.py", line 73, in init_display
File "ssd1306.py", line 101, in show
File "ssd1306.py", line 119, in write_data
OSError: [Errno 5] EIO

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: OLED display

Post by Roberthh » Mon May 09, 2022 5:19 am

Error 5 usually indicates a basic communication problem. Do you get the device address when you run i2c.scan()?

Post Reply