Is it possible to get an estimate of LiPo battery connected to Adafruit Feather

Hi,

I am using a Adafruit Feather M0 with RFM95 LoRa module connected to a 3.7V, 1200mAh LiPo battery. I am trying to figure out a way to print out the voltage and battery level of the battery using a sketch I wrote after reading some blogs but I think I am doing something wrong since the value of battery charge is not changing.

According to the documentation, GPIO 9 (analog input is connected to a voltage divider for the lipoly battery ).
But A0 - This pin is analog input A0 but is also an analog output due to having a DAC (digital-to-analog converter). You can set the raw voltage to anything from 0 to 3.3V, unlike PWM outputs this is a true analog output.
So I am a not sure which pin I should be using. But Below is the code I am using.

const float MAX_BATTERY_VOLTAGE = 4.2;  // Max LiPoly voltage of a 3.7 battery is 4.2
void setup() {
  Serial.begin(9600);
}

void loop() {

  int rawValue = analogRead(9);
  float voltageLevel = (rawValue / 4095.0) * 2 * 1.1 * 3.3;  // calculate voltage level
  float batteryFraction = voltageLevel / MAX_BATTERY_VOLTAGE;
  Serial.println((String) "Raw:" + rawValue + " Voltage:" + voltageLevel + "V Percent: " + (batteryFraction * 100) + "%");
  delay(1000);
}

Please explain. Also post a wiring diagram of your voltage divider.

Why can't You use one pin for analogRead and another for the output? I guess that switching from output to analog input there might be some settling time to pay attention to.

It's not perfectly clear that the OP is using the DAC for anything...

What is that value? Did you try serial printing the raw ADC value? Edit - now I see that you already do. What is the value that is printed?

Please explain the significance of this. Are you concerned that you have made a mistake and used the pin incorrectly, or do you need DAC functionality for something?

Not at the same time.

Most pins have alternative functions, which you need to select in the code using function calls, before using the alternative.

These are the values being printed

Raw:574 Voltage:1.02V Percent: 24.23%
Raw:575 Voltage:1.02V Percent: 24.27%
Raw:576 Voltage:1.02V Percent: 24.31%
Raw:574 Voltage:1.02V Percent: 24.23%
Raw:574 Voltage:1.02V Percent: 24.23%

I was trying to figure out which pin should I use in order to get the voltage readings. I looked at the pinouts (Pinouts | Adafruit Feather M0 Radio with LoRa Radio Module | Adafruit Learning System) in order to find that. Since I am not dealing with DAC I thought about using pin 9.

The only purpose here is to pint out the remaining battery charge.

I was reading about how to calculate Voltage Level. (https://bit.ly/2zFzfMT), How to measure battery voltage? · Issue #35 · Xinyuan-LilyGO/TTGO-T-Display · GitHub

  • #9 - GPIO #9, also analog input A7. This analog input is connected to a voltage divider for the lipoly battery so be aware that this pin naturally 'sits' at around 2VDC due to the resistor divider

analogRead(A7) is what you need.

Yes, That's what I am using right now. Thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.