• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

boards/11-Mar-2024-140118

src/11-Mar-2024-12380

CMakeLists.txtD11-Mar-2024177 95

README.rstD11-Mar-20241.8 KiB6241

prj.confD11-Mar-202413 21

sample.yamlD11-Mar-2024329 1514

README.rst

1.. _adc-sample:
2
3Analog-to-Digital Converter (ADC)
4#################################
5
6Overview
7********
8
9This sample demonstrates how to use the ADC driver API.
10
11Depending on the MCU type, it reads the ADC samples of one or two ADC channels
12and prints the readings to the console. If supported by the driver, the raw
13readings are converted to millivolts.
14
15The pins of the ADC channels are board-specific. Please refer to the board
16or MCU datasheet for further details.
17
18.. note::
19
20   This sample does not work on Nordic platforms where there is a distinction
21   between channel and analog input that requires additional configuration. See
22   :zephyr_file:`samples/boards/nrf/battery` for an example of using the ADC
23   infrastructure on Nordic hardware.
24
25
26Building and Running
27********************
28
29The ADC peripheral and pinmux is configured in the board's ``.dts`` file. Make
30sure that the ADC is enabled (``status = "okay";``).
31
32In addition to that, this sample requires an ADC channel specified in the
33``io-channels`` property of the ``zephyr,user`` node. This is usually done with
34a devicetree overlay. The example overlay in the ``boards`` subdirectory for
35the :ref:`nucleo_l073rz_board` can be easily adjusted for other boards.
36
37Building and Running for ST Nucleo L073RZ
38=========================================
39
40The sample can be built and executed for the
41:ref:`nucleo_l073rz_board` as follows:
42
43.. zephyr-app-commands::
44   :zephyr-app: samples/drivers/adc
45   :board: nucleo_l073rz
46   :goals: build flash
47   :compact:
48
49To build for another board, change "nucleo_l073rz" above to that board's name
50and provide a corresponding devicetree overlay.
51
52Sample output
53=============
54
55You should get a similar output as below, repeated every second:
56
57.. code-block:: console
58
59   ADC reading(s): 42 (raw)
60
61.. note:: If the ADC is not supported, the output will be an error message.
62