I have an problem to use TSL257 Light-to-Voltage optical converter. I have tried to achieve pulse counting on Wemos D1 Mini (ESP8266).
10k resistor is connected between signal and ground (inside of sock in the picture) and I also printed ambient light cover for sensor, but no help.
Even tought I held my thump over the sensor (and this way secure that there is no any light leak) sensor is stating at same state.
I have used code from here: Learn | OpenEnergyMonitor
and I am getting readings if I am disconnecting/reconnecting signal pulse from D1 pin physically so interrupt seems to be working.
Any thoughts what could be wrong?
With setting PIN mode to
pinMode(D1, INPUT); behavior change so that interrupt never happens.
Here is full code:
long pulseCount = 0;
unsigned long pulseTime,lastTime;
double power, elapsedkWh;
int ppwh = 1; //1000 pulses/kwh = 1 pulse per wh
attachInterrupt(digitalPinToInterrupt(D1), onPulse, FALLING);
// The interrupt routine
//used to measure time between pulses.
lastTime = pulseTime;
pulseTime = micros();
power = (3600000000.0 / (pulseTime - lastTime))/ppwh;
//Find kwh elapsed
elapsedkWh = (1.0pulseCount/(ppwh1000)); //multiply by 1000 to convert pulses per wh to kwh
//Print the values.