Skip to content

Commit 8a674ca

Browse files
committed
working demo! tested w/two sensors
1 parent 5826898 commit 8a674ca

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

main.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
ow = OneWire.OneWire(board.D2)
77
ds18 = ds18x20.DS18X20(ow)
88

9-
print("Resetting!",ow.reset())
9+
def pretty_address(addr):
10+
return ''.join('{:02x}'.format(x) for x in addr)
11+
12+
print("Resetting, found anything?",ow.reset())
1013

1114
print("Found the following 1-Wire devices: ", end="")
1215
for dev in ow.scan():
13-
address = ''.join('{:02x}'.format(x) for x in dev)
14-
print(address)
15-
16-
print("Found the following DS18x20 devices: ", end="")
17-
for dev in ds18.scan():
18-
address = ''.join('{:02x}'.format(x) for x in dev)
19-
print(address)
16+
print(pretty_address(dev))
17+
print("")
2018

2119
while True:
20+
print("Found the following DS18x20 devices")
2221
for dev in ds18.scan():
23-
print(ds18.read_temp(dev))
22+
ds18.convert_temp()
23+
time.sleep(1)
24+
print(pretty_address(dev), ":", ds18.read_temp(dev))
25+
print("--------------")
26+
time.sleep(1)

0 commit comments

Comments
 (0)