2 Arduino boards, both acting like watchdog - How.

Welcome ! :slight_smile:

Just have a quick and propably very simple question but for me, newbie, it's a pain ....... anyway - I've got 2 Arduino Mega 2560 boards and I want them to act like a long term watchdog timer for each other. In simple words - one board is listening for signal from the second one and if can't hear it for 30 seconds, puts a message on display ang shout "WARNING" :wink: Two of them have WDT allready included in the code in case of hang but I want to add this kind of "hardware WDT" in case of different events. Can somebody point me direction, please ?

PS - sorry for my English :slight_smile:

Are they acting as watchdogs for each other?
Just have a digital output from one connect to the input of an other. A transition of these pins will reset a counter. If the counter overflows then fire off a reset. A monostable made from a NE555 is a good way to do a hardware reset.

The code can be written as an interrupt service routine, resting one of the internal timers.

Simple HIGH or LOW states arent the way I want to follow - i'm looking for kind of clock signal. I wrote code using mills() to create siple timer which incements counter but how to make the listening board reacting only at clock signal, not the static one ? I don't want to use "static" signal because : if one board hang - the signal might be still the same ( low or high ) , those two boards will be about 10 meters away from each other, so if the cable is cut - i still want to know there is something wrong. Thats why I want to use something similar to built in WDT .

I've got 2 Arduino Mega 2560 boards and I want them to act like a long term watchdog timer for each other.

Should be pretty simple. The first thing to decide is how each will tell the other "I'm alive". What have you decided?

one board is listening for signal from the second one and if can't hear it for 30 seconds, puts a message on display ang shout "WARNING"

Making note of when the last "I'm alive" signal arrived is easy. Checking, periodically, if it has been more than X milliseconds since an event is easy. Invoking the displayMessage() function is easy. Invoking the shout("WARNING"); function is only marginally harder. Once you've got the function written, calling it is easy.

Can somebody point me direction, please ?

That way! No, no, the other way.

unsigned long MILLIS_COUNT = millis();

 if ( MILLIS_COUNT - MILLIS_PAST > TIME_WATCH && digitalRead(WATCHDOGENABLE) == LOW) { MILLIS_PAST = MILLIS_COUNT; COUNT_WATCH ++; digitalWrite(WATCHDOGOUT, LOW); }   

  
  if (COUNT_WATCH > 2 ) { digitalWrite( WARNING_PIN, HIGH); Serial.println(" WARNING ");  }

Thats what I've got sor far... was trying different things but got stuck ... How to make the counter reset only at chanching ( clock ) singnal comming from the other board ( no mather if the other board hangs at HIGH or LOW - if it hangs for longer than 30s - i have to know )

Simple HIGH or LOW states arent the way I want to follow

That is not what I said.
I said:-

A transition of these pins will reset a counter.

It matters not if the system fails when the signal is high or low, the lack of a transition will stop the counter being reset and so will trigger the watchdog.

unsigned long MILLIS_COUNT = millis();

Lousy name! The name of a variable should imply what it is for. A name like lastSignalTime says exactly what the value it contains is for. MILLIS_COUNT says that it contains a value obtained from millis(), but when? Last Tuesday? A month from Wednesday?

Grumpy_Mike:

Simple HIGH or LOW states arent the way I want to follow

That is not what I said.
I said:-

A transition of these pins will reset a counter.

It matters not if the system fails when the signal is high or low, the lack of a transition will stop the counter being reset and so will trigger the watchdog.

I'm sorry - didn't get it the first time. Ok.. so I should be using edge detection of the comming signal ?

Something, like the code from this tutorial :

void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    }
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");

PaulS:

unsigned long MILLIS_COUNT = millis();

Lousy name! The name of a variable should imply what it is for. A name like lastSignalTime says exactly what the value it contains is for. MILLIS_COUNT says that it contains a value obtained from millis(), but when? Last Tuesday? A month from Wednesday?

I know but in my code I use Polish names - so I thought i change them to something similar to English language :wink: Its just an egzample.

I've used the code posted earlier - state changing detection and... It's working ! :slight_smile: Thanks everyone - especially Grumpy_Mike ! :slight_smile: