Hi there!
Apologies for the lengthy post, but I didn’t want the system to think I was spamming based on the number of new posts.
Virtually a complete noob to Particle here, but I have had a Photon running and watching my freezer temperature off and on for a couple of years (and using IFTTT to log to a Google Sheet). Coming home after vacation to find a tripped breaker one time was enough!
I picked up a couple more Photons recently so I can work towards making some “Who is teaching and/or in a meeting?” status boxes for use around the house and at the front door. After large parts of several days searching for help and getting distracted by all of the cool projects people have created, I need some general help all the way around.
To work towards that, I’ve decided to add more features to the FreezerMonitor, one at a time, so I can learn more about everything along the way. I am very much “hunting and pecking” to try to assemble this. I know bits and pieces about various languages that I’ve used over the years, but am a mere beginner in them all.
The first step is upgrading the FreezerMonitor system by adding a second Photon to sit on my desk, flash its D7 in different patterns based on what’s happening in the garage, and display the temp on an LCD screen.
Flashing an LED
What’s the best way to flash an LED? Since I’m getting Stack Overflow resets, I don’t think my way is working very well.
Is there a way to loop without being in the main void loop?
Am I using the handlers incorrectly? Is it a better idea to have them set a global variable, then test that variable inside the void loop, alternating patterns based on that value?
I wanted to start simply and have the FreezerGood and FreezerBad events be the triggers it would use, but then realized that I could probably do it with testing the value of the temperature event. I haven’t had time to clean up the code.
Formatting LCD Output
I have looked at numerous examples, but I just do not grasp the formatting nor how to concatenate text onto the end.
I would love for that to display 3.65°F or -4.34°F instead of the meaningless digits.
Also, I can’t figure out how to round a double down to two decimal places. I’ve managed to get the variable in my FreezerMonitor to display a whole number, but I’d like to see at least one decimal place. I’ve read the “74.14505494505494” post several times, tried it several times, to no avail. (Granted, that’s not in this code, but once it works here…)
Fixing Stack Overflow
Is my implementation of the handlers and the flashing LED causing the stack overflow issue?
The Serial output was so I could hopefully establish a pattern as to when the device would reset.
/*
* Project FreezerRemote
* Description: Remote display for FreezerMonitor
* Author:
* Date:
*/
#include "LiquidCrystal_I2C_Spark.h"
LiquidCrystal_I2C *lcd;
int led1 = D7;
int i = 0;
int counter = 0;
char line0[21];
char line1[21];
String tempDisplay = "initializing....";
// setup() runs once, when the device is first turned on.
void setup(void) {
// Put initialization like pinMode and begin functions here.
Particle.subscribe("FreezerGood", Safe, MY_DEVICES);
Particle.subscribe("FreezerBad", NotSafe, MY_DEVICES);
Particle.subscribe("temperature", TemperatureHandler, MY_DEVICES);
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
Serial.begin(9600);
//initialize the liquid crystal library
//the first parameter is the I2C address
//the second parameter is how many rows are on your screen
//the third parameter is how many columns are on your screen
lcd = new LiquidCrystal_I2C(0x27, 16, 2);
lcd->init();
lcd->backlight();
lcd->clear();
lcd->print("Freezer Monitor");
}
void Safe(const char *event, const char *data)
{
//Particle.publish("MonitorTempReceived", data, PRIVATE);
String datastr = String(data);
Particle.variable("MonitorTempReceived", datastr );
Serial.println();
Serial.println();
Serial.print("Safe Handler triggered - Temp = ");
Serial.println(datastr);
Serial.println();
//Print temp to LCD
lcd->clear();
lcd->print("Freezer Temp");
lcd->setCursor(0,1);
lcd->print(datastr);
//lcd->print(Time.minute() < 10? ":0": ":");
//Flash led1
for (int i=0; i<100000; i++) {
Serial.print(" Counter = ");
Serial.println(i);
digitalWrite(led1, LOW);
delay(750);
digitalWrite(led1, HIGH);
delay(2000);
}
}
void NotSafe(const char *event, const char *data)
{
String datastr = String(data);
digitalWrite(led1, LOW);
Particle.variable("MonitorTempReceived", datastr );
Serial.println();
Serial.println();
Serial.print("NotSafe Handler triggered - Temp = ");
Serial.println(datastr);
Serial.println();
for (int i=0; i<100000; i++) {
Serial.print(" Counter = ");
Serial.println(i);
digitalWrite(led1, LOW);
delay(100);
digitalWrite(led1, HIGH);
delay(100);
}
}
void TemperatureHandler(const char *event, const char *data)
{
String tempDisplay = String(data);
digitalWrite(led1, LOW);
}
// loop() runs over and over again, as quickly as it can execute.
void loop(void) {
// The core of your code will likely live here.
lcd->setCursor(0,1);
lcd->print(tempDisplay);
}
A billion bits of “thank you” in advance to all who care enough to answer!

