Hi All,
I have had a Core using a TSL251R-LF light-to-voltage working as pulse counter hooked up to my electricity meter running for a while now. As I have some connectivity issues with the Core, I desided to try a Photon with the same code. As it does not have interrupt on pin D0, I have changed it to D1 from the original code, this is the only thing I have changed. It flashes ok, and connects and publish.
But the counting does not happend. I’m a novice at this, is there something I have missed?
Here is my code, it’s based on https://github.com/scottsweb/watz / Watz
// Puls counter for energy-meter based on https://github.com/scottsweb/watz
SYSTEM_MODE(AUTOMATIC);
// pins
int intled = D7;
int sensor = D1;
// general vars
char json[64];
// pulse vars
void pulseInt(void); // function for interrupt
float pulseCount = 0; // counts power pulses on sensor
void setup() {
Particle.connect();
// set led as output
pinMode(intled, OUTPUT);
// set sensor as input
pinMode(sensor, INPUT);
// attach interrupt to LED pin, when RISING
attachInterrupt(sensor, pulseInt, RISING);
}
void loop()
{
// publish once every 1 minutes
if (Time.second() == 30)
{
noInterrupts(); // Disables interrupts while publishing data
float avgInterval = 60 / pulseCount;
float kw = 3600 / (avgInterval * 1000);
sprintf(json,"{\"kw\": %.3f, \"count\": %.0f}", kw, pulseCount);
Particle.publish("watz", json, 60, PRIVATE);
pulseCount = 0;
delay(1500); // delay more than 1000ms so that the data on second 30 is only published one time
interrupts(); // Re-enables interrupts when data is published
}
}
void pulseInt() {
// visually indicate the blink has been detected on internal LED D7
digitalWrite(intled, HIGH);
delay(100);
digitalWrite(intled, LOW);
// increment pulse count
pulseCount++;
}
All help is appreciated