zephyr/samples/drivers/adc
Andrzej Głąbek 07b4362bac samples/drivers/adc: Add support for nRF52840 DK and nRF51 DK boards
The overlay for the nRF52840 DK board uses ADC controller child nodes
for specifying channel configurations and it shows how to configure
a channel in differential input mode, so it can serve as an example
of how to use these new possibilities. The overlay for the nRF51 DK
board shows how to use a specific ADC resolution (the default 12 bit
setting is not supported by nRF51 SoCs).

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2022-05-13 12:46:06 -07:00
..
boards samples/drivers/adc: Add support for nRF52840 DK and nRF51 DK boards 2022-05-13 12:46:06 -07:00
src samples/drivers/adc: Rework to use channel configurations from DT 2022-05-13 12:46:06 -07:00
CMakeLists.txt cmake: increase minimal required version to 3.20.0 2021-08-20 09:47:34 +02:00
prj.conf
README.rst samples/drivers/adc: Rework to use channel configurations from DT 2022-05-13 12:46:06 -07:00
sample.yaml samples/drivers/adc: Add support for nRF52840 DK and nRF51 DK boards 2022-05-13 12:46:06 -07:00

.. _adc-sample:

Analog-to-Digital Converter (ADC)
#################################

Overview
********

This sample demonstrates how to use the ADC driver API.

Depending on the target board, it reads ADC samples from one or more channels
and prints the readings on the console. If voltage of the used reference can
be obtained, the raw readings are converted to millivolts.

The pins of the ADC channels are board-specific. Please refer to the board
or MCU datasheet for further details.

Building and Running
********************

The ADC peripheral and pinmux is configured in the board's ``.dts`` file. Make
sure that the ADC is enabled (``status = "okay";``).

In addition to that, this sample requires an ADC channel specified in the
``io-channels`` property of the ``zephyr,user`` node. This is usually done with
a devicetree overlay. The example overlay in the ``boards`` subdirectory for
the ``nucleo_l073rz`` board can be easily adjusted for other boards.

Configuration of channels (settings like gain, reference, or acquisition time)
can be specified in devicetree, in ADC controller child nodes. Also the ADC
resolution and oversampling setting to be used for particular channels can
be specified there. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay
<samples/drivers/adc/boards/nrf52840dk_nrf52840.overlay>` for an example of
such setup. If these parameters are not specified in devicetree, default values,
supposed to be supported by most ADCs, are used instead.

Building and Running for ST Nucleo L073RZ
=========================================

The sample can be built and executed for the
:ref:`nucleo_l073rz_board` as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/adc
   :board: nucleo_l073rz
   :goals: build flash
   :compact:

To build for another board, change "nucleo_l073rz" above to that board's name
and provide a corresponding devicetree overlay.

Sample output
=============

You should get a similar output as below, repeated every second:

.. code-block:: console

   ADC reading(s): 42 (raw)

.. note:: If the ADC is not supported, the output will be an error message.