:mod:`ds18b20` --- communicate with DS18B20 via UART/1-Wire =========================================================== .. module:: ds18b20 :synopsis: communicate with DS18B20 temperature sensor via UART/1-Wire This module provides control fo the Maxim DS18B20 temperature sensor provided it uses 3-wire scheme (with separate VCC pin) class DS18B20 ------------- The DS18B20 class provides an interace to the Maxim temperature sensor. Create an instance of this class to measure and read the temperature and control the sensor resolution. Connection: Pin1 (GND) to ground, Pin2 (DQ) to the UART_TX pin, Pin3 (Vdd) to 3.3/5V Usage example:: import ds18b20 import pyb ds = ds18b20.DS18B20(pyb.UART(1)) ds.measure() pyb.delay(1000) ds.temperature() Constructors ------------ .. class:: DS18B20(uart) Construct an DS18B20 object. The only parameter is the UART instance (ds18b20 DQ pin *must* be connected to UART TX pin) Instance members ---------------- The following instance members are publicly accessible. .. data:: DS18B20.resolution The resolution (9-12bits) of the connected sensor. The value is valid only after a successfull ``temperature()`` read. Setup commands -------------- .. method:: DS18B20.reset() Reset the device. Normally you do not need to call this function manually - all other member functions call it anyway. Return value: ``True`` if the device responded with a presence pulse, ``False`` othrewise .. method:: DS18B20.set_resulution(value) Set the resolution. ``value`` must be in the range of [9-12]. Fallback is 9. Return value: boolean (operation success) Measurement ----------- .. method:: DS18B20.measure() Request a temperature measurement. See `the datasheet `_ (484KiB PDF) for how long a single measurement takes. The function return immediately, i.e. to read the temperature user has to call, for example, ``pyb.delay(value)``. Return value: boolean (operation success) .. method:: DS18B20.temperature() Read and return the last measured temperature. Return value: temperature (float) or ``None``.