/ examples / onewire_simpletest.py
onewire_simpletest.py
 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.