Created
June 10, 2014 11:42
-
-
Save timpulver/f2c1e2524dedf05380b7 to your computer and use it in GitHub Desktop.
[Arduino, Watchdog] Soft-Reset Arduino using Watchdog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Watchdog example | |
| * | |
| * Send 'r' through serial to reboot the Arduino, when it's back up, "Boot..." should appear. | |
| */ | |
| // include watchdog, part of avr-gcc compiler | |
| #include <avr/wdt.h> | |
| void setup(){ | |
| wdt_enable(WDTO_2S); // we need to pet the dog at least every 2 seconds | |
| Serial.begin(9600); | |
| while (!Serial) { | |
| ; // wait for serial port to connect. Needed for Leonardo only | |
| } | |
| Serial.println("Boot..."); | |
| } | |
| void loop(){ | |
| wdt_reset(); // let's pet the dog | |
| while (Serial.available()) { | |
| Serial.println("Got char"); | |
| char inChar = (char)Serial.read(); | |
| switch(inChar){ | |
| case 'r': | |
| reboot(); | |
| break; | |
| } | |
| } | |
| } | |
| void reboot(){ | |
| while(1){} // let's stay here and ignore the dog | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment