Monday, December 23, 2013

Good to knows - 4

Using the watchdog to reset the mcu if something goes wrong:

See
#include 

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

This code comes from http://forum.arduino.cc/index.php?topic=128717.msg968831#msg968831

Obviously this can be used to trigger a restart when you detect an error (if error --> while(1){})


No comments:

Post a Comment