vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.96k stars 728 forks source link

suggested delay value for TINY_GSM_YIELD() #409

Closed lg007 closed 4 years ago

lg007 commented 4 years ago

Hello,

I have a setup with a SIM800L and a Lolin Lite 32 (ESP32) board running at 240 MHz and I am using the MQTT example to receive some messages. In order to have it working properly, I had to add:

#define TINY_GSM_YIELD() { delay(4); }

The value for the delay function was just a guess, but it seems to work. Without this delay, the ESP32 was resetting itself continuously.

My question is simple: how should I calculate the value of the delay? Is there some kind of formula or should I just try and guess?

Any help is appreciated!

SRGDamia1 commented 4 years ago

It should be (roughly) one or two character spaces at the baud rate your talking to the modem with. If your MCU is too fast and the baud rate is too low, strings might end up chopped up if you don't wait for them. Some boards are just touchier than others, too and extra tiny delays help.

I usually use 2, with an 8MHz MCU and 9600 baud. If it's stuttering, give more delay or increase the baud rate (or both). If you're missing characters, try decreasing it.