Chat freely about anything...

User avatar
By Chapu206
#79413
QuickFix wrote:
Chapu206 wrote:But my board is NodemCu with micro ESP8266.

So? :?

A NodeMCU (development board) uses an ESP-12E (module), which has an ESP8266 (chip) inside:
Image
An Arduino is development board with an Atmel (chip):
Image
It is possible to program the ESP8266 (the first picture) with code for an Arduino (the second picture), but then you need to change some things to make it compatible. :idea:
The most common changes are inserting yield()-commands (or delay(0)) in tight loops.


--------------------------------------------------------------------------------------------------------------------------------------------------------

Dear thank you very much,
But I have no idea how to do it, could you please send me an example?
Thanks very much!!!
User avatar
By QuickFix
#79421
Chapu206 wrote:But I have no idea how to do it, could you please send me an example?

We're here to help others, not to write code for others.

The solution is like I explained earlier, but I'll tell you the general process:
  • Search the code for "For" and "While" loops.
    In the block that belongs to the loop (the code between the { and } accolades following the loop-statement), see if there are already any calls to either yield() or delay().
    • If it already has: you (generally) don't have to do anything with that block
    • If it has not: insert a yield() or delay(0) somewhere in that block
  • The main loop() is also just a loop (like a for and a while) and inside this loop there also needs to be at least a yield() or delay(0) inserted if not already there
It's not always necessary to insert a yield() or delay() in every loop: with very short loops or in nested loops you only have to yield() or delay() less often.

The reason behind having to use yield() or delay() is to reset the (software) watchdog of the WiFi stack: if it isn't reset every 3 seconds (or so) it will trip and the entire ESP will be reset.
Some helpful reading: ESP8266 Watchdogs in Arduino :idea: