Compare the YouTube video and this webpage, the former one made programming very different in ESP32 and that was in Arduino nano, while the webpage seemed to imply that they work exactly the same.

Can we use the same code for standard Arduino library, like wire library, for ESP32 and ESP8266, or do we have to do something different?

  • 2
    in the video he doesn't use Arduino, but the Espressif IDF framework directly. the Arduino esp32 boards package has the Wire library for Arduino
    – Juraj
    Feb 8, 2020 at 18:39
  • @Juraj so does ESP 32 and ESP 8266 used exactly like Arduino for standard libraries? I heard the methods of pin labels were a little bit different. Feb 8, 2020 at 21:49
  • 1
    I had no trouble to use the same sketch with Wire library on Uno and esp8266
    – Juraj
    Feb 9, 2020 at 5:57
  • 1
    software is the same. watch the voltages and pullups.
    – dandavis
    Feb 9, 2020 at 20:38

1 Answer 1


Code using the Arduino Wire library is generally portable between processors, but there are pitfalls to watch for. One that I'm aware of is a difference in the Wire libraries for the ESP32 and ESP8266. The TwoWire::begin() method for the ESP32 has prototype:

bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency);

whereas for the ESP8266 it is:

void TwoWire::begin(int sda, int scl, uint8_t address);

So, a call to begin() using the ESP#2 library will set the clock using the third parameter, whereas on the ESP8266 it will truncate the third parameter and use it as an address.

If you wish code to be portable between the ESP32 and ESP8266, then the fix for this particular issue is to call TwoWire::begin( my_SDA_pin, my_SCL_pin ) (specifying only two parameters:the SDA and SCL pins), and use a separate call to TwoWire::setClock( my_clock_speed ) to set the clock.

There may be other differences I'm not aware of...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.