I have all the hardware and his code forces my particle photon to go into breathing green light. I have to go into safemode in order to re-flash which is inconvenient.
Here is the code I am referring to:
I am using 0.6.0 firmware.
// This #include statement was automatically added by the Spark IDE.
#include "thingspeak/thingspeak.h"
const int PiezoSensor = A1; // the piezo is connected to analog pin 1
const int threshold = 1;
const long interval = 17000; // interval at which to ping Thingspeak (milliseconds)
unsigned long previousMillis = 0; // will store last time we reported to thingspeek
int sensorReading = 0; // variable to store the value read from the sensor pin. From 0 to 1023
int ticks = 0;
ThingSpeakLibrary::ThingSpeak thingspeak ("Channel-API-Key");
void setup() {
pinMode(PiezoSensor, INPUT);
}
void loop() {
unsigned long currentMillis = millis();
sensorReading = analogRead(PiezoSensor);
if (sensorReading >= threshold) {
bool valSet = thingspeak.recordValue(1, String(sensorReading, DEC));
if (currentMillis - previousMillis >= interval) {
ticks = (currentMillis - previousMillis);
bool valSet = thingspeak.recordValue(2, String(ticks, DEC));
bool valsSent = thingspeak.sendValues();
if(valsSent) {
previousMillis = currentMillis;
ticks = 0;
}
}
}
delay(100);
}
That sounds like when trying to send values, the code is blocking and preventing your Photon from processing it’s background tasks. So eventually after about 10-15 seconds the Photon will drop back to breathing green.
This is likely because your Thingspeak account is not setup properly I’d guess. Did you by any chance replace Channel-API-Key with your own?
@BDub
Yes, I have replaced the Channel-API-Key with my own. Is there a tutorial that shows how to properly set up a thingspeak account with a particle photon?
Thanks!
You just need these lines with your secret numbers--you don't seem to be using the channel number.
/*
*****************************************************************************************
**** Visit https://www.thingspeak.com to sign up for a free account and create
**** a channel. The video tutorial http://community.thingspeak.com/tutorials/thingspeak-channels/
**** has more information. You need to change this to your channel, and your write API key
**** IF YOU SHARE YOUR CODE WITH OTHERS, MAKE SURE YOU REMOVE YOUR WRITE API KEY!!
*****************************************************************************************/
unsigned long myChannelNumber = 31461;
const char * myWriteAPIKey = "LD79EOAAWRVYF04Y";