-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Effective temperature reading from multiple sensors
- Loading branch information
Showing
4 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import time | ||
from digitemp.master import UART_Adapter | ||
from digitemp.device import TemperatureSensor | ||
from digitemp.exceptions import OneWireException | ||
|
||
bus = UART_Adapter('/dev/ttyS0') | ||
|
||
sensors = [] | ||
for rom in bus.get_connected_ROMs(): | ||
try: | ||
sensors.append(TemperatureSensor(bus, rom)) | ||
except OneWireException: | ||
pass | ||
|
||
print(55 * "=") | ||
for sensor in sensors: | ||
sensor.info() | ||
print(55 * "=") | ||
|
||
# Instead of calling sensor.get_temperature() for each sensor we call bus.measure_temperature_all() once | ||
# and then do sensor.read_temperature() for each sensor. | ||
|
||
try: | ||
while True: | ||
measurements = [] | ||
bus.measure_temperature_all() | ||
for sensor in sensors: | ||
try: | ||
measurements.append("%3.02fºC" % sensor.read_temperature()) | ||
except OneWireException: | ||
measurements.append(" error") | ||
print(" ".join(measurements)) | ||
time.sleep(3) | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
bus.close() |