Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By John Snow
#38073 Hi everyone

I have the ESP8266 from Olimex
https://www.olimex.com/Products/IoT/ESP ... e-hardware

I'd like to use the ESP as a I2C-Master. It's horrible but i spend so many hours today and a did not even get a signal on one of the pins. Ckecked it with an oscilloscop. I would really appreciate if someone could tell me which of these pins on this piece here are SCL and SDA:
https://www.olimex.com/Products/IoT/MOD ... e-hardware
and the shematics:
https://github.com/OLIMEX/ESP8266/blob/ ... ematic.pdf

Another thing I'd like to know is, how to use I2C in the Arduino Code. I'm rly confused about this. Today I read SCL and SDA are either Pin 0 and 2, 2 and 4, 4 and 5 and I even heard that there is only Software I2C possible on the ESP8266.

In fact I already worked with I2C on Arduino, but with an Arduino Mega board only, that seems to be somewhat easier.

I would be super thankful if someone could give me just a little piece of code, how to initialize I2C on the ESP.

Greetings John
User avatar
By martinayotte
#38082 The Arduino ESP has already the Wire library, so simply use it !
The pins number can be provided to the constructor.
Yes, on ESP, the I2C is software bit-banging.
Personally, I'm using GPIO2 and GPIO0 pins since they have already pullup resistors for the boot mode, so it is a perfect match for using them for I2C bus and leave other GPIOs for something else.
I've used GPIO Expander MCP23017 since almost a year, and recently, I've added an OLED SSD1306 display.
User avatar
By martinayotte
#40587 You're right !
Current implementation of ESP I2C library is Master only.
That should make Slave version undoable, it is simply it is a lot trickier, since Slave needs to receive the SDA/SCL asynchronously using interrupts and since ESP Wifi is also using interrupt, it can become a problem if missing some.