0
votes

I came across this website when trying to find a reliable way to use the watchdog for preventing failures (code lock ups) and saving battery using an Arduino.

I tried the code and it worked fine. However, i would also like to use the serial monitor. I tried adding Serial.begin(9600); in the setup, however, most of what is shown in the serial monitor (from the code within the main loop) are strange characters (the baud rate is set to 9600). Is this something to do with the function to configure the wdt and the placement of Serial.begin(9600) in the code?

I'd also like to use an external interrupt (via a button on Digital pin 3) to wake the board from sleep. How can be achieved based on the current code? I know how to implement using a different method of making the board go to sleep without using any watchdog at all, however, i have been unsuccessful in making it work with this code.

Many thanks for any help.

1
Serial and Watchdog should not be a problem. Did you set your watchdog time to short? ... possibly your routine got to long?Fruchtzwerg
I've set it so the time before the watchdog fires is 8 seconds. And the program as it is with delays, takes a bit over 2 seconds, so it shouldn't be an issue of the watchdog time been too short. I added Serial.begin(9600); at the very first line after setup and a message to say the program is starting. This shows fine in the serial monitor. Any printing in the main loop is just random characters though.Maus
Serial should not be te problem. Look here: forum.arduino.cc/index.php?topic=63651.0Fruchtzwerg
In setup(); , i have added Serial.begin(9600); and below this line is Serial.println("starting..."); These show fine in the serial monitor. Any printing in the main loop() are just random characters.Maus

1 Answers

0
votes
  • As said above, the serial communication should work fine. Are you sure you are able to make your serial communication work fine without the watchdog part of the code? I have used the watchdog tips given on the website along with serial communications without any problem on Arduino Uno, so I would guess the serial communication problem lies somewhere else in your code. Can you write a bare bone example of your code with the watchdog management part, a serial communication or two somewhere in your loop(), and if you want some delays / infinite loops to test the watchdog firing, post it here, test it on your board and indicate if / where you have problems?

  • I have never used a pin interrupt, but it seems that google gives some nice results with example code. Have you tried the results given by google?

https://www.arduino.cc/en/Reference/AttachInterrupt

http://www.allaboutcircuits.com/technical-articles/using-interrupts-on-arduino/

You will have to be careful regarding the choice of the pin on which you put the interrupt, as explained in the Arduino Reference only pins 2 and 3 support interrupt on the Uno.