Hi There,
i am trying to estimate the battery status of a 9V Lithium-Ion Akku connected to my Arduino Nano BLE via the VIN pin.
I am aware of the method where i could connect the 9V (after two resistors) to one of the analog pins to compare the voltage to the internal reference and via the relation of Voltage to Battery-discharge i get an estimate of the battery.
However, i would prefer to measure the status by comparing the input voltage with the internal voltage reference. I am aware that due to the voltage regulator most of the information is lost, but i really dont care about a good estimate. I just want a heads-up a few hours before the battery dies and i hope to find that signal even after the voltage regulator.
There are plenty of explanations available where this is done for some arduino boats https://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ (i believe mostly for AVR boards) see for example this code:
long readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#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
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA,ADSC)); // measuring
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
long result = (high<<8) | low;
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
return result; // Vcc in millivolts
}
My Questions is: Is this also possible for the Nano 33 BLE? Two days of (unexperienced) research got me nowhere.
Trying to run the above Code i find that all the constants (probably of the AVR Chip) are not defined.