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
596 stars 422 forks source link

Arduino Wifi rev 2 compatibility #56

Open 1omarsaid opened 4 years ago

1omarsaid commented 4 years ago

It doesnt seem like this library works with the arduino uno wifi rev 2 due to the change of the analog pin names. I get the following error:



/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp: In member function 'long int EnergyMonitor::readVcc()':
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:3: error: 'ADCSRA' was not declared in this scope
   ADCSRA |= _BV(ADSC);                             // Convert
   ^~~~~~
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:3: note: suggested alternative: 'ADC_t'
   ADCSRA |= _BV(ADSC);                             // Convert
   ^~~~~~
   ADC_t
In file included from /Users/omarsaid/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/String.h:30,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Print.h:24,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Stream.h:25,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Client.h:22,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/ArduinoAPI.h:29,
                 from /Users/omarsaid/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:23,
                 from /Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.h:15,
                 from /Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:13:
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:17: error: 'ADSC' was not declared in this scope
   ADCSRA |= _BV(ADSC);                             // Convert
                 ^
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:251:17: note: suggested alternative: 'ADC0'
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:253:12: error: 'ADCL' was not declared in this scope
   result = ADCL;
            ^~~~
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:253:12: note: suggested alternative: 'ADC0'
   result = ADCL;
            ^~~~
            ADC0
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:254:13: error: 'ADCH' was not declared in this scope
   result |= ADCH<<8;
             ^~~~
/Users/omarsaid/Documents/Arduino/libraries/EmonLib-master/EmonLib.cpp:254:13: note: suggested alternative: 'ADC0'
   result |= ADCH<<8;
             ^~~~
             ADC0
exit status 1
Error compiling for board Arduino Uno WiFi Rev2.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.```

Any way I can change the code to make it compatible with the arduino uno wifi rev 2? I know I need to make some changes to the "ADC" and looking online, I see that they changed the names to AIN but I am not sure exactly what to do.
TrystanLea commented 4 years ago

Hello @1omarsaid we are not targeting support for Arduino Wifi so Im afraid it is not likely that this will be fixed. Let us know if you work out what is needed to fix

J0J015JK commented 3 years ago

I changed the registers so that Emonlib will work on the Arduino UNO WiFi I called it EmonDIY so just change the #include Emonlib line to include EmonDIY Download link => https://github.com/J0J015JK/EmonDIY

gbtassara commented 3 years ago

Dear J0J015JK, it seems your lib does not work on Arduino UNO WIFI rev2... it seems that MUXPOS, REFSEL0, AIN1, AIN2, AIN3, ADCn.COMMAND, STCONV, ADCn.RESL, ADCn.RESH are not defined...