Absolutely!!! I need to keep testing of course, but when trying to duplicate outages as soon as the code stops the reset occurs flawlessly so far. Lets see how it does with a week running.
So here is how it works: the Spark runs code in a loop, I placed a small code that tells it to toggle a pin on and off every 5 seconds (you can adjust this). The reason I did this rather than just keep a pin on as an indicator is I found when the code freezes, it keeps the current state, therefore never distinguishes that the code froze. This fixes that by requiring constant change.
The attiny is listening in on that pin, and records the last change. If it has been 10 seconds since the last change (you can adjust this too), it will trigger the reset pin.
The attiny is powered by the core itself.
I programmed the attiny using an arduino uno via: http://highlowtech.org/?p=1695
Here is how it is hooked up:
Spark: A7 to pin 3 of attiny as trigger pin or sensor pin
Spark Gnd to pin 4 of chip
Spark 3v3 to pin 8 of chip
Reset to pin 5 of chip
I tried to comment everything, hope it helps! I am sure there is a better way to write this code but I am a newbie.
Spark Code
int trigger = A7; // this is the pin talking to the attiny
int led = 7; // this is the led pin for a visual indicator that things are running, it is optional
void setup() { // setup
pinMode(trigger, OUTPUT); // set signal pin to output
pinMode (led, OUTPUT); // set led pin to output
}
void loop() { // loop
checker(); // This tells the code to send the checker signal in the loop
///////////////////////////
// place nrmal code here //
///////////////////////////
}
void checker() // trigger code
{
delay(5000); // wait 5 seconds between signals
digitalWrite(led,HIGH); // indicator on
digitalWrite(trigger,HIGH); // Send signal
delay (1000); // wait
digitalWrite(trigger,LOW); // turn off signal
digitalWrite(led,LOW); // turn off indicator
}
Here is the ATTINY Code
/*
Spark Cyan Flash of Death Killer - by Scott Lichtenstein (StartGroup)
Open Sourcec - Please feel free to do whatever you want with this! :)
*/
const int resetButton = 0; // pin that will flip the reset switch
int sensorValue = 0; // variable to store the value coming from the Spark pin
int sensorPin = 3; // pin from Spark Core
int sensorState; // holds current state of pin from Spark Core
int lastTriggerState = LOW; // the last successful read of the Spark Core pin
long lastTriggerTime = 0; // the last time the state was changed
void setup() {
delay(10000); // wait 10 seconds for the core to connect.
pinMode(resetButton, OUTPUT); // call the resetbutton pin as an output
pinMode(sensorPin, INPUT); // call the sernsorPin as an input
digitalWrite(resetButton, HIGH); // Keep reset pin at high until further notice
}
void loop() { // here starts my loop
setState(); // checks the sensor and sets value to 1 or 0 depending on its value
if (sensorState != lastTriggerState) { // checks if pin is the same or different from last time.
lastTriggerTime = millis(); // sets new time for change
lastTriggerState = sensorState; // changes new state
}
if ((millis() - lastTriggerTime)>10000){ // if it has been more than 10 seconds since the state has changed, do a reset
reset(); // activate reset function
}
}
void reset(){ // here is the reset function
digitalWrite(resetButton,LOW); // Push Reset button
delay(1000); // Wait
digitalWrite(resetButton,HIGH); // Let go of Reset button
delay(30000); // wait 30 deconds for reconnect prior to checking again
}
void setState(){ // here is the set state function, number varibles are just to identify change in state.
sensorValue = analogRead(sensorPin); // check for spark pin
if (sensorValue < 500) // if analog value is less than 500, set to variable 0
{
sensorState = 0; // variable 0
}
if (sensorValue > 500) // if analog state is more than 500, set to varible 1
{
sensorState = 1; // varible 1
}
}
*Please keep me updated it if helps you!
I am so excited to be able to contribute! *