Battery Level SAMD21proRF

Have questions about a SparkFun product or board? This is the place to be.

Moderator: phalanx

Post Reply
awootton
Posts: 7
Joined: Sat Jul 18, 2015 5:55 pm

Battery Level SAMD21proRF

Post by awootton » Wed Feb 06, 2019 12:17 am

I'd like to take (and send) battery readings. I can do this with Sodaq boards because they have a voltage divider on the Lipo charge circuit. Here's the code to read it (NB: pin A6):

Code: Select all

#define ADC_AREF 3.3
#define BATVOLTPIN A6
#define BATVOLT_R1 4.7
#define BATVOLT_R2 10

float getRealBatteryVoltage() {
  uint16_t batteryVoltage = analogRead(BATVOLTPIN);
  return (ADC_AREF / 1023.0) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * batteryVoltage;
}
So my question is can I do this with the Sparkfun board? Looking at the schematic I see there is a divider with VBATT_LVL marked and as far as I can see this is on A5. So can I use the same code (changing to A5 of course)?

Post Reply