Simple test

Ensure your device works with this simple test.

examples/ds248x_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5"""Adafruit DS248x DS18B20 Example"""
 6
 7import time
 8
 9import board
10
11from adafruit_ds248x import Adafruit_DS248x
12
13# Initialize I2C bus and DS248x
14i2c = board.I2C()
15ds248x = Adafruit_DS248x(i2c)
16
17rom = bytearray(8)
18if not ds248x.onewire_search(rom):
19    print("No more devices found\n\n")
20
21print("Found device ROM: ", end="")
22for byte in rom:
23    print(f"{byte:02X} ", end="")
24print()
25while True:
26    temperature = ds248x.ds18b20_temperature(rom)
27    print(f"Temperature: {temperature:.2f} °C")
28
29    time.sleep(1)

DS2482S-800 8-Channel example

Read all 8 channels from the DS2482S-800

examples/ds2482s-800_8-channel_test.py
 1# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5"""Adafruit DS2482S-800 8-Channel DS18B20 Example"""
 6
 7import time
 8
 9import board
10
11from adafruit_ds248x import Adafruit_DS248x
12
13# Initialize I2C bus and DS248x
14i2c = board.STEMMA_I2C()
15ds248x = Adafruit_DS248x(i2c)
16
17while True:
18    for i in range(8):
19        ds248x.channel = i
20        print(f"Reading channel {ds248x.channel}")
21        temperature = ds248x.ds18b20_temperature()
22        print(f"Temperature: {temperature:.2f} °C")
23        print()
24        time.sleep(1)