Hello,
NCS1.9.1, nRF52840DK, Windows10 X64, VS Code,
1.
i want to read voltage from RT_ADC pin (P0.04),
and than converting NTC thermistor value to Temperature.
2.
read battery Voltage;
is there any sample code?
thanks
Best Regards
Hello,
NCS1.9.1, nRF52840DK, Windows10 X64, VS Code,
1.
i want to read voltage from RT_ADC pin (P0.04),
and than converting NTC thermistor value to Temperature.
2.
read battery Voltage;
is there any sample code?
thanks
Best Regards
Hi,
You can find general ADC sample and battery voltage sample in Zephyr:
There is also an un-official example in this GitHub repository. This is written for the nRF9160, but it should work for the SAADC in nRF52 devices as well.
Best regards,
Jørgen
Hi,
It is explained in the Battery sample documentation how to create a vbatt node without voltage divider, for measuring VDD directly. The input_positive will then be set to VDD. I tested this by adding the following to a "nrf52840dk_nrf52840.overlay" file in the sample directory:
/ {
zephyr,user {
io-channels = <&adc 4>;
};
};
You can use the same overlay file in the ADC sample, then set the AIN2 pin in the code.
In the last GitHub sample, the pin is set in the code as well. CONFIG_ADC_CONFIGURABLE_INPUTS is automatically selected for NRF devices.
Best regards,
Jørgen
Hello,
thanks for reply,
your two project, see zip. i've not change code.
i've add io-channels = <&adc 4>;
but build error
devicetree.h:81:17: error: 'DT_N_S_zephyr_user_P_io_channels_IDX_0_VAL_input' undeclared
Best regards,
Make sure that you run a pristine build, or remove the build folder after adding the overlay file, if not, the new devicetree configs may not be detected.
Your overlay looks exactly like the one I used, which works fine.
I also tested building your application, and I'm not seeing any errors.
Hi,
delete it and add build, and change to pin P0.04

got Voltage:

how to converting 181mV value to Temperature?
Best regards,
Hi,
You also got the raw SAADC sample value (1240). How to convert this to temperature depends on your sensor, you should check the datasheet. The resolution of the SAADC is 12 bit by defaults, so you the raw samples will go from 0-4095.
Best regards,
Jørgen
Hi,
You also got the raw SAADC sample value (1240). How to convert this to temperature depends on your sensor, you should check the datasheet. The resolution of the SAADC is 12 bit by defaults, so you the raw samples will go from 0-4095.
Best regards,
Jørgen