Page 1 of 1

ssd1306 OSError: I2C operation not supported

Posted: Fri Apr 13, 2018 5:26 pm
by gpson
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?..

Re: ssd1306 OSError: I2C operation not supported

Posted: Sat Apr 14, 2018 11:25 am
by pythoncoder
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 :?

Re: ssd1306 OSError: I2C operation not supported

Posted: Sat Apr 14, 2018 1:32 pm
by gpson
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)

Re: ssd1306 OSError: I2C operation not supported

Posted: Sun Apr 15, 2018 9:50 am
by pythoncoder
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)

Re: ssd1306 OSError: I2C operation not supported

Posted: Tue May 01, 2018 10:56 am
by alayi
i2c = I2C(2) ----> i2c = I2C(1)

Re: ssd1306 OSError: I2C operation not supported

Posted: Mon Mar 25, 2024 3:52 pm
by moefear85
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.