Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Wemos D1 Mini (ESP8266) pulse counting

Tags: #<Tag:0x00007f1be3048700> #<Tag:0x00007f1be3048598> #<Tag:0x00007f1be30484d0>

Hi,
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: https://learn.openenergymonitor.org/electricity-monitoring/pulse-counting/interrupt-based-pulse-counter
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.

-Joni

Here is full code:

long pulseCount = 0;
unsigned long pulseTime,lastTime;
double power, elapsedkWh;
int ppwh = 1; //1000 pulses/kwh = 1 pulse per wh

void setup()
{
Serial.begin(115200);

pinMode(D1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(D1), onPulse, FALLING);
Serial.println(“ready…”);
Serial.println(“ready…”);
}

void loop()
{
}

// The interrupt routine
void onPulse()
{

//used to measure time between pulses.
lastTime = pulseTime;
pulseTime = micros();

//pulseCounter
pulseCount++;

//Calculate power
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.
Serial.print(“current power:”);
Serial.print(power,4);
Serial.print(" ");
Serial.println(elapsedkWh,3);
}

You have connected the TSL Pin 1 - GND, pin 2 - Wemos VCC, pin 3 - Wemos D1?
Silly question: You have looked at the pins from the correct side, and you do not have 1 & 3 swapped over?

Can you measure the voltage on pin 3 changing as you cover and uncover the sensor?

Yep, TSL Pin 1 - GND, pin 2 - Wemos VCC(3,3v and 5v tested), pin 3 - Wemos D1. I double checked 1 & 3 many times. From front view, GND is most left pin.
There is no any change on voltage in pin 3, it’s constantly 0.7v.

What is the supply voltage on Pin 2?

If the diagrams on the data sheet are correct, the output is from an amplifier, and you should not need the 10 kΩ resistor. What voltage do you see when you remove that resistor?

The 0.7 V that you measure makes me suspicious, because it is the forward voltage of a silicon junction. According to the data sheet, without the load resistor (the 10 kΩ), the output should go from 15 mV dark to (VCC - 10 mV) maximum.

Supply voltage is 3.3v or 5v, I have tried both. I removed resistor and now I am getting 1v and no any changes from dark to light.
Between pin 1(gnd) and pin 2(voltage) I am getting supply voltage depending on source. What makes me feeling odd is if I am not contacting pin 3 to digital input, then voltage is 0v, but no short circuit between pin1 and pin3.

The TSL should work on any voltage between 2.7 V and 5.5 V. Therefore 3.3 V and 5 V should both be OK - and should make no difference, except for the range over which the output voltage moves.

Are you measuring at the sensor, or at the end of the cable? Is the cable faulty? Unsolder Pin 3. If the supply is correct at the sensor, and you have daylight, and you do not see nearly VCC on pin 3, then I think you have a damaged or faulty sensor.

I thinking this same and I measured straight from pins to ensure that cable is not problem. I also tried to unsolder pin3, but same result. I have to give it up and go to shop new sensor. Thank you very much of helping. Will be update thread when getting new sensor.