Using EmonLib with Arduino Zero or MKR1000

Hello friends!

I’ve been searching around a bit and not really finding anything helpful.
My question is:

What changes will I need to make in order to run the basic voltage_and_current sketch on an Arduino Zero or MKR1000? I have found that I need to include " analogReadResolution(12);" in my setup function in order to accommodate the 12-bit ADC of the Zero. Are there other changes I need to make in consideration of the 3.3v operating voltage?

Hi Nick,

The line you need to include should read analogReadResolution(ADC_BITS);
vice analogReadResolution(12);

Here’s the example in EmonLib.h

// to enable 12-bit ADC resolution on Arduino Due,
// include the following line in main sketch inside setup() function:
//  analogReadResolution(ADC_BITS);
// otherwise will default to 10 bits, as in regular Arduino-based boards.
#if defined(__arm__)
#define ADC_BITS    12
#else
#define ADC_BITS    10
#endif

I’ve been experimenting with an Arduino Due for the last two days, so that’s one change I’m aware of.
As I’m just getting started with it myself (the move to a 32-bit µcontroller) I’m not completely up to speed on other changes that will be necessary.

Thanks for catching that! I misread it but I see how it is setup now.

Did you find a way to make this work ? My MKR1000 Seems to be giving inaccurate values.

These are the values i get when i don’t have anything connected.
Power , IRMS
115.85 0.97
116.76 0.97
119.50 1.00

That is quite meaningless - there’s no indication what the scale of your units is. If you have that badly wrong, the smallest amount of noise could give those numbers. And in our experience, unless you have been very careful with filtering and screening of your analogue front end (including the ADC reference voltage) then noise can be significant. Check that, and work through the maths of calibration - including the voltage reference that emonLib uses.