openenergymonitor / EmonLib

Electricity monitoring library - install in Arduino IDE's libraries folder then restart the IDE
openenergymonitor.org
GNU Affero General Public License v3.0
593 stars 419 forks source link

Arduino Nano Every NOT Supported #68

Open GabriCattazz01 opened 2 years ago

GabriCattazz01 commented 2 years ago

Hi guys, we have bought the newest arduino nano every for our IOT projects and to monitoring houses consumptions.

However, we have seen that your library does not yet support these models... The arduino compiler gives us this ADC register error :

/* C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp: In member function 'long int EnergyMonitor::readVcc()': C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:253:3: error: 'ADCSRA' was not declared in this scope ADCSRA |= _BV(ADSC); // Convert ^~ C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:253:3: note: suggested alternative: 'ADC_t' ADCSRA |= _BV(ADSC); // Convert ^~ ADC_t

ADCSRA |= _BV(ADSC); // Convert ^ C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:253:17: note: suggested alternative: 'DDRC' C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:255:12: error: 'ADCL' was not declared in this scope result = ADCL; ^~~~ C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:255:12: note: suggested alternative: 'ADC0' result = ADCL; ^~~~ ADC0 C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:256:13: error: 'ADCH' was not declared in this scope result |= ADCH<<8; ^~~~ C:\Users\Mauro\Documents\Arduino\libraries\EmonLib-master\EmonLib.cpp:256:13: note: suggested alternative: 'ADC0' result |= ADCH<<8; ^~~~ ADC0 */

Would you able to integrate this model in your library? Thanks!

AndreLuisFeltrin commented 1 year ago

For atmega4809 make this change inside emonlib.cpp file:

if defined(AVR)

delay(2); ADC0.COMMAND = ADC_STCONV_bm; while (ADC0.INTFLAGS & ADC_RESRDY_bm == 0) ; result = ADC0.RES; ADC0.INTFLAGS = ADC_RESRDY_bm; result = READVCC_CALIBRATION_CONST / result; // 1100mV*1024 ADC steps http://openenergymonitor.org/emon/node/1186 return result;

elif defined(arm)

return (3300); // Arduino Due

else

return (3300); // Guess that other un-supported architectures will be running a 3.3V!

endif

}