EmonLib icon indicating copy to clipboard operation
EmonLib copied to clipboard

Solve most of your issues, ESP32

Open alexmoz2016 opened this issue 2 years ago • 4 comments

Some code that you may want to change to make it work (I have ESP32): In EmonLib.h:

	#if defined(__arm__)
	#define ADC_BITS    12
	#else
	#define ADC_BITS    10
	#endif

Just add/replace with: #define ADC_BITS 12

Because ESP32 is a 12-bit ADC.

In EmonLib.cpp Replace all occurences of "/1024" by "/(ADC_COUNTS>>1". The code was originally written for a 10-bit ADC, without ability to change it to 12 bits.

That's all. The precision and predictability of the reading is improved a lot.

Another note, for Calibration (111.1 value). If you have a voltage-output sensor (SCT-013-015, SCT-013-020, etc.), replace the "111.1" with "15" for -015, "20" for -020, etc. In other words, use the same calibration value as the Amp/V value (15A/V use "15", 30A/V use "30"). Most of the examples I saw online, using the 111.1 calibration value, are only good for SCT-013-000 with current output (which also require a burden/load resistor). Since the non-000 (-015, -020, -050, etc.) sensors have the burden/load resistors integrated, the calibration constant is different.

I hope it helps someone. Took me a few days to figure it out.

Alex

alexmoz2016 avatar Apr 02 '23 02:04 alexmoz2016