Hi All,
Can anybody give me any tips on how to monitor the internal and external battery levels?
Setting up completely autonomous nodes with the standard coin battery and a solar panel (and maybe an external if needed)
Regards
Paul
Hi All,
Can anybody give me any tips on how to monitor the internal and external battery levels?
Setting up completely autonomous nodes with the standard coin battery and a solar panel (and maybe an external if needed)
Regards
Paul
Anybody got any ideas please?
Hi,
You can make a voltage divider to read the battery voltage.
On our support page we have a function how to read the voltage with a voltage divider
http://support.sodaq.com/sodaq-one/battery/
Regards,
Jan
Will this work for a coin battery? I thought that with coin batteries, the output voltage remains quite steady until the battery is basically spent?
This is true for non-rechargeable coin cells.
On the Explorer we use a rechargeable LIR2450 coin cell. Here the voltage is between 4.2V and 3.5V.
See datasheet:
Hi!
I am also wanting to do this with the Explorer board, like the OP, but I am more novice than is seemingly required to understand Jan’s description as to how to achieve this. The link (http://support.sodaq.com/sodaq-one/battery) is obviously for the Sodaq One board. Will the provided sketch work the same for monitoring the LIR2450 coin cell battery supplied with the Explorer board; or, if not, how would I need to modify it? Also, would I need to physically build a voltage divider? Sorry - as I said - total noob.
I would like to be able to plant the board remotely and be alerted by Cayenne when the battery level falls below a threshold, thereby allowing me to go and rescue it.
Thanks!
RP1
Hi…i am a new user here. As per my understanding you need a voltage divider, a voltage divider is a passive linear circuit that produces an output voltage (Vout) that is a fraction of its input voltage (Vin). Voltage division is the result of distributing the input voltage among the components of the divider.
I’m using Mbili rev. 6b and trying to periodically read battery voltage level. I’m using the following code:
#define ADC_AREF 3.3
#define BATVOLTPIN A6
#define BATVOLT_R1 4.7
#define BATVOLT_R2 10
float getRealBatteryVoltage() {
uint16_t batteryVoltage = analogRead(BATVOLTPIN);
return (ADC_AREF / 1023.0) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * batteryVoltage;
}
I have a RTC set to make an interrupt every 15min and I send a battery voltage via MQTT using GPRSbee. The problem is that battery level is only correctly sent the first time. Every other time the value stays unchanged. If I press a reset button it sends a new value and continue sending it until the next hardware reset.
What am I doing wrong?
The code you posted above appears to be correct. This leads me to believe that there may be an issue somewhere else in your code.
Could you post your full sketch above? Alternatively, you can email me it at gabriel at sodaq dot com.
Thanks Gabriel, I found a problem. I was turning off and on ADC the wrong way when going to and from power down sleep. Now I’m getting battery reading normally. Thanks!
How can I measure the battery level on Explorer rev 6C? I see on the schematics there is an VBAT_MEASURE pin already connected to a voltage divider on this board revision, but this pin is not defined in the software. I looked the variant.cpp file and it looks like no definition is attached to this pin. I’m using the SODAQ SAMD board package version 1.6.11.
How can I use it?
Thanks for letting us know.
I will come back to you how to use this pin.
Hi all,
Add the following line to variant.cpp g_APinDescription
{ PORTB, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // VBAT
And use 48 as the pin number.
I haven’t tested this, let me know if this works.
Regards.
I’m using the Arduino IDE, is this modification done in the libraries sources? Which library?
Hi ismangil,
You need to edit the file here:
%localappdata%\arduino15\packages\SODAQ\hardware\samd\1.6.17\variants\sodaq_explorer
Variant.cpp
Consider using Visual Studio + VMicro for larger projects.
Regards
Yes, it works. It would be nice if Sodaq include this on the next board definition release for Arduino IDE.
Hi jairorotava,
I’ve contacted the maintainers of this code, it will be part of the next major release as long is it is not too soon.
Thank you for testing the solution.
Regards
Could you please share your code snippet to do this?
Find your variant.cpp file. My variant.cpp file was on this directory (the version may be different):
%localappdata%\arduino15\packages\SODAQ\hardware\samd\1.6.11\variants\sodaq_explorer
Find a table with this name:
const PinDescription g_APinDescription[]=
Add after last line:
//48 Vbat
{ PORTB, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // VBAT
Should look like this:
// 47 Button
{ PORTA, 14, PIO_OUTPUT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 }, // BUTTON
//48 Vbat
{ PORTB, 5, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // VBAT
Then you can read the battery voltage (mV) with this code:
#define ADC_AREF 3.3f
#define BATVOLT_R1 4.7f
#define BATVOLT_R2 10.0f
#define VBAT_MEASURE 48
uint16_t getBatteryVoltage()
{
pinMode(VBAT_MEASURE, INPUT);
uint16_t voltage = (uint16_t)((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(VBAT_MEASURE));
return(voltage);
}