Watchdog in Arduino Library - or at least support by bootloader

... it seems to be very complicated using Arduino 1.0.1 ...

Doesn't seem complicated to me:

#include <avr/wdt.h>

void setup ()
{
  Serial.begin (115200);
  Serial.println ("Restarted.");
  wdt_enable (WDTO_1S);  // reset after one second, if no "pat the dog" received
 }  // end of setup

void loop ()
{
  Serial.println ("Entered loop ...");
  wdt_reset ();  // give me another second to do stuff (pat the dog)
  while (true) ;   // oops, went into a loop
}  // end of loop

You need a bootloader that doesn't get into a loop if you have the watchdog fire, but that is just an issue of uploading the right bootloader.

1 Like