The watchdog not only provides a recovery path from failed software it also provides a recovery path from failed hardware. It is always a bad idea to call blocking functions like Serial.println in the context of an interrupt service routine. It is an especially bad idea to call a blocking function in the watchdog interrupt service routine. If the USART has stopped working correctly, the call to Serial.println may never return; the processor may never reset.I think your article is well written. I obviously stand to be corrected here but does the millis overflow not cause the arduino to freeze?
I cant say ive left any arduino on for more than 3 days, I was led to believe it encountered an error after 49 odd not days?Nope, it wont fire unless you remove the wtdreset, the code was really more of a blank template than a functional example. I guess I could create a series of growing loops that would eventually cause a time-out. At the time of writing I just thought it simplest to leave things relatively blank for people to fill in the dotsI will correct the PDF when I get back to my desktop in the morning. Code: // static variableunsigned long lastFiredTime.// in loop or some such placeunsigned long now = millis ;unsigned long interval = now - lastFiredTime;lastFiredTime = now;Because of the way unsigned integers overflow, the variable 'interval' will be correct, regardless of whether millis has overflowed or not.
That is, unless the interval itself exceeds 49.7 days (because that is all that will fit in it).Certainly nothing freezes if it overflows, it is just an integer arithmetic overflow. They happen all the time.
For all of the different kinds of small OLED monochrome displays, you'll need to install the Arduino libraries. The code we have is for any kind of Arduino, if you're using a different microcontroller, the code is pretty simple to adapt, the interface we use is basic bit-twiddling SPI or I2C. Today i made a example for the FS1000A 433mhz Wireless Transmitter and receiver set. I am testing these for my website and will set them for sale on the website soon.
Quote I may be wrong here as this is something hew to me, but one thing you might want to consider in your guide is to alter the example code fractionally to move the watchdogSetup; line to the top of the setup function.I think you're actually relying on code in the bootloader to disable the watchdog before you enable it here.I was having issues because I was not using a bootloader.Once the WDT fires, it's left enabled at restart, but the duration is set to the minimum time (I think - read it somewhere & it seems to fit my experience). It then fires again within the delay(500), and your locked in to an infinite loop.With the watchdogSetup at the top of the setup the code will work fine with or without a bootloader (though it'll still fail for a bootloader that doesn't handle the WDT properly). Zanic, thanks for the description. As the post above may have indicated, I've been avoiding the wdt on the mega 2560 board because the bootloader doesn't initialize it properly. The board would hang up in a loop, requiring a power cycle to recover. That meant that I had to fake a watchdog using timer 3 on the board.
That was not a very satisfactory solution especially since the watchdog should be able to do this job.Well, your description got me to thinking and I came up with a solution that uses the watchdog AND allows me to have a much longer watchdog timer. This is exactly the solution I needed to free up timer three and put the job back on the watchdog like it should be. I still can't use WDE, but that problem is easy to work around. Here's the code if you want to include it at some point or just to expand your example.Nice job.
Thanks very much for the feedback draythomp- Ive only got UNOs sitting on my desktop at home which is why I haven't encountered any of the problems you guys are bringing up. I may update the tutorial at some stage or another but for now the forum thread is short enough for someone to be able to skim and make changes at a glance - great timer work-around!I presume you only added the Serial in the WDT interrupt to debug and get some sort of feedback - Ive never encountered any problems but just be aware if serial happened to be the function that caused the board to malfunction and prompt a WDT interrupt, It may cause the interrupt to hang if you bring up serial in the interrupt and you will never get around to resetting the board.Thanks again for the feedback!
Such contributions are what make forums such great mediums.