EmonLib with 4 Probes and Real Power Issues

Hello everyone, I’m new to the forum and I’m writing to you for a problem that I can’t understand.
I made a simple circuit on an ESP32, with 4 probes of the type SCT-013 20A. I also connected the circuit to detect the voltage on an esp32 input, with a AC/AC 230V-12V.
See below my definition.

#define ADC_E1 35  // current pin energy 1, for other ones see below
#define ADC_E2 33
#define ADC_E3 34
#define ADC_E4 32
#define ADC_VV 39 // voltage pin
#define VCAL 185
#define ICAL 20
EnergyMonitor emon1,emon2,emon3,emon4;

 emon1.current(ADC_E1, ICAL);
 emon1.voltage(ADC_VV, VCAL, 1.7);
 emon2.current(ADC_E2, ICAL);
 emon2.voltage(ADC_VV, VCAL, 1.7);
 emon3.current(ADC_E3, ICAL);
 emon3.voltage(ADC_VV, VCAL, 1.7);
 emon4.current(ADC_E4, ICAL);
 emon4.voltage(ADC_VV, VCAL, 1.7);

Everything works fine, Vrms and Irms provide very accurate value.
Problem is realPower, two clamps works and but not the other ones, which provide ZERO or NOT CORRECT real power. If I reverse the 12 volt ac input cables, the probes that gave wrong values ​​start to work fine but the other two stop working well. Can you help me, where can the problem be?

Welcome, Antonio, to the OEM forum.

The problem is, emonLibCM is written for the Atmel ATMega328P processor only. To make it work with any other processor, you will need to make significant changes, which are most likely to be in the area of addressing the multiplexer / extracting the values from the ADC, and compensation necessary to remove the errors created by the delay between reading voltage and current and the phase errors of the two transformers.

This might help: ESP32 Problem with YHDC SCT-013-000

In general, many people seem to have a problem with the analogue inputs of an ESP32. See [TW#12287] ESP32 ADC accuracy · Issue #164 · espressif/esp-idf · GitHub and the comments that follow.

I do not have an ESP32, so I am unable to help you further.

Of course, if your c.t’s are not on the same phase as the voltage transformer, you will never read the correct real power with emonLibCM - in that situation, you need the 3-phase sketch, which also was written specifically for the Atmel ATMega328P.

Real problem was obscured by a software feature that I had introduced myself to reduce background noise. From the real power I subtracted a treshold value (2 watts) and if the result was negative I set the power to zero. This check is also triggered when the power was already negative for other non-software problems.
This, was the problem to investigate: why does the real power of emonlib provide a negative value? And the solution was in this topic: https://openenergymonitor.org/forum-archive/node/10334.html.

By convention, we regard real power as positive when importing, and negative when exporting. The difference is the phase of the current in relation to the voltage. If you flip your CT on its cable, you will invert the current signal and you should then read positive real power when importing (which I assume is what you are doing).