Hi gabriel,
i write this simple code to measure the voltage of battery of mbili rev 6b.
#define ADC_AREF 3.3
#define BATVOLTPIN A6
#define BATVOLT_R1 4.7
#define BATVOLT_R2 10
void setup() {
Serial.begin(57600);
while(!Serial){
}
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(getRealBatteryVoltage());
delay(1000);
}
float getRealBatteryVoltage() {
uint16_t batteryVoltage = analogRead(BATVOLTPIN);
return (ADC_AREF / 1023.0) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * batteryVoltage;
}
I have any question:
- pin A6 is correct to measure the level of lipo battery ? I do not have to connect any wire?
- i read (with battery and usb connected) always 4.22 Volt. Is correct?
- What is the minimum voltage level to declare the exhausted battery or fully charged?
- is it possible to know also the level of current coming from the solar panel?
- where can I find a lib written by you on battery level management for sodaq mbili rev 6b ?
thanks
Here is the schematic for the Mbili Rev 6b: http://support.sodaq.com/wp-content/uploads/2016/08/sodaq_mbili_rev6b_sch.pdf
- If you look in the JST section you can see that A6 is connected to the voltage divider using the same resistor values as in that code.
- Both the USB and the Solar Panel will charge the LiPo battery. When either is attached you will read either the charge voltage or the battery voltage, whichever is greater.
- This will depend on the specifications of that attached battery and the requirements of whatever components you are using. For instance the Mbili MCU runs at 3.3v, but the GPRSbee I believe requires a minimum of 3.5v. You may start running into issues once the voltage drops below 3.7v.
- You will need an additional hardware to measure this.
- There is no library for this. The only code you really need is the function above which measures the voltage level.
You could use a breakout board such as this one to measure the current: https://www.sparkfun.com/products/8883
Alternatively, you could approximate the charge current by measuring the voltage coming off of the solar panel. Due to the Mbili operating at 3.3V levels, you will not be able to attach the solar panel directly to an analog input, you will need to use a voltage divider to reduce the voltage to with the acceptable input range.