From 3ce44b4576739a7e36c8d3eab70833f31c4b5a12 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 21 Sep 2021 10:00:38 -0700 Subject: [PATCH 1/3] add multi sensor example --- examples/ds18x20_multi.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/ds18x20_multi.py diff --git a/examples/ds18x20_multi.py b/examples/ds18x20_multi.py new file mode 100644 index 0000000..eaf55ea --- /dev/null +++ b/examples/ds18x20_multi.py @@ -0,0 +1,33 @@ +# Example of specifying multiple sensors using explicit ROM codes. +# These ROM codes need to be determined ahead of time. Use `ow_bus.scan()`. +# +# (1) Connect one sensor at a time +# (2) Use `ow_bus.scan()` to determine ROM code +# (3) Use ROM code to specify sensors + +import time +import board +from adafruit_onewire.bus import OneWireBus, OneWireAddress +from adafruit_ds18x20 import DS18X20 + +# !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!! +ROM1 = b"(\xbb\xfcv\x08\x00\x00\xe2" +ROM2 = b"(\xb3t\xd3\x08\x00\x00\x9e" +ROM3 = b"(8`\xd4\x08\x00\x00i" +# !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!! + +# Initialize one-wire bus on board pin D5. +ow_bus = OneWireBus(board.D5) + +# Use pre-determined ROM codes for each sensors +temp1 = DS18X20(ow_bus, OneWireAddress(ROM1)) +temp2 = DS18X20(ow_bus, OneWireAddress(ROM2)) +temp3 = DS18X20(ow_bus, OneWireAddress(ROM3)) + +# Main loop to print the temperatures every second. +while True: + print("Temperature 1 = {}".format(temp1.temperature)) + print("Temperature 2 = {}".format(temp2.temperature)) + print("Temperature 3 = {}".format(temp3.temperature)) + print("-" * 20) + time.sleep(1) From 6646259e3026610ad8b0ed695f33e4d641151069 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 21 Sep 2021 10:05:39 -0700 Subject: [PATCH 2/3] dox tweak --- examples/ds18x20_multi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ds18x20_multi.py b/examples/ds18x20_multi.py index eaf55ea..8a6a0cd 100644 --- a/examples/ds18x20_multi.py +++ b/examples/ds18x20_multi.py @@ -2,8 +2,8 @@ # These ROM codes need to be determined ahead of time. Use `ow_bus.scan()`. # # (1) Connect one sensor at a time -# (2) Use `ow_bus.scan()` to determine ROM code -# (3) Use ROM code to specify sensors +# (2) Use `ow_bus.scan()[0].rom` to determine ROM code +# (3) Use ROM code to specify sensors (see this example) import time import board From ab0bc4746c1d2980ac95abd03394536a9aafa4ce Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 21 Sep 2021 10:56:38 -0700 Subject: [PATCH 3/3] super happy ci fun time --- .pre-commit-config.yaml | 2 +- examples/ds18x20_multi.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system diff --git a/examples/ds18x20_multi.py b/examples/ds18x20_multi.py index 8a6a0cd..3c2dda1 100644 --- a/examples/ds18x20_multi.py +++ b/examples/ds18x20_multi.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + # Example of specifying multiple sensors using explicit ROM codes. # These ROM codes need to be determined ahead of time. Use `ow_bus.scan()`. # @@ -19,6 +22,10 @@ # Initialize one-wire bus on board pin D5. ow_bus = OneWireBus(board.D5) +# Uncomment this to get a listing of currently attached ROMs +# for device in ow_bus.scan(): +# print(device.rom) + # Use pre-determined ROM codes for each sensors temp1 = DS18X20(ow_bus, OneWireAddress(ROM1)) temp2 = DS18X20(ow_bus, OneWireAddress(ROM2))