I am looking for an efficient way to communicate between 2 arduino's (without using intermediaries such as XBee or IP).
I have 2 Arduino's at the moment (an Uno and a Mega), now I want the Uno to regularly check (1Hz) whether the Mega is still alive (ie, hasn't fried itself somehow), and if it is not alive execute some failsafe procedures.
Serial communication would be one way, or just use two connections; make the uno flip the state on one and require the mega to flip the other to match.
If not you just want to implement an external watchdog timer (the Mega has an internal one you could use). To do that you could have the Mega pulse an output pin periodically. Have the pin connected to an interrupt pin on the UNO. Note the time of the interrupt (variable = millis() and have the Uno check to see if too much time has elapsed:
if (millis() - variable > 1000)
{
ALARM! It has been more than one second since we last got a ping from the Mega!
}
Fortunately does not require getting any data from the mega, just the alive check. I've been experimenting with some shields recently, and I've noticed that if I don't connect them correctly they 'hang', so while the microcontroller might still be ok it would need a reset to continue processing. I know ideally the bugs should be fixed in the code, and I will do this as best as I can, but it would be great if I could get the Uno to try resetting the Mega if it doesn't get an alive signal, and then waiting a fixed period before activating failsafe measures.
Is there anyway to reset the Mega from the Uno without getting a servo to actually press that little reset button?
Pull the Reset pin low. You can do that by connecting the Reset pin (next to the 3v3 pin) to an output of the Uno. If the Uno sets the output to LOW the Mega will be reset and stay reset (inactive) until the Uno set the pin HIGH again.