EmonLib / ESP32 How to calibrate?

Hi,

I am using my Arduino development tools to use emonlib on an ESP32 development board. I got everything compiling and running but my serial output is not putting out stable and correct values. So I guess I need to calibrate but after several days I haven;t managed to get it working.

I am using an SCT-013-010 sensor. This sensor has a build in burden and puts out 0-1V for 0-10A.

I am using 2x 10k Ohm resistor devider between +3v3 and gnd. One side of the sct to the middle of this devider and the other pin to ESP input pin GPIO-36.

My question:

  • How to get the correct value for Cal in: emon1.current(CurrentSensePin, Cal);

  • Is 1480 good enough for my setup? double Irms = emon1.calcIrms(1480); I notice no stable value with a stable load…

I am not measuring the voltage.

I just want to measure my power usage and put it out on serial. no more then that. Well, next step will be sending an email when power passes a border, hence the ESP32. But basically my question is just Arduino / EmonLib.

I havent found many example with the SCT-013-010. So probably others may find this a helpfull question as well. Thank you!

I haven’t worked with the SCT-013-010, or the ESP. But
I have built an Arduino with other clamp-on CT’s.
My experience has been at the lower end of the scale,
less than 1.5 amps, the accuracy was like +/- 50%.
I would suggest try measuring at 5 or even 10 amps.

Few people use the low current c.t’s, but there’s no specific reason to think it should be any different to the “shop standard” SCT-013-000 except that the burden is internal.

1.  The current calibration constant for your 10 A c.t. is 10.0
2.  “1480” is no longer the optimal value. You want the closest number that is the number of samples to a whole number of mains cycles. The sampling rates, measured with a standard emonTx V3.4 (and the emonPi is the same processor) are:
calcIrms( ) - approx 5588 current samples per second.
calcVI( ) - approx 2535 pairs of voltage & current samples per second.
See
Sampling rate of emonLib
for more details.

I’ve no idea how good (or otherwise) the ADC on the ESP32 is, but the one in the ESP8266 is not really usable for our purposes, as it takes far too long to make a reading, hence there are not enough samples in each mains cycle to get a sensible reading.
I’ve read that it is capable of 6000 samples / second, but whether that is using the same method to access the ADC that emonLib uses, I do not know.

If you are interested in measuring currents significantly lower than 10 A, you can of course multiply the current by passing more turns through the c.t, then change the calibration accordingly: 5 for 2 turns, 3.33 for 3, etc.

I think the ESP32 ADC is not compatible with emonlib or it is just very bad at all. It seems to have functions to set the attenuation and voltage range. This makes the 2 resistors not ending up in the middle. But even after studying ESP32, I still dont understand the values read. I made my own lowest/highest detector over 50000 samples and calculated RMS from there but the values are just very noicy and come not close to what I expect. On my scope I do understand the readings and can manually calculate the power (using a 100W light bulb). So I will probably move to a normal Arduino as a test now.

EmonLib was designed and developed for the Arduino platform and the Atmel 328P.

Is the title of this thread correct? It seems that your problem is not calibration, but with correctly designing the input conditioning components and converting emonLib to work with the ESP32. Is that correct?

It is very obvious to me that changes will be necessary for a different processor with a different architecture, so my first question is, having quickly looked at some of the documentation for the ESP32, how have you changed emonLib to cater for the different commands that the different processor requires, and the different procedures required by the ADCs?

That makes no sense to me, can you explain what you mean?
Looking here, it would appear that (a) noise is a problem that Espressif acknowledges, and (b) that the input must be biased to a level of 1 V for optimal operation, not 1.65 V as you appear to have it.

Hello Hasse,

Would you mind to share how you interfaced the ESP32 ADC to EmonLibCM ?
I amstudying how I could get this to work, but if the work has already be done that would be great.

I understand that the ESP32’s ADC is not the best, but at the moment I have started my project and this is mainly for learning purpose. In the future I might go back to the ATMEGA.

Thanks

I ended up with using an external ADC. Worked flawlessly and at once.

Sorry I lack a bit of knowledge on this topic. The only ADC I used was the MCP3008 for rapsberrypi.

In your case I understand that you used ESP32 + ADC. And so the sensors are connected to the ADC and the ADC sends the Digital value of the sensor to the ESP32. From what I know, the ADC sends the infor,ation to the MCU via 1 pin only. Then how have you modified the Emonlib to take all these changes ?

Thank you

I think I used an ADS1115 /1015 ADC from AliE. It connects over SPI to the ESP. I used Arduino programming interface and there is a good library for this ADC. So you will get it working with just a few lines of code.

But after I finished the project, I replaced it with a Sonoff POW module that I loaded with the Tasmota firmware to talk to my MQTT server that collects all the data. That was eventually what I wanted to achieve.

Hi,

May I know what is this sentences means? Is it set the ground to 1V instead set to 1.65V will get more accurate result?

Thank you

I recommend you study the section in ‘Learn’ that explains how to design the input circuit for a single-ended analogue to digital converter (ADC): Learn | OpenEnergyMonitor

Although the values of the voltages will be different for an ESP32, the same principle will apply. You must find what the maximum and minimum voltages for your ADC input are, then set the mid-point or bias voltage to be half-way between the two. For an Arduino, those voltages are 5.0 V and 0 V, and half-way is 2.5 V. For our emonTx, the voltages are 3.3 V and 0 V and the mid-point is 1.65 V.

I had studied it and built out using the esp32, I set it to 1.65V. Same with others, the reading is very inaccurate. So, the conclusion for this problem is ADC of esp32 is not suitable to using the emonlib?

Have you set up the ADC to have a 0 – 3.3 V input range? If you connect a potentiometer to the ADC input, and vary the voltage between 0 V and 3.3 V, do the numbers from the ADC change in proportion? can you plot this on a graph? You should have a straight line going from 0 counts at 0 V to the maximum counts (1023, 4095 or whatever the resolution gives you) at 3.3 V.

I have a note about the ESP32 that says this:
ESP32 Analogue input [TW#12287] ESP32 ADC accuracy · Issue #164 · espressif/esp-idf · GitHub and the comments that follow. A correction look-up table is available (comment 21 Oct 2021)