New function in emonLib

Hi guys. If I write add function() for calcVrms, number of sample…?.
I want to V=0 when plug out.
Thanks & regards

You are of course free to modify your copy of emonLib as you wish.

The rms voltage is already calculated in calcVI().

I do not understand what you want when you write

Which plug?
If V != 0 when the a.c. adapter is unplugged, then the problem is electrical noise entering somewhere. Unlike the c.t. input of the emonTx, if there is a switch on the a.c. input socket, we cannot use it because that is also the normal power supply for the emonTx.

hi guys!
When a power outage (V0), the result will not appear on the value of Vrms (If I only measuring V only). So I want to write more for Vrms function (for when don’t electricity or electricity), it still appears the value of V. Without knowing the number of samples of V.
this code:

this is a result if don’t electricity (V~0)

If you want a function that will read only voltage samples, then the simple way is to make a copy of the function “calcIrms(…)” and call it calcVrms.

Then in the new function, you change the names of everything that is about current to the same name about voltage:
sampleI → sampleV
inPinI → inPinV
offsetI → offsetV
filteredI → filteredV
sumI → sumV
Irms → Vrms

You must also add the new function to the class EnergyMonitor.

The new function will work in exactly the same way as calcIrms. You must tell it the number of samples over which to calculate the average. For the voltage to be accurate, the number of samples must be at least 5 cycles of mains frequency in your country. You will sample approximately 5588 times per second with an Atmel 328P (Arduino Uno), therefore 559 is a good small number. A better big number would be 2235 (to sample for approximately 0.4 s)

You should put after Serial.println(supplyVoltage);

delay(10);

to give the sketch time to print the voltage.

1 Like

FWIW,
Based on the numbers in one of the pics above,
(the line that says leaving 53608 bytes for local variables.Maximum is 81920 bytes.
It looks like he’s running something other than an Atmel 328.

I gave those numbers as an example, because đặng is clearly struggling with English (though his English is much better than my Vietnamese).

@Bill.Thomson Any clues where the hex dump comes from - it’s clearly not from Serial.print.

1 Like

Good question. Unfortunately I’ve nary a clue. On the Due, (and some others) there’s a
programming port and a native port. The programming port is for uploading sketches
(although that can also be done via the native port) and the native port can be used in a manner
that makes the Due look like a mouse, keyboard, etc. That’s strictly a guess though. :thinking:

1 Like

It looks like an ESP8266.

1 Like

thanks you very much. <3
when I show up result in port of Arduino. Its output is unstable too. Export value of continuity and many mismatches error.

I use wemos d1 mini.

You must choose the number of samples so that this requirement is satisfied.

If you are not measuring over an exact number of mains cycles, you will have an error because you might include a part of a cycle, but you do not know whether that extra part is a high voltage or a low voltage, and it will distort the average.

You can find out the time to measure one sample by measuring, using millis( ), the time it takes to measure say 500 samples, then measure the time it takes to measure 1500 samples. The difference between the two times is the time for 1000 samples. Then you know the time for one sample, and it is easy to calculate the best number of samples to give you an integer number of mains cycles.

1 Like