hello everyone, my project is progressing well and my RAK3172 is working wonderfully, I still have one or two things left to finish it, my question concerns the battery level, I read on the forum contradictions on the ADC divider I have a “custom board” should I not modify my power supply circuit or not to use “api.system.bat.get()”?

It depends.

The problem is that the ADC input of the STM32WLE5 requires a impedance in the kOhm area to work well.
But that means a quite high power consumption all the time.

We use the 1M/1.5M in our WisBlock Base Boards and api.system.bat.get() is adjusted to work with this high impedance resistor divider with some “calculations” to get the “correct” (estimated) values.

So there are two ways:
(1) if the relative accuracy of api.system.bat.get() is good enough for you, you can use the 1M/1.5M resistor divider.
(2) if you need higher accuracy, use the analogRead() function, use a resistor divider in the kOHm area and add a mosfet and a GPIO to disconnect the divider when not needed.

1 Like

no I only need relative precision it’s unique to know if the battery is almost empty, so in summary I have to modify my PCB to include the red circle circuit?

Correct, with this resistor divider with 1M/1.5M the api.system/bat/get() will work.
I am usually doing 10 readings in a row and take the average.

ok thank you for this clarification, the only downside is that I will have to buy PCBs hahaha

OK, my script doesn’t work, must I be doing things wrong? here is the response of the script with or without battery whatever the real level.

17:22:46.405 → Niveau de batterie: 3%

17:25:31.380 → Niveau de batterie: 3%

17:25:46.382 → Niveau de batterie: 3%

17:26:02.599 → Niveau de batterie: 3%

17:26:16.425 → Niveau de batterie: 3%

#include <Arduino.h>

void setup() {

void loop() {
  // Lire le niveau de batterie
  int batteryLevel = api.system.bat.get();

  // Afficher le niveau de batterie
  Serial.print("Niveau de batterie: ");

  // Attendre quelques secondes avant la prochaine lecture

Nobody reads the documentation api.system.bat.get

It is a float value, not an integer
It is not percentage, it is voltage

1 Like

hello, I have to say in my defense that I started from nothing three months ago and that I read several tons of documentation and that one escaped me :grin: :grin: :grin:, thank you for your help, I will test that, then there will come a another question how to display the result in %

I get between 3.7v and 3.8v if I disconnect the battery I have 3.0v we might believe that it works, my module communicates with a USB to TTL, I disconnected the + from the USB so I fall back to 3.0v?

13:30:42.417 → Battery Level: 3.700000

13:30:47.380 → Battery Level: 3.800000

13:30:52.380 → Battery Level: 3.800000

13:30:57.383 → Battery Level: 3.000000

13:31:02.384 → Battery Level: 3.000000

13:31:07.409 → Battery Level: 3.700000

13:31:12.424 → Battery Level: 3.700000

What do you measure on VBat with a multimeter?
I don’t know the charger chip you are using, but 3V seems low.

more seriously, I measure 3.9v at the terminal of my battery,my charger is: MCP73831T-5ACI/OT .

3.9V with the battery connected or disconnected?

3.9v the rak 3172 connected to the battery and 4.2 if I connect with USB TTL

And what are you measuring in both cases on the ADC1 pin?

I do not have such a setup with unregulated supply voltage. It is difficult to verify what’s happening.

then battery only 2.20v usb only 2.40v and both 2.40v

I think the problem might be related to “ADC voltage reference for RAK3172 and RAK3172-SiP is fixed to VDD voltage.”

You are measuring VDD, but the reference voltage is VDD as well. So the measurement does not really work because your reference voltage is changing together with the voltage you are measuring.

Unfortunately I have no solution for this. VRef is tight internally inside the RAK3172.

sorry I didn’t understand, do you mean that it is not possible to read the voltage?

The ADC reads the external voltage and compares it to a reference voltage, that gives you an value that is converted to the measured voltage.

In your case both the measured voltage and the reference voltage are the same, so the comparison does not work. When tbe battery voltage goes up or down, your reference voltage goes up or down as well.

It is a problem with the WisDuo modules when you supply from an unregulated voltage.

so on battery impossible to read the voltage? Is there another way to get around the problem?

The only possibility I see is to use a voltage regulator and supply with a regulated 3.3V.