Having an issue getting the lib for the SSD1306 working

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
Pigeon
Posts: 8
Joined: Tue Oct 12, 2021 9:22 pm
Location: UK
Contact:

Having an issue getting the lib for the SSD1306 working

Post by Pigeon » Wed Oct 13, 2021 10:19 pm

have the SSD1306.py in my Lib forler.

Trying to run some simple code:

Code: Select all

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

WIDTH = 128
HEIGHT = 64

i2c = I2C(0, scl = Pin(17), sda = Pin(16), freq=200000)

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)

oled.fill(0)

oled.text("I CAN HAZ PANCAKE?", 10, 10)

oled.show
But when I run it I get the following error in Thonny:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 10, 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
some googling suggested it could be the I2C address being wrong for my module, but when I do a

Code: Select all

i2c.scan()
I get a reply of [60] so think that means its the default 0X3C?

User avatar
curt
Posts: 25
Joined: Thu Jul 29, 2021 3:52 am
Location: Big Lake, Alaska

Re: Having an issue getting the lib for the SSD1306 working

Post by curt » Sat Oct 16, 2021 7:22 pm

I had problems with this too. After much searching here is what worked for me:

Code: Select all

# Complete project details at https://RandomNerdTutorials.com

import machine
#from machine import Pin, SoftI2C
import ssd1306
from time import sleep

i2c = machine.SoftI2C(scl=machine.Pin(15), sda=machine.Pin(4))

pin = machine.Pin(16, machine.Pin.OUT)
pin.value(0) #set GPIO16 low to reset OLED
pin.value(1) #while OLED is running, must set GPIO16 in high

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

oled.fill(0)
oled.text('Hello, World 1!', 0, 0)
oled.text('Hello, World 2!', 0, 10)
oled.text('Hello, World 3!', 0, 20)
oled.show()
Curt

User avatar
Pigeon
Posts: 8
Joined: Tue Oct 12, 2021 9:22 pm
Location: UK
Contact:

Re: Having an issue getting the lib for the SSD1306 working

Post by Pigeon » Fri Oct 29, 2021 5:28 am

curt wrote:
Sat Oct 16, 2021 7:22 pm
I had problems with this too. After much searching here is what worked for me:
Thank you Curt, forgot to reply that this also worked for me!

Sincerely, Thank you!

Tigran
Posts: 1
Joined: Thu Jan 27, 2022 8:21 pm

Re: Having an issue getting the lib for the SSD1306 working

Post by Tigran » Thu Jan 27, 2022 8:34 pm

Thank you Curt, it worked for me too!

mike2545
Posts: 1
Joined: Sun Apr 03, 2022 12:22 pm

Re: Having an issue getting the lib for the SSD1306 working

Post by mike2545 » Sun Apr 03, 2022 12:32 pm

Using Lib ssd1306.py with 128x32 OLED display
I found that tying 3v3_EN High gets rid of this error.

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 19, 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
Regards,

Mike2545

Conrad
Posts: 2
Joined: Mon Apr 11, 2022 11:46 pm

Re: Having an issue getting the lib for the SSD1306 working

Post by Conrad » Mon Apr 11, 2022 11:51 pm

Hi Mike2545,

I'm also getting EIO error with Tiny 2040 and oled 128x32, tried delays. Can you explain what you did to 'tying 3v3_EN High' ?

Thanks.

Shards
Posts: 39
Joined: Fri Jun 25, 2021 5:14 pm
Location: Milton Keynes, UK

Re: Having an issue getting the lib for the SSD1306 working

Post by Shards » Tue Apr 12, 2022 9:22 am

No one is saying what boards they are using. I assume the 3.3v Enable pin is on the processor board and controls output on the 3.3v external supply. The majority of boards just have 3.3v available so this is unlikely to be the problem.

I would suspect hardware though. You do have pull up resistors on SDA and SCL don't you?

Conrad
Posts: 2
Joined: Mon Apr 11, 2022 11:46 pm

Re: Having an issue getting the lib for the SSD1306 working

Post by Conrad » Tue Apr 12, 2022 12:04 pm

Thanks for reply.

No I don't have pull up resistors on either line - I've only seen this mentioned in one Youtube video and this was when multiple devices were connected on the one I2C bus, all other references (youtube/code) to oled and Tiny/2040 make no mention of these. I will add these next and re-try, 330ohm I think, was mentioned.

I now suspect this is the problem.

Scanning for addresses also returns [] so nothing found.

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

Re: Having an issue getting the lib for the SSD1306 working

Post by Roberthh » Tue Apr 12, 2022 12:21 pm

If the wires are not long 4700 Ohm is a typical value. 330 Ohm is more at the lower edge, resulting in 10mA sink current.

luisfelipeSald
Posts: 1
Joined: Thu Apr 28, 2022 8:32 pm

Re: Having an issue getting the lib for the SSD1306 working

Post by luisfelipeSald » Thu Apr 28, 2022 8:38 pm

Pigeon wrote:
Wed Oct 13, 2021 10:19 pm
have the SSD1306.py in my Lib forler.

Trying to run some simple code:

Code: Select all

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

WIDTH = 128
HEIGHT = 64

i2c = I2C(0, scl = Pin(17), sda = Pin(16), freq=200000)

oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)

oled.fill(0)

oled.text("I CAN HAZ PANCAKE?", 10, 10)

oled.show
But when I run it I get the following error in Thonny:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 10, 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
some googling suggested it could be the I2C address being wrong for my module, but when I do a

Code: Select all

i2c.scan()
I get a reply of [60] so think that means its the default 0X3C?

Hi, I had the same problem, I solved it by changing the I2C port that I was using, i also change the frequency, from 200000 to 400000, and made some tests with it. In both cases the screen worked properly.
Hope you find this useful :D

Code: Select all

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


width = 128
height = 64

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

oled = SSD1306_I2C(width, height, i2c)

oled.fill(0)

oled.text("Hola perro", 5, 8)
oled.text("2022", 5, 18)
oled.show()

Post Reply