Explorer Battery level

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.

pcb assemble

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?

1 Like

Thanks for letting us know.
I will come back to you how to use this pin.

1 Like

Hi @Jan any update on how to measure internal battery in rev 6C boards?

Thanks!

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.

2 Likes

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.

1 Like

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);
}
1 Like

Sorry to re-open old topic. May I know how with voltage divider schematic you refer on the support page the battery level can be measured? Also, I have coin LIR2450 coin battery on Sodaq ExpLoRer, how could i monitor battery level? thanks lot

The voltage divider was added in Rev6. You can see the diagram and the resistor values in the MCU section above the main symbol in the 6c schematic: http://support.sodaq.com/wp-content/uploads/2018/02/explorer_schematic_rev6c_868.pdf

The AIN for the reading voltage is attached to PB05. This is not in the current board files but will be released in the next version (v1.6.20). The pin will have a defined label BAT_VOLT.

If you need it before then you can get a copy of v1.6.20 from the test release here:
http://downloads.sodaq.net/test/package_test_sodaq_samd_index.json

Please note that the test release versions will change and this can cause issues with the Arduino IDE’s cached copies and their checksums. This can always be fixed by cleaning out the ‘staging’ folder that Arduino creates (the default location on the Windows platform is in /AppData/Local/Arduino15).

This solution worked for me. (Sodaq Explorer Rev. 6c)
I removed the coin cell, unplugged the USB cable, and used a power supply as the 4.20V reference. I used the JST battery connector on the explorer to power the board. Remember to switch the battery switch from INT to EXT.

The analog read from the BAT_VOLT pin was 902, 4.20 / 902 = .00465632.
I then reduced the supply voltage in .1 volt steps to check my work. Note: the board does not work with <3.6V.

If you repeat the experiment remember the resistors are +/-5% and you’ll get a slightly different result.

float getBatt(){
uint16_t mVolts = analogRead(BAT_VOLT);
SerialUSB.println(mVolts);
float batt = (mVolts * .00466);
SerialUSB.println(batt);
return float(batt);
}