Datasheet

Advanced Example (12-bit, 3.0V Reference)
The original source for this code is included in the nRF52 BSP and can be viewed online here (https://adafru.it/zoe).
int adcin = A5;
int adcvalue = 0;
float mv_per_lsb = 3600.0F/1024.0F; // 10-bit ADC with 3.6V input range
void setup() {
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
}
void loop() {
// Get a fresh ADC value
adcvalue = analogRead(adcin);
// Display the results
Serial.print(adcvalue);
Serial.print(" [");
Serial.print((float)adcvalue * mv_per_lsb);
Serial.println(" mV]");
delay(100);
}
#define VBAT_PIN (A7)
#define VBAT_MV_PER_LSB (0.73242188F) // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
#define VBAT_DIVIDER (0.71275837F) // 2M + 0.806M voltage divider on VBAT = (2M / (0.806M + 2M))
#define VBAT_DIVIDER_COMP (1.403F) // Compensation factor for the VBAT divider
int readVBAT(void) {
int raw;
// Set the analog reference to 3.0V (default = 3.6V)
analogReference(AR_INTERNAL_3_0);
// Set the resolution to 12-bit (0..4095)
analogReadResolution(12); // Can be 8, 10, 12 or 14
// Let the ADC settle
delay(1);
// Get the raw 12-bit, 0..3000mV ADC value
raw = analogRead(VBAT_PIN);
// Set the ADC back to the default settings
analogReference(AR_DEFAULT);
analogReadResolution(10);
return raw;
}
uint8_t mvToPercent(float mvolts) {
uint8_t battery_level;
if (mvolts >= 3000)
{
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 156 of 175