arduino watchdog

KBennett

Member
Joined
Sep 17, 2012
Location
Brantford
Well, after two days of trying to burn a new bootloader to my spare mega 2560 r3, I've given up!

Instead, I am going to use an uno to monitor my controller's heartbeat (hardwired blinking signal) and reset it if it doesn't see a change within 10 seconds or so.  Much easier than burning a bootloader.
 

Neopimp

Website Doctor
Staff member
Website Admin
Joined
Jun 9, 2014
Location
Sarnia
lol we used that idea when i programmed plc s and robots:)  Simple and it works :)
 

AdamS

Active Member
Joined
Oct 7, 2012
Location
London, Ontario
Doesnt the watchdog work on the uno? Why not just use the uno or two, and rid yourself of the mega? You cant possibly need more outputs than 2 unos, can you?
 

KBennett

Member
Joined
Sep 17, 2012
Location
Brantford
I'm afraid ill run out of room on an uno.... Program is already pretty big.  I'd rather have everything running on the same device.
 

Boga

Active Member
Joined
Jan 12, 2012
Location
Dorchester, Ontario
So you used an uno to burn on mega, right? I am willing to try it tonight . At one point I have to do it anyway. I have two mega's right now so I can try. What procedure have you used? Few links would help.

And if that makes it better. .... I spent two days troubleshooting PWM signals, tons of research, and finally I found a defective LED in my module :)

Sent from my SGH-I747M using Tapatalk
 

KBennett

Member
Joined
Sep 17, 2012
Location
Brantford
I got the bootloader hex file from here:
http://www.desert-home.com/2012/05/arduino-mega2560-wrapping-up-bootloader.html

I never really found a good example of the normal way to burn using arduino as ISP and using the burn bootloader function.  It involves a 10uF cap but I couldn't find a straight forward explanation of how to wire it.    I tried every configuration I could think of.  I think it would be easier with a non-uno.

I had a tiny bit of success with this:
http://www.gammon.com.au/forum/?id=11635
Just download the sketch onto your uno.  It is supposed to detect which board you are using and upload the bootloader.
I tried faking  cable that didn't work.
I got somewhere wiring it like this though:
Arduino Uno      Target Mega2560

D10 (SS)            Reset
D11 (MOSI)          D51
D12 (MISO)          D50
D13 (SCK)          D52

Gnd                Gnd
+5V                +5V

However, it found the signature of mine as x53x53x53, which it didn't recognize.

I modified the code to accept that signature as the 2650.  It went through its motions but it didn't actually erase or write.
The fuses might have to be changed in the code, but I gave up before frying my board.
 

Boga

Active Member
Joined
Jan 12, 2012
Location
Dorchester, Ontario
Finally, after 3 hours, I fixed my both Mega's 2560.

I've tried until desperation using the burn bootloader from IDE. I had 10nF, 10uF, resistors to prevent reset, etc. Always I got errors after couple minutes of "burning?".

Anyway, I got it using your link http://www.gammon.com.au/forum/?id=11635 Thank you.

Board with sketch        Target
Mega2560R3              Mega2560R1

D10                            Reset
D51 (MOSI)                D51
D50 (MISO)                D50
D52 (SCK)                  D52

Gnd                            Gnd
+5V                          +5V

Loaded the sketch and run it.

Then I reversed the D10 and reset between the boards, load and run again.
 

KBennett

Member
Joined
Sep 17, 2012
Location
Brantford
Awesome!  Did you try the watchdog?  Did it work?  Did you use the hex file in the www.gammon.com link, or did you write in the hex file from that other link I sent you?

What signature did yours come back with?  Maybe I'll try mega to mega...
 

Boga

Active Member
Joined
Jan 12, 2012
Location
Dorchester, Ontario
Yes I tried the watcdog on both and it works.

For the first card, I used the other hex file, did not work, then I used the sketch, instructions and everything from gammon.com. I think it comes with its own hex file "bootloader_atmega2560_v2.h", after decompressing.

The second card I went straight with the second options, run it first, pressed "V", it listed two pages of "found errors". Then I pressed "G", it showed successfully. I did again "V" and did not show any errors.

Then I tested watchdog on both cards and both worked fine.

I am not sure about the signature. Was it in the list? It showed mega 2560 on both ... ? I used pin 10 on mega, on the second option, as specified. Compared with the first variant where you have to use 53.
 

KBennett

Member
Joined
Sep 17, 2012
Location
Brantford
I tried it with the megas.  Got the same crap as before.  Then I changed to all new jumpers and it worked like a charm!
Considering that I troubleshoot electronics for a living, I should have known better!

Thanks for your help Boga!
 

Boga

Active Member
Joined
Jan 12, 2012
Location
Dorchester, Ontario
KBennett link said:
I tried it with the megas.  Got the same crap as before.  Then I changed to all new jumpers and it worked like a charm!
Considering that I troubleshoot electronics for a living, I should have known better!

Thanks for your help Boga!

Great news! Thank you for bringing this watchdog to our attention. I did no know about it. I was planning to do something like an external circuit.

Here is the simple code that I used for testing:
Code:
#include <avr/wdt.h>

void setup() {
      wdt_enable(WDTO_4S);
      Serial.begin(9600);
}


void loop()
{
  Serial.println ("Pet the dog");  
  wdt_reset();

  digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); 
  Serial.println ("1 second");

  digitalWrite(13, HIGH);delay(1000); digitalWrite(13, LOW); 
  Serial.println ("2 seconds");

 digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); 
  Serial.println ("3 seconds");
 
 digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); 
  Serial.println ("4 seconds");

 digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); 
  Serial.println ("5 seconds");

}

A good watchdog should reset after 4 seconds, so the serial monitor should never see "5 seconds"
 
Top