Hello all! I am having an issue with my “stealth” core reading and writing analog and digital values. I have connected a piezoelectric element to the A3 pin of my core and I am attempting to read the analog value of the pin using curl. When I make the GET request, the returned result is always zero. I’ve moved the element to other analog pins (and changed the relevant code), but the result is the same. Measuring the output of the piezoelectric element with a multimeter returns a non-zero value. The code on my core is posted below:
#include "application.h"
#include "math.h"
const int piezoPin = A3; //piezoelectric element connected to A3
const int ledPin = D7; //D7 LED on Spark Core
double inst_volts; //average volts in
double instVoltSum;
int maxVolts = 3; //max volts generated by piezo element
int i = 0; //counter
char publishString[40];
void setup() {
pinMode(piezoPin, INPUT);
digitalWrite(ledPin, LOW);
Spark.variable("inst_volts", &inst_volts, INT);
}
void loop() {
instVoltSum = 0;
for(i = 0; i < 10; i++){
instVoltSum += analogRead(piezoPin);
}
inst_volts = (instVoltSum/10)*(maxVolts/4096); //average volts calculation
if(inst_volts > 1.5){
sprintf(publishString, "The average generated voltage was: %d", (double) inst_volts);
Spark.publish("Energy", publishString);
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
The GET request is as follows:
https://api.spark.io/v1/devices/[Core ID]/inst_volts?access_token=[access_token]
As stated, the returned result is always zero. I’ve also reflashed the core with Tinker and attempted to read the analog pin. The app presents a “404” error. A similar error occurs when attempting to write the D7 LED “HIGH”.
Has anyone else experienced these issues, and if so, how were they resolved?
Thanks for your help!