If you code your module into an endless loop.....

Code tips and tricks for beginners
Post Reply
Zim
Posts: 281
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 258 times
Been thanked: 128 times

If you code your module into an endless loop.....

Post by Zim »

If your a beginner like me, you will some day find yourself in a endless loop from your code, and can't communicate with the module.
READ the help file on "Recovery Mode". Shorting Tx and Rx pins together will allow you to boot up in a "virgin state" allowing you to edit your code.

Glad I read this before losing ALL my hair! Hope I saved you some!

Zim
BeanieBots
Posts: 344
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 180 times
Been thanked: 112 times

Re: If you code your module into an endless loop.....

Post by BeanieBots »

Wait till you have code which does a sensor read and then sleeps!
I now always put in a removeable hardware link to a GPIO pin and test in code to decide sleep or no sleep. :oops:
The watchdog timer is also very handy for getting out of endless loops.
Zim
Posts: 281
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 258 times
Been thanked: 128 times

Re: If you code your module into an endless loop.....

Post by Zim »

Wait till you have code which does a sensor read and then sleeps!
LOL LOL!

Thats exactly what I did!

Zim
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 124 times
Been thanked: 132 times

Re: If you code your module into an endless loop.....

Post by AndyGadget »

Ah yes, been there done it.
When I'm using sleep commands I'll put in a 10 second delay at the beginning of the program while I'm debugging.
It gives me a chance to halt the program before it gets to the sleep routine.
Such as when I used SLEEP 60000, before remembering the time is in seconds, not milliseconds :oops:
Zim
Posts: 281
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 258 times
Been thanked: 128 times

Re: If you code your module into an endless loop.....

Post by Zim »

If shorting Rx toTx doesn't work for you (as I have found on some ESP32) , try the online flasher. Enter atleast one change in the "config" prompt and uncheck all check marks on the firmware page. This will only erase the config page and prevent running the auto start bas. file.

Cheers
Zim
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: If you code your module into an endless loop.....

Post by Electroguard »

Good tip Zim.
If shorting Rx to Tx doesn't work for you (as I have found on some ESP32)...
And for modules like S2's which don't have conventional RX and TX for shorting together to break out of an endless loop, it may be worthwhile defining the onboard gpio0 button interrupt branch just to issue an END instruction... then simply pressing the gpio0 button could halt the script.
Zim
Posts: 281
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 258 times
Been thanked: 128 times

Re: If you code your module into an endless loop.....

Post by Zim »

And for modules like S2's which don't have conventional RX and TX for shorting together to break out of an endless loop, it may be worthwhile defining the onboard gpio0 button interrupt branch just to issue an END instruction... then simply pressing the gpio0 button could halt the script.

Thanks Electroguard. Sounds like a good idea! I will try that.

Zim
Post Reply