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