This feels like a total noob question, but it is driving me crazy that I can't figure out the problem here. I am trying to get the Teensy to measure the battery voltage with a Lipo attached, with to the Featherwing adapter and I keep getting a value from the Teensy that is too low.
I even wired up an external voltage divider and still get the same low result (roughly 3.8-3.9 volts when it should be around 4.2).
I measured actual voltages at the A7 pin (when using the internal divider from the Featherwing adapter), and I get the expected 2.1v reading.
I grabbed the example code from the FeatherOLED and modified it slightly (since the micro isn't recognized, it would default to an "unknown feather" message). I also pulled out all of the code relating to the OLED to make sure something odd wasn't happening there.
I pulled out all of the if statements that determine the feather type, and just defined the battery pin as A7 (the center of the voltage divider). I even modified it to serial print each step of the battery voltage calculation, and the raw reading is coming in low.
My gut is telling me that I am missing a #define statement that would tell the code that this is a teensy 3.2, or there is something amiss with my analog reference voltage. The AREF pin reads 3.3v when I check it. Alternately, I could have a solder issue, but I inspected the solder joints under a microscope and can't see anything that looks "off".
I also ran a separate test the does an analogwrite() which slowly increments in value and an analogwrite() reads those values (connecting A14/DAC to A0). That works perfectly fine (raw values of the read are close to the write value), so I think this is a glitch in my code below.
Finally, I also ran the "battery" example from the FeatherOLED library "as-is" on a Feather328 with the same OLED plugged into it and it gave accurate battery voltage values.
What am I missing here?
I copied a sequence of the serial output below the code. The values are very similar if using my external resistor divider, too (pin A0).
Serial Output Example:
I even wired up an external voltage divider and still get the same low result (roughly 3.8-3.9 volts when it should be around 4.2).
I measured actual voltages at the A7 pin (when using the internal divider from the Featherwing adapter), and I get the expected 2.1v reading.
I grabbed the example code from the FeatherOLED and modified it slightly (since the micro isn't recognized, it would default to an "unknown feather" message). I also pulled out all of the code relating to the OLED to make sure something odd wasn't happening there.
I pulled out all of the if statements that determine the feather type, and just defined the battery pin as A7 (the center of the voltage divider). I even modified it to serial print each step of the battery voltage calculation, and the raw reading is coming in low.
My gut is telling me that I am missing a #define statement that would tell the code that this is a teensy 3.2, or there is something amiss with my analog reference voltage. The AREF pin reads 3.3v when I check it. Alternately, I could have a solder issue, but I inspected the solder joints under a microscope and can't see anything that looks "off".
I also ran a separate test the does an analogwrite() which slowly increments in value and an analogwrite() reads those values (connecting A14/DAC to A0). That works perfectly fine (raw values of the read are close to the write value), so I think this is a glitch in my code below.
Finally, I also ran the "battery" example from the FeatherOLED library "as-is" on a Feather328 with the same OLED plugged into it and it gave accurate battery voltage values.
What am I missing here?
I copied a sequence of the serial output below the code. The values are very similar if using my external resistor divider, too (pin A0).
Code:
// Adafruit OLED FeatherWing Battery Example
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
// integer variable to hold current counter value
int count = 0;
void setup()
{
Serial.begin(115200);
//analogReadResolution(12);
}
void loop()
{
float battery = getBatteryVoltage();
// increment the counter by 1
count++;
// delay 1 second (1 second == 1000 milliseconds)
delay(1000);
}
#define VBATPIN A7
#define EXTVBATPIN A0
float getBatteryVoltage() {
float measuredvbat = analogRead(EXTVBATPIN);
Serial.print(measuredvbat);Serial.print(" ");
measuredvbat *= 2; // we divided by 2, so multiply back
Serial.print(measuredvbat);Serial.print(" ");
measuredvbat *= 3.3; // Multiply by 3.3V, our reference voltage
Serial.print(measuredvbat);Serial.print(" ");
measuredvbat /= 1024; // convert to voltage
Serial.println(measuredvbat);
return measuredvbat;
}
Serial Output Example:
Code:
598.00 1196.00 3946.80 3.85
567.00 1134.00 3742.20 3.65
602.00 1204.00 3973.20 3.88
589.00 1178.00 3887.40 3.80
556.00 1112.00 3669.60 3.58
583.00 1166.00 3847.80 3.76
596.00 1192.00 3933.60 3.84
589.00 1178.00 3887.40 3.80
582.00 1164.00 3841.20 3.75
571.00 1142.00 3768.60 3.68
587.00 1174.00 3874.20 3.78
599.00 1198.00 3953.40 3.86
588.00 1176.00 3880.80 3.79
596.00 1192.00 3933.60 3.84
595.00 1190.00 3927.00 3.83
599.00 1198.00 3953.40 3.86
564.00 1128.00 3722.40 3.64
596.00 1192.00 3933.60 3.84
582.00 1164.00 3841.20 3.75
580.00 1160.00 3828.00 3.74
586.00 1172.00 3867.60 3.78
587.00 1174.00 3874.20 3.78
588.00 1176.00 3880.80 3.79