.. module:: ds18x20 :synopsis: DS18B20 temperature sensor driver :mod:`ds18x20` --- DS18B20 temperature sensor driver ==================================================== The one wire bus is a serial bus that uses only a single wire for communication (in addition to the wires for ground and power). The DS18B20 temperature sensor is a very popular single-wire device, featuring a small size, low hardware overhead, strong anti-interference ability, and high accuracy. -------------------------------------------------- | | .. image:: /_static/external/DS18B20-500x500-800x800.jpg :width: 200 .. note:: The image must be viewed online: `ds18b20-module.png `__ .. image:: /_static/external/cebe2df9-a7d2-4f28-8477-9fd5ffc0ab46.jpg :width: 200 - Unique onewire (single-bus) interface: when connecting to a microprocessor, the DS18B20 needs only one port line to achieve two-way communication between the microprocessor and the DS18B20. - Temperature measurement range: -55℃~+125℃, - Supports multi-point networking: multiple DS18B20 devices can be connected in parallel on the only three wires, up to 8 in parallel, to achieve multi-point temperature measurement. If there are too many, the supply voltage will be too low, causing unstable signal transmission. - Operating power: 3.0~5.5V/DC | | .. figure:: /_static/products/ledong-v2/_static/image/tutorials/ds18x20_res.jpeg :width: 300 :align: center If you are using a single ds18b20 device, to ensure stable data transmission, the signal OUT pin needs a 4.7K pull-up resistor. -------------------------------------------- DS18X20 Class ------------- .. class:: DS18X20(onewire) Construct the DS18X20 class. - ``onewire`` - The one wire instance object .. method:: DS18X20.scan() Scan the ds18b20 devices on the single bus and return a list of device addresses. .. method:: DS18X20.convert_temp() Read the sampled temperature and perform the temperature unit conversion. .. method:: DS18X20.read_temp(rom) Return the temperature value of the device. Note that after converting the temperature with ``convert_temp()``, you must wait at least 750 milliseconds before reading the temperature value. - ``rom`` - The device address .. literalinclude:: /_static/products/ledong-v2/_static/examples/onewire/ds18b20.py :caption: Example - ds18b20 :linenos: