ESP-01 I2C

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
ta1db
Posts: 53
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

ESP-01 I2C

Post by ta1db » Sat Nov 16, 2019 2:23 pm

Would anyone kindly help me to run machine.I2C module on ESP-01
Which pin numbers should I use for GPIO0 and GPIO2 ?
I found an example here : https://www.dobitaobyte.com.br/i2c-com- ... cropython/ like that

Code: Select all

from machine import Pin, I2C
sda = Pin(12)
scl = Pin(14)
i2cbus = I2C(scl,sda)
if I am not wrong the Pin(12) is not available on ESP-01.
Here https://primalcortex.wordpress.com/2015 ... -01-board/ it says ESP8266 can create and use an I2C bus on GPIO0 GPIO2 pins, here https://www.forward.com.au/pfod/ESP8266 ... magic.html the writer talks about ESP8266-01 Pin Magic; however I couldn't find a way to implement it in MicroPython.
I appreciate your help.

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

Re: ESP-01 I2C

Post by Roberthh » Sat Nov 16, 2019 3:47 pm

GPIO0 is Pin(0), GPIO2 is Pin(2). Both must not be 0 upon boot for normal opeartion, but pulling them up for I2C is no problem. So your code snippet would e.g. be

Code: Select all

from machine import Pin, I2C
scl_pin = Pin(0)
sda_pin = Pin(2)
i2cbus = I2C(scl=scl_pin, sda = sda_pin)
I used scl_pin and sda_pin to point at the difference between a keyword parameter and the name of the variable.

User avatar
ta1db
Posts: 53
Joined: Mon Sep 02, 2019 12:05 pm
Contact:

Re: ESP-01 I2C

Post by ta1db » Sat Nov 16, 2019 7:18 pm

Thank you very much Roberth, it worked!

Post Reply