I'm not good in programming so I was wondering if some one already made a script or can help me with it.
I have 2 power (kWh) meters with a S0 output.
I would like to have a script that reads the energy usage from the 2 power meters, and combine them to 1 led pulse output.
On the led output I will put a sensor of a Toon Thermostaat.
Can some one help me?
Hardware:
D1 mini or nodeMCU.
2 kWh meters with S0 output. (or led)
Restistor to at on the S0 output
Led or onboard led.
If power meter 1 does 1000 watts (1000 pulses a minute) and power meter 2 does 1000 watts (1000 pulse per minute) the d1 mini has to combine it to 2000 pulses a minute.
I monitor my solar panels (2 solar inverters in different phases) with a toon thermostaat. This thermostaat has 1 sensor that you put on the led output of 1 power meter. It does not support 2 power meters.
A Toon thermostat is a smart device to control the heating of your house.
You can program it. In the morning the room temperature has te be 21 degree and at night 19 degree etc. It is also a screen where you can monitor your solar panels etc.
Unfortunately it is not smart enough to support 2 power meters.
//Print the values.
Serial.print(power,3); // meter A
Serial.print(" ");
Serial.print(elapsedkWh,3); //meter B
Serial.print(" ");
Serial.println(power + elapsedkWh ); //A+ B
If you don't have anything connected to the two input pins they are probably picking up noise. It may be necessary to set the pinMode() on those two pins to INPUT_PULLUP.
//Number of pulses, used to measure energy.
//Source https://forum.arduino.cc/t/2-power-meters-combine-to-one-led-pulse/854753/10
//Made by johnwasser
volatile byte pulseCount = 0;
const byte Meter1Pin = 5; // External Interrupt Pin //D1 GPIO5
const byte Meter2Pin = 4; // External Interrupt Pin //D2 GPIO4
const byte LEDPin = LED_BUILTIN;
void onPulse()
{
pulseCount++;
}
void setup()
{
// KWH interrupts attached to external interrupts
attachInterrupt(digitalPinToInterrupt(Meter1Pin), onPulse, FALLING);
attachInterrupt(digitalPinToInterrupt(Meter2Pin), onPulse, FALLING);
pinMode (5 , INPUT_PULLUP); //D1 GPIO5
pinMode (4 , INPUT_PULLUP); //D2 GPIO4
}
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(10);
digitalWrite(LEDPin, LOW);
delay(10);
}
}
After uploading the led is still flashing. (Nothing connected) (Tried first pin1 and 2, some problem)
I think pin5 in the script is D1 GPIO5 of the nodemcu and pin6 = GPIO6?
If I connect GPIO 5 and 6 to ground with a resistor the led is still flashing.
The Arduino functions like pinMode() and attachInterrupt() ALWAYS use Arduino Pin Numbers. Your NodeMCU has pins labeled D1, D2, D3... so use those names.
The Arduino numbers do not match physical pin numbers (counting counterclockwise around the chip) or the numbers used in Direct Register Access (like GPIO5).
D1 and D2 are the Wire/TWI/I2C pins (SDA&SCL). As long as you are not using Wire.h they should be fine.
If you have a real Arduino clone available you could try the sketch on it. Perhaps there is something strange in the ESP8266 core.