Giter VIP home page Giter VIP logo

arduino_vcc's Introduction

arduino_vcc

Arduino library to read VCC supply level without external components

arduino_vcc's People

Contributors

yveaux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino_vcc's Issues

If using Minicore version 2.0.8, the compiler produces errors in this library

When trying to compile a sketch using this library and the Minicore board manager version 2.0.8 for a 328P 1MHz board, the compiler gives following errors:

"C:\\Users\\Eric\\AppData\\Local\\Temp\\arduino_build_851041\\libraries\\VccBatteryPercent\\Vcc.cpp.o"
In file included from C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.h:27:0,
                 from C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp:24:
C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp: In member function 'float Vcc::Read_Perc(float, float, boolean)':
C:\Users\Eric\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.8\cores\MCUdude_corefiles/Arduino.h:133:22: error: 'l' was not declared in this scope
   typeof (low) _l = (l);           \
                      ^
C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp:75:12: note: in expansion of macro 'constrain'
     perc = constrain(perc, 0.0, 100.0);
            ^~~~~~~~~
C:\Users\Eric\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.8\cores\MCUdude_corefiles/Arduino.h:133:22: note: suggested alternative: '_l'
   typeof (low) _l = (l);           \
                      ^
C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp:75:12: note: in expansion of macro 'constrain'
     perc = constrain(perc, 0.0, 100.0);
            ^~~~~~~~~
C:\Users\Eric\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.8\cores\MCUdude_corefiles/Arduino.h:134:23: error: 'h' was not declared in this scope
   typeof (high) _h = (h);          \
                       ^
C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp:75:12: note: in expansion of macro 'constrain'
     perc = constrain(perc, 0.0, 100.0);
            ^~~~~~~~~
C:\Users\Eric\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.8\cores\MCUdude_corefiles/Arduino.h:134:23: note: suggested alternative: '_h'
   typeof (high) _h = (h);          \
                       ^
C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp:75:12: note: in expansion of macro 'constrain'
     perc = constrain(perc, 0.0, 100.0);
            ^~~~~~~~~
C:\Users\Eric\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.8\cores\MCUdude_corefiles/Arduino.h:135:35: error: expected ';' before '}' token
   _x < _l ? _l : _x > _h ? _h :_x })
                                   ^
C:\Users\Eric\Documents\Arduino\libraries\VccBatteryPercent\Vcc.cpp:75:12: note: in expansion of macro 'constrain'
     perc = constrain(perc, 0.0, 100.0);
            ^~~~~~~~~

When doing a compile of the same sketch using the Minicore version 2.0.7, no compiler errors.

https://github.com/MCUdude/MiniCore/releases/tag/v2.0.8
Changelog:
- Fix export compiled binary for Windows computers
- Improve "unsafe" macros
- This includes abs(), min(), max(), sq(), round() and constrain()

The problem probably lies in the improved 'unsafe' macros like constrain()...

Read Vcc pulls 200uA with LowPower sleep

Your example VccSleep.ino, makes arduino pull 200 micro Amps in LowPower.
Commenting out Vcc.h code, gives correct LowPower of 4.5 micro Amps.
Tested on Pro mini 8Mhz.
It's not only your Vcc code that does this, but all readVcc code I found online does this.
I would be glad to see any solution to this.

4.5uA code:

#include <Vcc.h>
#include <LowPower.h>

const float VccMin        = 2.0*0.6;  // Minimum expected Vcc level, in Volts. Example for 2xAA Alkaline.
const float VccMax        = 2.0*1.5;  // Maximum expected Vcc level, in Volts. Example for 2xAA Alkaline.
const float VccCorrection = 1.0/1.0;  // Measured Vcc by multimeter divided by reported Vcc

Vcc vcc(VccCorrection);

void setup()
{
  Serial.begin(9600);
}

void loop()
{  
//  float v = vcc.Read_Volts();
//  Serial.print("VCC = ");
//  Serial.print(v);
//  Serial.println(" Volts");
//
//  float p = vcc.Read_Perc(VccMin, VccMax);
//  Serial.print("VCC = ");
//  Serial.print(p);
//  Serial.println(" %");
//
//  delay(200); //delay to allow serial to fully print before sleep

  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}

VccCorrection Question

Hello - I want to make sure I understand what I need to do to get the correct values in in the below line. It looks like I should measure the voltage of the battery power supply for the numerator and then run the code with the ratio = 1.0 and get the denominator and then plug in the respective values. Is this correct?

const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc

Thank you,
AFI

Support for new Arduino Nano Every (ATMEGA4809) planned?

Hi,

I tried to compile the VccSimple example on the new Arduino Nano Every (ATMEGA4809) and get the following errors. Are you planning support for this new board?

Thanks
Stephan

