File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Example of specifying multiple sensors using explicit ROM codes.
2
+ # These ROM codes need to be determined ahead of time. Use `ow_bus.scan()`.
3
+ #
4
+ # (1) Connect one sensor at a time
5
+ # (2) Use `ow_bus.scan()` to determine ROM code
6
+ # (3) Use ROM code to specify sensors
7
+
8
+ import time
9
+ import board
10
+ from adafruit_onewire .bus import OneWireBus , OneWireAddress
11
+ from adafruit_ds18x20 import DS18X20
12
+
13
+ # !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!!
14
+ ROM1 = b"(\xbb \xfc v\x08 \x00 \x00 \xe2 "
15
+ ROM2 = b"(\xb3 t\xd3 \x08 \x00 \x00 \x9e "
16
+ ROM3 = b"(8`\xd4 \x08 \x00 \x00 i"
17
+ # !!!! REPLACE THESE WITH ROM CODES FOR YOUR SENSORS !!!!
18
+
19
+ # Initialize one-wire bus on board pin D5.
20
+ ow_bus = OneWireBus (board .D5 )
21
+
22
+ # Use pre-determined ROM codes for each sensors
23
+ temp1 = DS18X20 (ow_bus , OneWireAddress (ROM1 ))
24
+ temp2 = DS18X20 (ow_bus , OneWireAddress (ROM2 ))
25
+ temp3 = DS18X20 (ow_bus , OneWireAddress (ROM3 ))
26
+
27
+ # Main loop to print the temperatures every second.
28
+ while True :
29
+ print ("Temperature 1 = {}" .format (temp1 .temperature ))
30
+ print ("Temperature 2 = {}" .format (temp2 .temperature ))
31
+ print ("Temperature 3 = {}" .format (temp3 .temperature ))
32
+ print ("-" * 20 )
33
+ time .sleep (1 )
You can’t perform that action at this time.
0 commit comments