Quantcast
Viewing all articles
Browse latest Browse all 30

Wemos D1 Mini (ESP8266) pulse counting

@JoniR wrote:

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);
}

Posts: 7

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 30

Trending Articles