0

I'm trying to add a watchdog on an Arduino Nano, for my code, and I'm following exactly code in this manual, but after the amount of time for not resetting the watchdog- it resets but does not reboot.

At last paragraph- it says that :"

However, I could not find something similar in Optiboot bootloader (If I'm wrong, correct me please!), used by Arduino UNO and other new boards. It seems that they sacrificed this check for size. So, it is possible that watchdog timer will be enabled after reset, so - if you set it's value too low, your board may never come out of bootloader stage. So, to be always on the safe side, set watchdog to longer periods (2S and more).

So I've tried for 8s, but still same result.

What is wrong ?

EDIT1:

#include <avr/wdt.h>
int k=1;
void setup() {
  Serial.begin(9600);
  wdt_enable(WDTO_8S);
}
void loop() {
  //do stuff here
  k++;
  wdt_reset();
  Serial.println(1000 * k);
  delay(1000 * k);

}
  • Please describe "resets but does not reboot". What happens? What does not? Try section 11.8 of the Atmega328p datasheet which describes the operation modes of the watchdog timer. You may need some additional setup to get the result you want. – JRobert Nov 9 '18 at 22:45
  • Please post the actual test code you are using. The linked page only shows code which should not reset unless "do stuff here" takes too long. (Edit your question to do this). – Nick Gammon Nov 10 '18 at 1:51
  • @NickGammon added – Guy . D Nov 10 '18 at 9:57
  • As @JRobert said, what do you mean by "it resets but does not reboot"? Do you mean the watchdog timer resets, or the processor resets? If the processor resets then it would reboot. – Nick Gammon Nov 11 '18 at 6:33
1

the "old" Nano bootloader doesn't clear the Watchdog flag and while the bootloader waits for the upload, the board resets.

flash the "new" bootloader to Nano

In IDE 1.8.6 you can select version of Nano in Tools menu. It is the 'new' bootloader if you select "Atmega328p" and 'old' if you select "Atmega328p (Old bootloader)". If you invoke "Burn bootloader" it will use the bootloader for the selected option.

  • Can you please refer ? – Guy . D Nov 10 '18 at 10:05
  • how to burn bootloader? you need a programmer or other Arduino. arduino.cc/en/Tutorial/ArduinoISP – Juraj Nov 10 '18 at 10:09
  • where to get this "NEW" bootloader ? – Guy . D Nov 10 '18 at 10:10
  • I enhanced the answer – Juraj Nov 10 '18 at 10:18
0

This works on an Uno R3.

The sketch restarts every 4 seconds when wdt_reset() is commented out.

Please copy the code and try it.

  #include <avr/wdt.h>

  void setup() {
    pinMode(13,OUTPUT);
    digitalWrite(13,LOW);

    delay(50);
    digitalWrite(13,HIGH);    // flicker the LED to identify when setup() is running
    delay(50);
    digitalWrite(13,LOW);
    delay(50);
    digitalWrite(13,HIGH);
    delay(50);
    digitalWrite(13,LOW);
    delay(50);
    digitalWrite(13,HIGH);
    delay(50);
    digitalWrite(13,LOW);
    delay(50);

    wdt_enable(WDTO_4S);

  }
  void loop() {
    digitalWrite(13,HIGH);
    delay(500);
    digitalWrite(13,LOW);
    delay(500);
    //wdt_reset();
   }
  • hi- same affect... perhaps Uno and Nano behave not the same ? – Guy . D Nov 10 '18 at 10:01
  • @Guy.D: We still need to know what you see happening and what you expected would happen instead. – JRobert Nov 11 '18 at 13:20
  • @JRobert I’ll describe what I see: code run ok until time that wdt does not get its reset ( which I do on purpose). After that leds on board start to flicker non stop, and data stop posting on serial monitor ( this part I call- reset ). Only after a power off - board is booting back up. If I wouldn’t power off- that flickering state would keep forever. – Guy . D Nov 11 '18 at 14:40
  • this makes no sense .... the code that i posted flickers the LEDs during setup(), but there is no serial I/O code ..... it appears that you are not loading the new sketch into the Arduino, just rerunning the old sketch – jsotola Nov 11 '18 at 18:05
0

After that leds on board start to flicker non stop, and data stop posting on serial monitor

Definitely have a read of the datasheet for the '328p, section 11.8. There are several modes of operation - it can interrupt; reset; or both. Even if it resets, it doesn't reload your initial RAM data, so, for instance, line 2 int k=1; looks like an executable statement but is an initializer and has no effect at reset, and k retains its current value. There are probably other, similar, anomalies that happen when the WDT fires.

You probably don't need to understand the WDT down to its last control-bit but definitely make sure you're using it in the mode you want to be in. It will probably be handy during your testing to have a tiny sketch that just disables the watchdog so you can quickly get your Arduino back for the next test.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.