|
| 1 | +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +# Example of specifying multiple sensors using explicit ROM codes. |
| 5 | +# These ROM codes need to be determined ahead of time. Use `ow_bus.scan()`. |
| 6 | +# |
| 7 | +# (1) Connect one sensor at a time |
| 8 | +# (2) Use `ow_bus.scan()[0].rom` to determine ROM code |
| 9 | +# (3) Use ROM code to specify sensors (see this example) |
| 10 | + |
| 11 | +import time |
| 12 | +import board |
| 13 | +from adafruit_onewire.bus import OneWireBus, OneWireAddress |
| 14 | +from adafruit_ds18x20 import DS18X20 |
| 15 | + |
| 16 | +# !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!! |
| 17 | +ROM1 = b"(\xbb\xfcv\x08\x00\x00\xe2" |
| 18 | +ROM2 = b"(\xb3t\xd3\x08\x00\x00\x9e" |
| 19 | +ROM3 = b"(8`\xd4\x08\x00\x00i" |
| 20 | +# !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!! |
| 21 | + |
| 22 | +# Initialize one-wire bus on board pin D5. |
| 23 | +ow_bus = OneWireBus(board.D5) |
| 24 | + |
| 25 | +# Uncomment this to get a listing of currently attached ROMs |
| 26 | +# for device in ow_bus.scan(): |
| 27 | +# print(device.rom) |
| 28 | + |
| 29 | +# Use pre-determined ROM codes for each sensors |
| 30 | +temp1 = DS18X20(ow_bus, OneWireAddress(ROM1)) |
| 31 | +temp2 = DS18X20(ow_bus, OneWireAddress(ROM2)) |
| 32 | +temp3 = DS18X20(ow_bus, OneWireAddress(ROM3)) |
| 33 | + |
| 34 | +# Main loop to print the temperatures every second. |
| 35 | +while True: |
| 36 | + print("Temperature 1 = {}".format(temp1.temperature)) |
| 37 | + print("Temperature 2 = {}".format(temp2.temperature)) |
| 38 | + print("Temperature 3 = {}".format(temp3.temperature)) |
| 39 | + print("-" * 20) |
| 40 | + time.sleep(1) |
0 commit comments