From 3bedd4abb18f6d459af5c0225575046376c996fa Mon Sep 17 00:00:00 2001 From: caternuson Date: Sun, 21 Jan 2018 13:37:12 -0800 Subject: [PATCH] added examples --- examples/onewire_demo.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/onewire_demo.py diff --git a/examples/onewire_demo.py b/examples/onewire_demo.py new file mode 100644 index 0000000..7b658dd --- /dev/null +++ b/examples/onewire_demo.py @@ -0,0 +1,31 @@ +import board +from adafruit_onewire.bus import OneWireBus + +# Create the 1-Wire Bus +# Use whatever pin you've connected to on your board +ow_bus = OneWireBus(board.D2) + +# Reset and check for presence pulse. +# This is basically - "is there anything out there?" +print("Resetting bus...", end='') +if ow_bus.reset(): + print("OK.") +else: + raise RuntimeError("Nothing found on bus.") + +# Run a scan to get all of the device ROM values +print("Scanning for devices...", end='') +devices = ow_bus.scan() +print("OK.") +print("Found {} device(s).".format(len(devices))) + +# For each device found, print out some info +for i, d in enumerate(devices): + print("Device {:>3}".format(i)) + print("\tSerial Number = ", end='') + for byte in d.serial_number: + print("0x{:02x} ".format(byte), end='') + print("\n\tFamily = 0x{:02x}".format(d.family_code)) + +# Usage beyond this is device specific. See a CircuitPython library for a 1-Wire +# device for examples and how OneWireDevice is used.