Read battery_level like SYS_GetBatteryLevel() for RUI3

Hello,

in STM32IDE there is a function SYS_GetBatteryLevel() to get the batterylevel of the chip.

Is there a function for Arduino available?

Greetings

E_T

You can use api.system.bat.get() API. But this is designed to work on the RAK3172 Evaluation Board. This board is based on WisBlock Base board and has built-in voltage divider.

image

You can also try to use analog read directly and choose on two analog inputs of RAK3172.

We have example code for the Analog read.

You can change ADC1 or ADC2 via WB_A0 or WB_A1 respectively.

image

Thank you!

Greetings
E_T

@carlrowan, how do i set vREF?
I’m using a CR2032 battery and I can’t get its voltage, analogRead() always returns 1023 on ADC1 (I connected the VCC directly to ADC1)

Hi @dgois100 ,

CR2032 will have a voltage around or less than 3V. Currently, the default VRef of ADC is VDD voltage. It means that you will not be able to track the voltage level properly. We have an API that can set the voltage reference but it seems to have issue at the moment.

If you need CR2032 on your project, another workaround is to series two CR2032. With this approach, you’ll have 5 to 6V voltage input on the board. You can have a steady 3.3V VDD which means you can track the CR2032 batteries effectively.

@carlrowan Hi,

Now, Before I will purchase some samples of RAK3172 smd modules, I hope to get clear information about ADC pins and feature.
I want to make my own board using RAK3172 smd module (without evaluation board and base board).

Considering;

Working platform: Arduino and RUI3 API the latest version
Only Available ADC Pins: ADC1(32) and ADC2(31)

How does api.system.bat.get() work?
Which ADC pin should use and how to wire externally, Or is it internal feature of module/mcu without need external wiring?
Because there is no Pin definition as a parameter for this system API.
Since this is RAK3172 and “ADC voltage reference for RAK3172 and RAK3172-SiP is fixed to VDD voltage”.
And ADC voltage reference could not bu set using analogReference() for any other RAK_ADC_MODE precise voltage reference level.

With external wiring between VDD(Battery) and any ADC pin (direct wiring or a resistor division), Are you sure api.system.bat.get() will measure as a float (Unit: Volt) when VDD(Battery) is at any unknown level from 2.6V to 3.6V?
Because, actually we don’t have an absolute reference.

And my next question will be about using readAnalog() for another purpose within the same issue.

Thank you

Hi @mserkanu ,

Welcome to RAK forum.

The battery api is based on the voltage divider of the WisBlock Base boards and goes to ADC1 (WisBlock A0 pin). If you use the same voltage divider resistor network, you should have the voltage value directly (I think this is the one you mentioned that is in float unit: Volt).

However, you should have a steady voltage supply of 3.3v to make this work. If your VDD level change or not fix, it is impossible for you to get a useable reading since your ADC values wont have a fix voltage reference.

Hi @carlrowan ,
Thank you for the information.

Currently RUI3, for battery powered operations that seems impossible to use properly api.system.bat.get() for battery measurement and analogRead(pin) for other analog measurement as a voltage.

To implement a 4 20ma sensor node, an external voltage reference IC will be needed.

  1. Wire IC to ADC1 and wire 4 20ma analog circuit to ADC2
  2. Once analogRead(pin) on ADC1 as reference and every time analogRead(pin) on ADC2
  3. Compare these values and calculate 4 20ma

This time there is no pins left to measure battery level and will not be able to send information.

Maybe using an additional switching circuitry.

For RAK3172, in the next version RUI3 API, internal reference voltage levels ( analogReference(type); RAK_ADC_MODE; 1.2V, 1.8V, 2.4V, 3.0V ) will be available?

HI @mserkanu ,

  1. More ADC pins useable will be supported in future version on RUI3.
  2. Configurable reference will not be supported by RAK3172. It is only possible on WisDuo RAK4630 which has those configurable internal voltage reference.

Hello! Can you please provide any updates how measure battery voltage ? Thanks!

Hi @Diaver ,

This post is all about battery measurement.

Please check my reply here (same thread) Read battery_level like SYS_GetBatteryLevel() for RUI3 - #2 by carlrowan