2 pulse counters to 1 blinking led (1000 pulses/kwh)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
prutzer
Normal user
Posts: 10
Joined: 16 Jun 2020, 16:45

2 pulse counters to 1 blinking led (1000 pulses/kwh)

#1 Post by prutzer » 13 Jun 2021, 13:46

Hi All,

I have got 2 power metes (kWh meters) with a S0 output. They do 1000 pulse/kwh
The output is going to a D1 mini with Easy ESP. I made 2 pulse counters.
It is counting the pulses from the power meters.

I would like to make a rule (script) to do the following:

Pulses powermeter1 + pulses powermeter2 --> Led blink. (1000 pulses / kwh) with little delay.
How can we do this?

I'm not very good in scripting. I was thinking about this:

on system#clock=All,**:**:** do //run every second
let,1,[Solarsystem1#Count]+[Solarsystem2#Count]

Now we have a variable "1" with the pulse of meter 1 and 2.
How can i send it to the onboard led and make it do 1000 pulses/kwh?
It may not overlap or skip pulses and it need to be in a stable ritmh

On a Arduino nano V3 I use a arduino script. (This script is not working on a ESP8266 or D1 mini).
The script works, but the output is not in a stable ritmh. Source: https://forum.arduino.cc/t/2-power-mete ... /854753/30
The pulses of the arduino led are received by a smart thermostat. It is thinking it is a pulse from a power meter of a solar panel system. The unstable ritmh causes very high and low power generated peaks in the graphs.

Code: Select all

//Number of pulses, used to measure energy.
//Made by Johnwasser
volatile byte pulseCount = 0;

const byte Meter1Pin = 2; // External Interrupt Pin
const byte Meter2Pin = 3; // External Interrupt Pin
const byte LEDPin = 13;

void onPulse()
{
  pulseCount++;
}

void setup()
{
  pinMode(Meter1Pin, INPUT_PULLUP);
  pinMode(Meter2Pin, INPUT_PULLUP);
  pinMode(LEDPin, OUTPUT);
  // KWH interrupts attached to external interrupts
  attachInterrupt(digitalPinToInterrupt(Meter1Pin), onPulse, FALLING);
  attachInterrupt(digitalPinToInterrupt(Meter2Pin), onPulse, FALLING);
}

void loop()
{
  bool pulse = false;

  noInterrupts();
  if (pulseCount > 0)
  {
    pulse = true;
    pulseCount--;
  }
  interrupts();

  if (pulse)
  {
    // LED pulse rate is limited to 50 pulses per second, max. 
    // = 50 Wh per second
    // = 3000 Wh per minute
    // = 180 kWh per hour
    // = 180 kW
    // = over 800 Amps at 220 Volts, 1600 Amps at 110 Volts
   // Should be fast enough for any home system
    digitalWrite(LEDPin, HIGH);
    delay(60);
    digitalWrite(LEDPin, LOW);
    delay(60);
  }
}

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 2 pulse counters to 1 blinking led (1000 pulses/kwh)

#2 Post by TD-er » 13 Jun 2021, 14:29

You could perform a looptimer_ms which also has a parameter for number of pulses.
Just realize the pulses will then be sent from the rules, which may also affect the pulse counters if the pulses received by the pulse counter are too short.

One way to overcome the need for real-time behavior of the ESP is to feed the pulses into a flipflop, to essentially divide the number of received pulses by 2, but by counting on "CHANGE" instead of "RISING" (or "FALLING") you correct it.

prutzer
Normal user
Posts: 10
Joined: 16 Jun 2020, 16:45

Re: 2 pulse counters to 1 blinking led (1000 pulses/kwh)

#3 Post by prutzer » 13 Jun 2021, 19:03

Hi TD-er,

I use the option: Falling.
D5 is connected to S0+ and ground to S0-

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests