1

I'm using the same script(and standard wire and serial library only) one uploaded to Arduino nano one uploaded to ESP8266. However, despite ESP8266 running at 160MHz, 10 times faster than nano, it's taking 3.5 ms to complete the loop, compare to 2.5 ms than that of nano.

How could that be? why ESP8266 was slower?

  • 3
    It depends on what the script is doing. In practice the ESP8266 will almost always be faster. An exception might be I2C (the Wire library, like in your test). The Arduino Nano AVR processor has hardware support for I2C; the ESP8266 must use the much slower “bit banging” method. – StarCat Feb 19 at 21:51
  • @StarCat will the same thing (wire) happen to esp32? – ShoutOutAndCalculate Feb 19 at 21:58
  • 1
    It depends. Please show us the code. – the busybee Feb 20 at 7:25
  • 2
    @ShoutOutAndCalculate, The ESP32 has hardware support for I2C so should be able to run faster. – StarCat Feb 20 at 7:30
  • 1
    You can use internal pull ups, but the consensus seems to be that they are too weak for fast I2C operation and that external pullups are better (around 4.7K Ohm). – StarCat Feb 20 at 8:01
3

However, despite ESP8266 running at 160MHz, 10 times faster than nano, it's taking 3.5 ms to complete the loop, compare to 2.5 ms than that of nano.

There's a number of reasons for that. Chiefly:

  1. The ESP8266 has no I2C hardware, so has to use software "bit-banging" to emulate I2C. That is slower to execute.
  2. The ESP8266 also has to manage the WiFi hardware which takes a portion of the processing power away from the user

The result is slower execution for I2C operations and "jitter" added to timings of loops and such.

will the same thing (wire) happen to esp32?

No (or not as much). The ESP32 has hardware I2C so it doesn't need to use bit-banging to emulate it, so it will be faster. Also it is dual core and one core is used for "system management" including managing the WiFi and Bluetooth, while the second core is used to execute your sketch, so there is no (or little1) interruption by the WiFi slowing down your sketch.


1: Two cores accessing the same area of RAM causes some contention as only one core can access the same block of RAM at a time, so it's not perfect. You may still get slight delays, but they will be minuscule compared to the processing needed for the ESP8266's WiFi code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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