Hi,
I had issues with the example code of the PIR motion sensor as using Serial.println(“MOTION DETECTED!!!”); in an Interrupt function causes this error if you use the motion sensor multiple times while the esp32 is running.
source: https://stackoverflow.com/questions/71992044/esp32-core-1-paniced-interrupt-wdt-timeout-on-cpu1
To fix it I applied another boolean and moved the Serial.println(“MOTION DETECTED!!!”); to the void loop where it is no problem to use.
https://pastebin.com/Lf7bxWi1
Maybe this can be changed in the course so others are not struggeling with the same issue.
Hi.
Thanks for the feedback.
We’ll resolve that issue in the next eBook edition.
Regards,
Sara
Hi Sara,
thank you 🙂 I also want to say that I’m very happy with the course as it really helped me a lot to.
Great job with the course.
Best,
Kai
That’s great. Thank you.
I’m glad you’re enjoying the course.
I’ll mark this issue as resolved. If you have any doubts or need any help, you just need to open a new question in our forum.
Regards,
Sara
I’m butting my head against that problem right now, have been on it for many hours. I was able to prove I had no hardware issues by downloading an alternative interrupt sketch and modifying it to debounce the sensor.
I’ll now try and get this sketch running and understand what is going on. I haven’t been able to source enough information from around the net to understand what the original problem is exactly.
The online resources are what need fixing the link in the Ebook takes you there, but it is wrong. Should be a fairly easy fix that doesn’t need to await an Ebook update.
Mike.
Hi.
I’m sorry. You are absolutely right. That was my fault.
I’ve just fixed the code in the link. It should be working now.
I’m sorry for the inconvenience.
Regards,
Sara
Thanks Sara,
I will open the link again and keep on with it. I will use it as an opportunity to compare the code and try to learn something.
Regards,
Mike
I have downloaded the changed sketch and it works fine for me. I’ve printed out and compared the changes.. Now I need to work out fully why and how. I’m treating it as an opportunity to learn.
I attempted to get to this spot independently but was beyond me at this moment.
Regards,
Mike
Hi Mike.
Here’s a quick explanation:
Interrupts are useful for making things happen automatically in microcontroller programs and can help solve timing problems. With interrupts you don’t need to constantly check the current pin value. When a change is detected, an event is triggered (a function is called).
When an interrupt happens, the processor stops the execution of the main program to execute a task, and then gets back to the main program.
This is especially useful to trigger an action whenever motion is detected or whenever a pushbutton is pressed without the need for constantly checking its state.
The interrupt handling function should be as simple as possible, so the processor gets back to the execution of the main program quickly. The best approach is to signal the main code that the interrupt has happened by using a global variable, for example. That’s what we’re doing with the motion variable.
In previous versions of the Arduino core, it was ok to use Serial.print() inside the interrupt handling routine. But, with the updates, it now crashes the ESP32. So, we can conclude that the Serial.print() task is too much to be running on the interrupt handling routine. so, we need to run it on the loop() instead.
I hope this helps you understand.
Regards,
Sara
Thanks again Sara,
Here I was thinking it was mostly a contact debounce issue. The upside of this, is the opportunity to explain the difference when it comes time to update the Ebook.
Regards,
Mike.