1.. zephyr:code-sample:: adc_dt 2 :name: Analog-to-Digital Converter (ADC) with devicetree 3 :relevant-api: adc_interface 4 5 Read analog inputs from ADC channels. 6 7Overview 8******** 9 10This sample demonstrates how to use the :ref:`ADC driver API <adc_api>`. 11 12Depending on the target board, it reads ADC samples from one or more channels 13and prints the readings on the console. If voltage of the used reference can 14be obtained, the raw readings are converted to millivolts. 15 16The pins of the ADC channels are board-specific. Please refer to the board 17or MCU datasheet for further details. 18 19Building and Running 20******************** 21 22The ADC peripheral and pinmux is configured in the board's ``.dts`` file. Make 23sure that the ADC is enabled (``status = "okay";``). 24 25In addition to that, this sample requires an ADC channel specified in the 26``io-channels`` property of the ``zephyr,user`` node. This is usually done with 27a devicetree overlay. The example overlay in the ``boards`` subdirectory for 28the ``nucleo_l073rz`` board can be easily adjusted for other boards. 29 30Configuration of channels (settings like gain, reference, or acquisition time) 31also needs to be specified in devicetree, in ADC controller child nodes. Also 32the ADC resolution and oversampling setting (if used) need to be specified 33there. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay 34<samples/drivers/adc/adc_dt/boards/nrf52840dk_nrf52840.overlay>` for an example of 35such setup. 36 37Building and Running for ST Nucleo L073RZ 38========================================= 39 40The sample can be built and executed for the 41:zephyr:board:`nucleo_l073rz` as follows: 42 43.. zephyr-app-commands:: 44 :zephyr-app: samples/drivers/adc/adc_dt 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: 60 - ADC_0, channel 7: 36 = 65mV 61 62.. note:: If the ADC is not supported, the output will be an error message. 63