ssd1306 OSError: I2C operation not supported

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
gpson
Posts: 21
Joined: Sun Jul 31, 2016 6:55 am

ssd1306 OSError: I2C operation not supported

Post by gpson » Fri Apr 13, 2018 5:26 pm

I connected the I2C ssd1306 module to my pyboard and can not get it to work

Uploaded the library https://github.com/micropython/micropyt ... ssd1306.py

The test code:

Code: Select all

from machine import I2C
i2c = I2C(2)
import ssd1306
display = ssd1306.SSD1306_I2C(128, 64, i2c, 60)
and the error:

Code: Select all

Traceback (most recent call last):                         
  File "main.py", line 15, in <module>                     
  File "app_oled.py", line 6, in <module>                  
  File "ssd1306.py", line 99, in __init__                  
  File "ssd1306.py", line 36, in __init__                  
  File "ssd1306.py", line 63, in init_display              
  File "ssd1306.py", line 91, in show                      
  File "ssd1306.py", line 109, in write_data               
OSError: I2C operation not supported                       
MicroPython v1.9.3-548-gd12483d9 on 2018-04-13; PYBv1.1 wit
h STM32F405RG                                              
Type "help()" for more information.                        
>>>
What could be wrong?..

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ssd1306 OSError: I2C operation not supported

Post by pythoncoder » Sat Apr 14, 2018 11:25 am

I think you're confusing the machine and pyb implementations of I2C. Your instantiation is for the pyb version. If you substitute

Code: Select all

from pyb import I2C
it should work.

I agree the two versions are confusing :?
Peter Hinch
Index to my micropython libraries.

gpson
Posts: 21
Joined: Sun Jul 31, 2016 6:55 am

Re: ssd1306 OSError: I2C operation not supported

Post by gpson » Sat Apr 14, 2018 1:32 pm

Well, with pyb there is another error :/

Code: Select all

from pyb import I2C
# from machine import I2C
i2c = I2C(2)
import ssd1306
display = ssd1306.SSD1306_I2C(128, 64, i2c, 60)

Code: Select all

PYB: sync filesystems                                                                   
PYB: soft reboot                                                                                                                                                  
Traceback (most recent call last):                                                      
  File "main.py", line 15, in <module>                                                  
  File "app_oled.py", line 6, in <module>                                               
  File "ssd1306.py", line 99, in __init__                                               
  File "ssd1306.py", line 36, in __init__                                               
  File "ssd1306.py", line 61, in init_display                                           
  File "ssd1306.py", line 104, in write_cmd                                             
AttributeError: 'I2C' object has no attribute 'writeto'                                 
MicroPython v1.9.3-548-gd12483d9 on 2018-04-13; PYBv1.1 with STM32F405RG                
Type "help()" for more information.                                                     
>>>
[UPDATE]

on the esp8266 this code is working with the same oled (not sure about the version of ssd1306 library):

Code: Select all

from machine import Pin, RTC, I2C
i2c = I2C(sda=Pin(4), scl=Pin(5))
import ssd1306
display = ssd1306.SSD1306_I2C(128, 64, i2c, 60)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ssd1306 OSError: I2C operation not supported

Post by pythoncoder » Sun Apr 15, 2018 9:50 am

Apologies, the driver is written for the machine module. You need to instantiate the I2C object with specific pins. This works on a Pyboard:

Code: Select all

pscl = machine.Pin('Y9', machine.Pin.OUT_PP)
psda = machine.Pin('Y10', machine.Pin.OUT_PP)
i2c = machine.I2C(scl=pscl, sda=psda)
Peter Hinch
Index to my micropython libraries.

alayi
Posts: 1
Joined: Tue May 01, 2018 10:54 am

Re: ssd1306 OSError: I2C operation not supported

Post by alayi » Tue May 01, 2018 10:56 am

i2c = I2C(2) ----> i2c = I2C(1)

moefear85
Posts: 5
Joined: Sat Oct 30, 2021 12:44 pm

Re: ssd1306 OSError: I2C operation not supported

Post by moefear85 » Mon Mar 25, 2024 3:52 pm

I2C was right, don't use pyb. The real reason for the error is confusing softI2C with hardware I2C. When you specify an I2C number (which i2c controller to use), then you are implicitly specifying it should be hardware i2c. In that case, the start/stop function's don't exist because they don't make sense, because they are only necessary for soft i2c when bitbanging the lines. So you need to avoid that call, or remove the i2c number, which implicitly makes micropython use a software i2c. but currently that throws a deprecation warning.

if you look at ` File "ssd1306.py", line 109, in write_data` you'll realize the function body attemps to call i2c.start()`, since the ssd1306 library in question expects it to be a software I2C. This means you either have to use software I2C, or modify the library, or use another one.

Post Reply