Feather M0 - Lipo Voltage reading - Bug in tutorial ?

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mchobby
 
Posts: 73
Joined: Tue Jan 24, 2012 3:14 pm

Feather M0 - Lipo Voltage reading - Bug in tutorial ?

Post by mchobby »

Hi,

In the M0 tutorial... https://learn.adafruit.com/adafruit-fea ... ng-battery

you are reading the Lipo Voltage and convert the reading to voltage with the following code.

Code: Select all

#define VBATPIN A7
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2;    // we divided by 2, so multiply back
measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage
Serial.print("VBat: " ); Serial.println(measuredvbat);
However, the M0 ADC have a resolution of 12 bits so the value should go from 0 to 4095 when reading the voltage.
So the line

Code: Select all

measuredvbat /= 1024; // convert to voltage
should become for the feather M0.

Code: Select all

measuredvbat /= 4096; // convert to voltage
Am'I right?

User avatar
mailhouse
 
Posts: 107
Joined: Sat Jul 25, 2015 8:06 pm

Re: Feather M0 - Lipo Voltage reading - Bug in tutorial ?

Post by mailhouse »

I get sane values returned for 1024 but not 4096. I dont have an explanation why your thought process seems correct but the results dont jive, but i'm new to all this.

User avatar
adafruit_support_mike
 
Posts: 67963
Joined: Thu Feb 11, 2010 2:51 pm

Re: Feather M0 - Lipo Voltage reading - Bug in tutorial ?

Post by adafruit_support_mike »

The SAMD21's ADC has configurable resolution. The default is 10-bit to make it compatible with all the other Arduino code that already exists.

You can change it with the analogReadResolution() function: http://www.arduino.cc/en/Reference/AnalogReadResolution

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”