RAK3172 ADC Functionality

Hi,

We wish to measure battery voltage with ADC.

We are using RAK3172 module + RUI3

Here we try to set internal reference voltage of ADC to the 1.8V or 2.4V by using functions
udrv_adc_set_mode(UDRV_ADC_MODE_1_8);

OR

analogReference(AR_INTERNAL_1_8).;

When we read ADC mode back with function “udrv_adc_get_mode()” it gives UDRV_ADC_MODE_3_3 (ie. Mode value - 1)
It seems that internal voltage is not getting set to the desired voltage level.

Please guide us to resolve this issue.

-Madhav

Hi @UsernameMadhavML ,

The internal reference of RAK3172 can’t be changed an fixed to VDD level. We have to update the docs to indicate this as added note :spiral_notepad: :pushpin:

Hi @carlrowan

Thank you for update.
I think it should get reflected in library files also. So that it will not be selected by the developer if RAK3172 board is selected.

Hi @carlrowan,

So if you want to accurately measure the analog value you are better of using an external Vref connected on a ADC channel and then compensate for the unknown Vin ??

Hi @carlrowan , I have also a question about the ADC. iam trying to read the battery voltage. Iam using a voltage divider of 1M and 1.5M ohm as recommended. So my max voltage on the ADC pin is 2.29V when iam using a 3.6V battery. But when i change the value on the ADC pin the analog value is not changing. Iam using ADC2 → WB-A1 for reading. When i turn the power supply voltage to 2.3V its still the same value as before… Really strange. Do you have some suggestion what the problem would be?

image

void setup() {
Serial.begin(115200);

//analogReference(AR_INTERNAL_2_4);
analogReadResolution(12);
}

void loop() {
float raw_adc = analogRead(WB_A1);
Serial.println(raw_adc);
//Serial.println(batV1);
 Serial.printf("Voltage value = %f V\r\n", 3.0*(((float)raw_adc)/4096)*(5.0f)/(3.0f));
delay(5000);
}

Kind regards Marnick

@NAS1975 ,

Having external voltage rerference for the module will not the improve accuracy on the built-in ADC. If can have fixed VDD level on RAK3172, you can use its ADC (vdd as reference) else it might be worth considering to check for an externa one or use RAK4631 (with programmable ADC reference.)

Hi @Marnick The Vref of RAK3172 is based on Vdd, if you lower your vdd, it will just follow the raw reading.

Your signal of interest must be lower than Vdd. If the signal you want to check is 2.29V, your vdd (for rak3172) must be above it.

Hello @carlrowan ,
My vdd is a battery (3.6V max). So when the battery is getting empty the Vref is getting lower. That means that i cant make a battery measurement?

Yes. That is correct. We are looking if there are ways for us to implement internal voltage monitoring.

For now, to do monitoring continuously the battery voltage even if it drops 3.3v, you might need extra hardware.

  1. Use boost converter to maintain 3.3V.
  2. Use ultra low power ADC or comparator that can indicate low battery threshold voltage.
1 Like

This is an enlightening discussion. Thank you both.

Where I am having difficulty is how to read from A0 when using RAK5811 mounted on a RAK19001/RAK11310 device.

The published example, RAK5811_0-5V.ino, I think shows how to read from A1 and I have been able to calibrate voltage_sensor so that it approximates the actual voltage being input from a variable power supply.

How does one read from A0? Would very much like to understand that. Pointers to documentation on this subject would be appreciated too.

Thank you for your input.

Hi @SoothingMist ,

AIN0 of RAK5811 is connected to pin32 of WisBlock connector which correspond to WisBlock IO4. On RAK11310’s RP2040 , this is GPIO 28.

So you can use either,

analogRead(WB_IO4) or analogRead(28)

Carl… My thanks for your patience but I am even more confused now than ever. The example provided with RAK5811 for this hardware combination refers to WB_A1 but seems to not actually read from there. Someone with my background would assume WB_A0 for the other input so that one is reading from A0 and A1 on the RAK5811. These refer to pins 26 and 27, according to pins_arduino.h.

A thought on the orientation of two customer groups: The first group is deep into electronics and so can easily understand schematics. The second group is deep into software and looks for documented application programmer interfaces. Microcontrollers and their applications do require basic knowledge of electronics. However, the second group does not have deep knowledge in that arena. My own talent is in building logical constructs that computers can carry out.

I really think the example provided for the RAK5811 should be modified so that it clearly refers to A0 and A1.

If RAKwireless wants to undertake the suggested modification, I am glad to volunteer as a tester and discussant.

This conversation came to an excellent conclusion. See the conversation at this thread.