Simple test

Ensure your device works with this simple test.

examples/onewire_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5
 6from adafruit_onewire.bus import OneWireBus
 7
 8# Create the 1-Wire Bus
 9# Use whatever pin you've connected to on your board
10ow_bus = OneWireBus(board.D2)
11
12# Reset and check for presence pulse.
13# This is basically - "is there anything out there?"
14print("Resetting bus...", end="")
15if ow_bus.reset():
16    print("OK.")
17else:
18    raise RuntimeError("Nothing found on bus.")
19
20# Run a scan to get all of the device ROM values
21print("Scanning for devices...", end="")
22devices = ow_bus.scan()
23print("OK.")
24print(f"Found {len(devices)} device(s).")
25
26# For each device found, print out some info
27for i, d in enumerate(devices):
28    print(f"Device {i:>3}")
29    print("\tSerial Number = ", end="")
30    for byte in d.serial_number:
31        print(f"0x{byte:02x} ", end="")
32    print(f"\n\tFamily = 0x{d.family_code:02x}")
33
34# Usage beyond this is device specific. See a CircuitPython library for a 1-Wire
35# device for examples and how OneWireDevice is used.