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: 19
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: 2479
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

gpson
Posts: 19
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: 2479
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

Post Reply