I2C pins on Laboris fw

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
cable134
Posts: 28
Joined: Sun Aug 20, 2017 10:51 pm

I2C pins on Laboris fw

Post by cable134 » Mon Oct 16, 2017 9:16 pm

Hi mates,

I'm trying to figure out which pins are available for the I2C with the help of the following script

Code: Select all

>>> import machine
>>> i2c=machine.I2C(sda=machine.Pin(25), scl=machine.Pin(23), freq=100000)
D (6073) intr_alloc: Connected src 49 to int 9 (cpu 1)
>>> i2c.scan()
[]
As you see, i2c.scan() returns None.

If I change I2C pins to G15 and G2 I will find in I2C bus my two devices.

Code: Select all

>>> import machine
>>> i2c=machine.I2C(sda=machine.Pin(15), scl=machine.Pin(2), freq=100000)
D (7337) intr_alloc: Connected src 49 to int 9 (cpu 1)
>>> i2c.scan()
[35, 119]
So does anybody know which GPIO pins work with machine.I2C ?
Thank you in advance.

P.S. Yes, I connected pull-up registers between VCC (+5v) and SDA and SCL.

cable134
Posts: 28
Joined: Sun Aug 20, 2017 10:51 pm

Re: I2C pins on Laboris fw

Post by cable134 » Mon Oct 16, 2017 10:25 pm

Update

I have a ESP32-WROOM dev board with the wrong text marks on some pins.
That was the point.

I changed Pin numbers and now it works fine.

BTW Also I changed Pull-up registers from 4.7K to 10K and now my I2C devices work fine with 3.3 VCC.

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

I2C pullups

Post by pythoncoder » Tue Oct 17, 2017 9:54 am

I find it surprising that 4.7KΩ pullups gave problems. The load is only 700μA!
Peter Hinch
Index to my micropython libraries.

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: I2C pins on Laboris fw

Post by loboris » Tue Oct 17, 2017 2:28 pm

@cable134
As I understand, you have 5V i2c device and pull-up resistors connected to +5V. It will not (probably) damage ESP32 as it has (probaby) some protection diodes on pins.
It is not a good practice to connect 3.3V device to 5V one.
You should use some kind of level shifter.

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

Level shifters

Post by pythoncoder » Tue Oct 17, 2017 4:29 pm

I hadn't spotted that. The fact that it only works with a higher value pullup suggests that something naughty is going on.

Definitely +1 for a level shifter, but it needs to be one designed for I2C because the interface design is dependent on open drain drivers.
Peter Hinch
Index to my micropython libraries.

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: I2C pins on Laboris fw

Post by loboris » Tue Oct 17, 2017 6:10 pm

Most of the cheap level shifters are simple MOS-FET shifters and are suitable for I2C.
Better and more expensive I2C level shifters are based on special IC like PCA9306.

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

Re: I2C pins on Laboris fw

Post by pythoncoder » Wed Oct 18, 2017 9:02 am

Clever use of the substrate diode!
Peter Hinch
Index to my micropython libraries.

Post Reply