Hi. I've had a hard time trying to run emonLib on a Mega2560.
I realized the ADMUX needs to be programmed differently.
I was about to post about this when I saw it had been modified in a recent commit already :
FWIW, here's what I had found, which may add compatibility for other Arduinos (and has a default case) :
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif
Note that I have no idea whether or not the "tiny" can run the rest of the emonLib code.
Re: RESOLVED - emonLib support on different Arduinos
Thanks, I've added support for ATtiny's: https://github.com/openenergymonitor/emonlib
The recent commit added support for Arduino Leonardo's ready for the upcoming emonTx shield.
Happy days!