Skip to content

added examples #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/onewire_demo.py
Original file line number Diff line number Diff line change
@@ -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.