Watchdog Arduino Yun

Hi,

I am trying to implement the watchdog on my Arduino with the following code

#include <avr/wdt.h>

void setup() {
  Serial.begin(9600);
  MCUSR = 0;
  wdt_disable();
  delay(1000);
  Serial.println("Setup");
  wdt_enable(WDTO_1S);
  
}

void loop() {

    for (int i = 0; i < 100; i++) {
      delay(100*i);
      wdt_reset();
      Serial.println(100*i);
    }
    
    
}

It only stops running the code but no reboot. Have anyone experienced the same?

thanks

Your code won't even compile so of course it won't reboot your Yun.

I would recommend calling Serial.begin() in setup().

Sorry, I have updated the code and also added Serial.begin(9600). The code iterates from 0 to 1000 then it stops. It should have been running the setup again...

It still won't compile. It's common courtesy to hit the compile button in the Arduino IDE and verify that your code is OK before posting it to the forum.

Should be compiling now.

 #include <avr/wdt.h> 

void setup() {
  Serial.begin(9600);
  MCUSR = 0;
  wdt_disable();
  digitalWrite(13, 1);
  delay(4000);
  Serial.println("Setup");
  wdt_enable(WDTO_1S);
  
}

void loop() {
  digitalWrite(13, 0);
    for (int i = 0; i < 100; i++) {
      delay(100*i);
      wdt_reset();
      Serial.println(100*i);
    }
}

With this code my ledpin 13 is flashing - Indicating that it runs the setup function after the reset. However, after the first reboot I have to re enter the monitor to see the Serial.print() again