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

..--

boards/04-Jan-2025-7664

src/04-Jan-2025-6744

CMakeLists.txtD04-Jan-2025224 96

README.rstD04-Jan-20252.8 KiB8259

arduino_serial.overlayD04-Jan-2025522 2924

prj.confD04-Jan-202572 64

sample.yamlD04-Jan-2025741 3029

README.rst

1.. zephyr:code-sample:: ds18b20
2   :name: DS18B20 1-Wire Temperature Sensor
3   :relevant-api: sensor_interface w1_sensor
4
5   Get ambient temperature data from a DS18B20 sensor (polling mode).
6
7Overview
8********
9
10This sample shows how to use the Zephyr :ref:`sensor` API driver for the
11`DS18B20`_ 1-Wire temperature sensor.
12
13.. _DS18B20:
14   https://www.analog.com/en/products/ds18b20.html
15
16The sample periodically reads temperature data from the
17first available DS18B20 device discovered in the system. The sample checks the
18sensor in polling mode (without interrupt trigger).
19
20Building and Running
21********************
22
23The devicetree must have an enabled node with ``compatible = "maxim,ds18b20";``.
24See below for examples and common configurations.
25
26If the sensor is not built into your board, start by wiring the sensor pins
27as shown in the Figure Hardware Configuration of the `DS18B20 datasheet`_ at
28page 10.
29
30.. _DS18B20 datasheet:
31   https://www.analog.com/media/en/technical-documentation/data-sheets/ds18b20.pdf
32
33Boards with a built-in DS18B20 or a board-specific overlay
34==========================================================
35
36Your board may have a DS18B20 node configured in its devicetree by default,
37or a board specific overlay file with an DS18B20 node is available.
38Make sure this node has ``status = "okay";``, then build and run with:
39
40.. zephyr-app-commands::
41   :zephyr-app: samples/sensor/ds18b20
42   :goals: build flash
43   :board: nucleo_g0b1re
44
45DS18B20 via Arduino Serial pins
46===============================
47
48Make sure that you have an external circuit to provide an open-drain interface
49for the 1-Wire bus.
50Once you have wired the sensor and the serial peripheral on the Arduino header
51to the 1-Wire bus, build and flash with:
52
53.. zephyr-app-commands::
54   :zephyr-app: samples/sensor/ds18b20
55   :goals: build flash
56   :gen-args: -DDTC_OVERLAY_FILE=arduino_serial.overlay
57
58The devicetree overlay :zephyr_file:`samples/sensor/ds18b20/arduino_serial.overlay`
59should work on any board with a properly configured Arduino pin-compatible Serial
60peripheral.
61
62Sample Output
63=============
64
65The sample prints output to the serial console. DS18B20 device driver messages
66are also logged. Refer to your board's documentation for information on
67connecting to its serial console.
68
69Here is example output for the default application settings, assuming that only
70one DS18B20 sensor is connected to the standard Arduino Serial pins:
71
72.. code-block:: none
73
74   *** Booting Zephyr OS build zephyr-v2.6.0-1929-gf7abe4a6689e  ***
75   Found device "DS18B20", getting sensor data
76   [00:00:00.000,039] <dbg> w1_serial: w1_serial_init: w1-serial initialized, with 1 devices
77   [00:00:00.015,140] <dbg> DS18B20: ds18b20_init: Using external power supply: 1
78   [00:00:00.021,213] <dbg> DS18B20: ds18b20_init: Init DS18B20: ROM=28b1bb3f070000b9
79
80   Temp: 25.040000
81   Temp: 25.030000
82