adafruit_ds18x20

Driver for Dallas 1-Wire temperature sensor.

  • Author(s): Carter Nelson

Software and Dependencies:

class adafruit_ds18x20.DS18X20(bus: adafruit_onewire.bus.OneWireBus, address: int)[source]

Class which provides interface to DS18X20 temperature sensor

Parameters:
  • bus – The bus the DS18X20 is connected to

  • address (int) – The device address.

Quickstart: Importing and using the device

Here is an example of using the DS18X20 class. First you will need to import the libraries to use the sensor

import board
from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

Once this is done you can define your adafruit_onewire.bus.OneWireBus object and define your sensor object

ow_bus = OneWireBus(board.D5)
ds18 = DS18X20(ow_bus, ow_bus.scan()[0])

Now you have access to the temperature attribute

temperature = ds18.temperature
property address

The address of the device. Useful if there are multiple sensors on the bus.

Note: this property is read only.

read_temperature() float[source]

Read the temperature. No polling of the conversion busy bit (assumes that the conversion has completed).

property resolution: Literal[9, 10, 11, 12]

The programmable resolution. 9, 10, 11, or 12 bits.

start_temperature_read() float[source]

Start asynchronous conversion, returns immediately. Returns maximum conversion delay [seconds] based on resolution.

property temperature

The temperature in degrees Celsius.