SSD1306 1.3" OLED (128x64)

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
abhi_R2000
Posts: 7
Joined: Thu Aug 04, 2022 8:48 am

SSD1306 1.3" OLED (128x64)

Post by abhi_R2000 » Thu Aug 04, 2022 8:54 am

Hi,
I have been doing a project with Raspberry Pi PICO and SSD1306 OLED(128x64) in Thonny IDE. I'm getting some errors in the program. Can you pls guide me to solve the issue ?

This is the code I'm trying -

Code: Select all

from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
import utime

WIDTH  = 128                                            # oled display width
HEIGHT = 64                                             # oled display height

i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=200000)               # Init I2C using pins GP8 & GP9 (default I2C0 pins)
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

# Raspberry Pi logo as 32x32 bytearray
buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")

# Load the raspberry pi logo into the framebuffer (the image is 32x32)
fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)

while True:
    # Clear the oled display in case it has junk on it.
    oled.fill(0)

    # Blit the image from the framebuffer to the oled display
    oled.blit(fb, 96, 0)

    # Add some text
    oled.text("Raspberry",0,0)

    # Finally update the oled display so the image & text is displayed
    oled.show()
    utime.sleep(1)
These are the errors showing for the above given program -

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 14, in <module>
  File "ssd1306.py", line 118, in __init__
  File "ssd1306.py", line 37, in __init__
  File "ssd1306.py", line 74, in init_display
  File "ssd1306.py", line 123, in write_cmd
OSError: [Errno 5] EIO

Thanks

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: SSD1306 1.3" OLED (128x64)

Post by Lobo-T » Thu Aug 04, 2022 10:29 am

Do you get a result from this part?:
print("I2C Address : "+hex(i2c.scan()[0]).upper())

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

Re: SSD1306 1.3" OLED (128x64)

Post by Roberthh » Thu Aug 04, 2022 12:15 pm

EIO is in most cases a wiring problem. Please check:

- Are GND and Vcc for the display connected?
- did you really connect to GPIO8 and GPIO9. Maybe you connected to board pin 8 an 9.
- Are pull-up resistors in place at SDA and SCL?

abhi_R2000
Posts: 7
Joined: Thu Aug 04, 2022 8:48 am

Re: SSD1306 1.3" OLED (128x64)

Post by abhi_R2000 » Thu Aug 04, 2022 12:43 pm

Lobo-T wrote:
Thu Aug 04, 2022 10:29 am
Do you get a result from this part?:
print("I2C Address : "+hex(i2c.scan()[0]).upper())
Yes, I'm getting that I2C address and I2C configuration part.

Code: Select all

I2C Address      : 0X3D
I2C Configuration: I2C(0, freq=200000, scl=9, sda=8)

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: SSD1306 1.3" OLED (128x64)

Post by Lobo-T » Thu Aug 04, 2022 12:49 pm

The driver defaults to 0x3c: https://github.com/micropython/micropyt ... 06.py#L113

Pass your address to the driver constructor:

Code: Select all

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3D)

abhi_R2000
Posts: 7
Joined: Thu Aug 04, 2022 8:48 am

Re: SSD1306 1.3" OLED (128x64)

Post by abhi_R2000 » Thu Aug 04, 2022 1:08 pm

Lobo-T wrote:
Thu Aug 04, 2022 12:49 pm
The driver defaults to 0x3c: https://github.com/micropython/micropyt ... 06.py#L113

Pass your address to the driver constructor:

Code: Select all

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3D)
Hi,
I passed that earlier itself. After passing that 0x3D, I started to get some scattered pixels.

Code: Select all

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)

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: SSD1306 1.3" OLED (128x64)

Post by Lobo-T » Thu Aug 04, 2022 1:15 pm

abhi_R2000 wrote:
Thu Aug 04, 2022 1:08 pm
I passed that earlier itself. After passing that 0x3D, I started to get some scattered pixels.
Roberthh wrote:
Thu Aug 04, 2022 12:15 pm
- Are pull-up resistors in place at SDA and SCL?
And the pull-up resistors are what value and placed where?

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

Re: SSD1306 1.3" OLED (128x64)

Post by Roberthh » Thu Aug 04, 2022 1:26 pm

Pull-Up resistors are usually 5-10kOhm. But the the display works with I2c, then there may be pull-up resistors on the display already.
They are placed between the signal wire (SDA or SCL) and Vcc.

Lobo-T
Posts: 36
Joined: Tue Nov 16, 2021 2:36 pm

Re: SSD1306 1.3" OLED (128x64)

Post by Lobo-T » Thu Aug 04, 2022 1:32 pm

I was asking abhi_R2000 what he was actually using.

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

Re: SSD1306 1.3" OLED (128x64)

Post by scruss » Thu Aug 04, 2022 11:55 pm

scattered pixels can also mean the wrong driver. Are you sure you're using an SSD1306 and not an SH1106?

Post Reply