Hi guys,
I’m trying to flash some new firmware to my Photon, but the newest code will not flash. I’m making small iterative changes to the code each time, but it seems like a crap shoot whether the new firmware (which I have saved a compiled) will actually flash.
Here’s my code. The relevant section is all the way at the bottom, in particular the final if statement. Apologize for the messiness, it’s still a work in progress:
#include <math.h>
#include <Particle.h>
// int's in C++ cannot have numbers in their name. Hence the bizarre nomenclature.
int XAccel; // x acceleration from the ADXL335
int YAccel; // y acceleration from the ADXL335
int ZAccel; // z acceleration from the ADXL335
int VOut; // voltage output of the ADXL335
//
double thermistorAnalog; // contains raw analog data from thermistor circuit VOut
double thermistorResistance; // converts analog reading to resistance
double temperature; // converts thermistor resistance to temperature, according to Amphenol datasheet
int EKG; // analog reading of EKG
String tempData = "0"; // stores temperature data as a large block
void setup()
{
// Let's register some Particle variables to the Particle cloud.
// This means when we "ask" the Particle cloud for the string in quotes, we will get
// the value after the comma. Note: The published variable name in quotes AND the
// actual variable name MUST be 12 characters or less. Otherwise, the cloud will
// ignore the variable and you won't be able to see it when you make a request.
Particle.variable("XAccel", XAccel);
Particle.variable("YAccel", YAccel);
Particle.variable("ZAccel", ZAccel);
Particle.variable("VOut", VOut);
Particle.variable("EKG", EKG);
Particle.variable("temp", temperature); // temp in Celsius
}
void loop()
{
// read the raw ADXL335 acceleration using analogRead().
XAccel = analogRead(A2);
YAccel = analogRead(A1);
ZAccel = analogRead(A0);
// determine the reference voltage by querying VOut on A3
VOut = analogRead(A3);
// read the raw thermistor analog data
thermistorAnalog = analogRead(A5);
thermistorResistance = (10000*thermistorAnalog/4096)/(1-thermistorAnalog/4096);
// calculated temperature by plotting a line of best fit using linear algebra and MATLAB. Error was found to be 3.7998*10^-4 Kelvins using Igor Pro.
temperature = pow((1.1106*.001 + 2.3724*.0001*log(thermistorResistance) + 7.4738*.00000001*pow(log(thermistorResistance), 3)), -1) - 273.15;
tempData += ",";
tempData += String(temperature);
delay(250);
if (tempData.length() > 5) // Once the chunk reaches a certain size, send it.
{
Particle.publish("Temps1", String(tempData));
tempData = "";
}
// read the EKG, connected to A4 of the Photon.
EKG = analogRead(A4);
}
In a nutshell - I’m gathering some data from sensors and publishing them to the cloud. Initially I was doing this using Particle.variable(), but now I’d like to experiment with publishing in bulk using Particle.publish().
The reason I know that my new code is not being uploaded, is when I subscribe to the datastream, the title of my publish variable is “Temps”, and not “Temps1” as indicated in the code. This means that the Photon is running my old code (which had a variable called “Temps”), but not the newest code.
Here are the steps I’m taking when flashing the Photon.
- Press Cmd+S to save the firmware.
- After seeing confirmation that firmware was saved, click Verify.
- After seeing confirmation that firmware successfully compiled, click Flash.
- Photon flashes Magenta for a few seconds, then Green, then breathes Cyan (not Blue). After about 10 seconds, the Photon will suddenly flash Blue for about a second, then return to breathing Blue. Web IDE console says “Ready” with no triangular exclamation marks.