with register emulation for ATMEGA328

Arduino: 1.8.9 (Mac OS X), Board: "Arduino Nano Every, ATMEGA328"

/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp: In member function 'float Vcc::Read_Volts()':
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:7: error: 'ADMUX' was not declared in this scope
   if (ADMUX != ADMUX_VCCWRT1V1)
       ^~~~~
In file included from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/String.h:30,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Print.h:24,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Stream.h:25,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Client.h:22,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/ArduinoAPI.h:29,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/Arduino.h:23,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.h:27,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:24:
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:30: error: 'REFS0' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                              ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:30: note: suggested alternative: 'VREF_t'
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                              ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:43: error: 'MUX3' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                                           ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:55: error: 'MUX2' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                                                       ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:67: error: 'MUX1' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                                                                   ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:3: error: 'ADCSRA' was not declared in this scope
   ADCSRA |= _BV(ADSC);
   ^~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:3: note: suggested alternative: 'ADC_t'
   ADCSRA |= _BV(ADSC);
   ^~~~~~
   ADC_t
In file included from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/String.h:30,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Print.h:24,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Stream.h:25,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Client.h:22,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/ArduinoAPI.h:29,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/Arduino.h:23,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.h:27,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:24:
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:17: error: 'ADSC' was not declared in this scope
   ADCSRA |= _BV(ADSC);
                 ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:17: note: suggested alternative: 'ADC0'
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:61:28: error: 'ADC' was not declared in this scope
   float vcc = 1.1*1024.0 / ADC;
                            ^~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:61:28: note: suggested alternative: 'ADC0'
   float vcc = 1.1*1024.0 / ADC;
                            ^~~
                            ADC0
exit status 1

without register emulation for ATMEGA328 (ATMEGA4809)

Arduino: 1.8.9 (Mac OS X), Board: "Arduino Nano Every, None (ATMEGA4809)"

Build-Optionen wurden verändert, alles wird neu kompiliert
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp: In member function 'float Vcc::Read_Volts()':
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:7: error: 'ADMUX' was not declared in this scope
   if (ADMUX != ADMUX_VCCWRT1V1)
       ^~~~~
In file included from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/String.h:30,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Print.h:24,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Stream.h:25,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Client.h:22,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/ArduinoAPI.h:29,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/Arduino.h:23,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.h:27,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:24:
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:30: error: 'REFS0' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                              ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:30: note: suggested alternative: 'VREF_t'
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                              ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:43: error: 'MUX3' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                                           ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:55: error: 'MUX2' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                                                       ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:38:67: error: 'MUX1' was not declared in this scope
 #define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
                                                                   ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
   if (ADMUX != ADMUX_VCCWRT1V1)
                ^~~~~~~~~~~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:3: error: 'ADCSRA' was not declared in this scope
   ADCSRA |= _BV(ADSC);
   ^~~~~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:3: note: suggested alternative: 'ADC_t'
   ADCSRA |= _BV(ADSC);
   ^~~~~~
   ADC_t
In file included from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
                 from /Users/stephan/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/String.h:30,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Print.h:24,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Stream.h:25,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/Client.h:22,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/api/ArduinoAPI.h:29,
                 from /Users/stephan/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.1/cores/arduino/Arduino.h:23,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.h:27,
                 from /Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:24:
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:17: error: 'ADSC' was not declared in this scope
   ADCSRA |= _BV(ADSC);
                 ^
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:55:17: note: suggested alternative: 'ADC0'
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:61:28: error: 'ADC' was not declared in this scope
   float vcc = 1.1*1024.0 / ADC;
                            ^~~
/Users/stephan/Projects/arduino/libraries/Arduino_Vcc/Vcc.cpp:61:28: note: suggested alternative: 'ADC0'
   float vcc = 1.1*1024.0 / ADC;
                            ^~~
                            ADC0
exit status 1

Using LiPo 3.7V with Arduino Mini Pro

Hi,
Thank you for the great library. Hower a question and a problem.
I am using the Arduino Pro Mini (ATMega328P) 3.3V version.

Problem: I go in PowerDown (for 8 seconds). However in most cases the percentage reading is 0 (zero). Had anyone the same problem? After investigation I found out that the reading is correct until the first PowerDown (LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_ON);). After the first wakeup it reads always 0 (float p = vcc.Read_Perc(VCC_MIN, VCC_MAX);).

Question: When using the LiPo, the battery has a typical voltage of 3.7, but can go to 4.2 when fully charged. The LiPo is connected to the "RAW". What is the vcc_max to use? As far as I understood, the measurement is done after the (internal) regulator on the Vin (so +-3.3 max, correct?). So what is then the min and max to use.

Recommendation: would also be great to add an example with voltage higher than 3V. You are using only 2 alkaline in your example of 1.5...

Thanks again!

Filip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.