So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By chputney
#78860 I am working on a small handheld vehicle speed detector which will report the results to ThingSpeak thru WiFi. The speed is detected by a radar doppler module and inputs a frequency of about 1000Hz for a vehicle speed of 50kph. I am measuring the input wave frequency using interrupts and this part is working. The report of the vehicle speed to ThingSpeak is working also, but when I put the two parts together, the ESP8266 crashes.

I think that after WiFi starts, an interrupt causes a crash.

I am using Arduino IDE for ESP8266.

I have seen other views on the internet that suggest turning off interrupts during WiFi activities, but with WiFi activities taking seconds, this is the reason for interrupts.

Is this a known problem of using interrupts during WiFi ?
User avatar
By QuickFix
#78874 Pictures, logs and/or sketches or it didn't happen. ;)

Two things to keep in mind:
  • The WiFi-stack is the most important process of an ESP: if you neglect it (giving it not enough time to do its work) it will reset your ESP.
  • Interrupts need to be as short as possible: actually only setting (or increasing) some global variables and not much more.
    No reading or writing to WiFi or serial (these also use interrupts), no delays and no (long) loops
Following the second rule we can only crunch numbers (like determining the frequency output by the module) and act upon this in the main loop, not forgetting to regularly yield() the WiFi stack as stated in the first rule.

To follow up on that first rule: if the WiFi process needs too much processor time, that's just hard luck for the main loop: the WiFi stack always has precedence over everything else.
User avatar
By rudy
#78884 If I were doing your application I would use two processors. Either the ESP8266 and another microcontroller doing the hardware IO, or the ESP32, one core for the WiFi and the other doing the IO.
User avatar
By chputney
#78931 Okay, thanks for the tips. I was making the interrupt routine a few lines, and putting in yield() every other line in the loop and I was still having problems. Well, I used a GPIO as output and turned it on at the start of the interrupt and turned it off at the end, and then looked at this on my scope to measure the interrupt time. To my amazement, instead of an interrupt every millisecond, I saw a lot of high frequency fuzz, and realized that I was looking at the wrong problem all the time.

For testing, I had an Arduino Nano output a square wave at 1000Hz for 2 seconds and then rest for 10 seconds to simulate the radar return from a car. Well, the square wave looked clean to me, so it did not occur to me that there would be any trouble triggering on the edge.

Well, there was maybe 25mv noise on this output and that was enough to trigger the interrupt multiple times.

So, I give up on interrupts. I went back to sampling the period periodically in the main loop.

I did think about using the Nano to do the measuring and (somehow) get the message to the ESP8266, but I will try polling first before I add a processor.

Thanks for the advice.