Skip to content

Commit f3ab5b0

Browse files
authored
Merge pull request #3 from caternuson/master
added examples
2 parents bb71e82 + 3bedd4a commit f3ab5b0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/onewire_demo.py

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

0 commit comments

Comments
 (0)