Need help in using the emonLibCM with esp32

Hello Wonderfull People !,
I hope you’re all very well, I am going to get straight to the point. I want to use this library for the ESP32, Previously I was using emonlib esp32 version by [@Savjee] (Savjee) Link to the Library , its working fine but there is no accuracy if the current is lower than 1 Amp. Found this library and want to shift to this one as this EmonlibCM has more accuracy.

I am unable to even compile the code. Just using esp32 dev kit v1 and a YHDC 30A/1V CT with the circuit mentioned by the emon learn page. (Really appreciate the work you guys do)

Kindly help me out here.

I removed the rf module part from the EmonLibCM Max example and I am getting this error

EmonLibCM-master/emonLibCM.h:50:24: fatal error: util/crc16.h:
No such file or directory compilation terminated.
exit status 1 Error compiling for board ESP32 Dev Module

Thanking in advance


Welcome, @saadimtiaz to OEM.

Sorry, but I don’t have an ESP32 to test the code on, the emonLibCM was written specifically for the Atmel ATMega 328P.

The library you are missing is part of the standard Arduino installation [Arduino directory]/hardware/tools/avr/avr/include/util/crc16.h - if you are not using that, then I’m afraid I cannot help you - but someone else might.

But – changing to emonLibCM will make a big difference if you have a rapidly switched load, but it won’t necessarily make a difference to the accuracy at very low currents. Every c.t. is inherently inaccurate at low current - this is due to how the magnetics in c.t’s work, and depending on how much you paid for your c.t. will make the difference about what “low” means in relation to the rated maximum current. For example, your YHDC SCT-013-030 is only specified down to 10% of rated current, i.e. 3 A. Below that, the manufacturer makes no claims for its accuracy.

You don’t say what sort of inaccuracy you have, but you should probably look at your breadboard layout and power supply filtering as a first move.

Thank you @Robert.Wall for the response, this is sad news. Looks like I will have to play with the library to make it compatible with the ESP32.

As you mentioned the rapidly switching load ( how fast do you mean ? )
I am using the emonlib to monitor the current of my Inverter Air Conditioner and its working fine.
I just wanted to use the emonlibCM to get the total kWh and accurate power factor, as emonlib is not accurate for that.

Looks like I might need a hybrid setup - 328P with ESP32…

Thanks again. Much appreciated.

Fast compared to most domestic loads, e.g. an induction hob switching every few seconds, rather than (say) an electric kettle that’s on for a few minutes, or a refrigerator that runs for 10 mins then off for 20 mins.

Provided that you calibrate your emonLib sketch correctly, and with steady loads, there should be little difference between emonLib and emonLibCM.

Are you aware of this regarding the 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) which, if the comments there are accurate, and I’ve no reason to disbelieve them, will be more or less essential to use if you require accuracy.

I think I must leave that to you. As I mentioned I don’t have an ESP32, but much worse, I don’t think I’ll ever find the time to make emonLibCM usable with it.

Its alright no worries, thanks for all the awesome work and help :slight_smile:

I’ll check it out and let you know, Thanks for the help, much obliged