Created
February 21, 2024 11:16
-
-
Save Elwell/87a94ba4b3390fbb0761adcca8a9aacb to your computer and use it in GitHub Desktop.
1-Wire bulk read
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
#!/usr/bin/python3 | |
# bulk-read all attached 1-Wire temp sensors | |
# see https://docs.kernel.org/w1/slaves/w1_therm.html | |
bus_base = '/sys/devices/w1_bus_master1/' | |
def get_temp(addr): | |
with open(f'{bus_base}/{addr}/temperature', 'r') as t: | |
print (addr, int(t.read().strip())/1000) | |
def bulk_read(): | |
with open (bus_base + 'therm_bulk_read', 'r') as bulk: | |
trig = bulk.read().strip() | |
if trig == '1': # all temps ready to read | |
with open(bus_base + 'w1_master_slaves', 'r') as s: | |
slaves = s.read().splitlines() | |
for line in slaves: | |
if line.startswith('28-'): # temperature sensor | |
get_temp(line) | |
with open (bus_base + 'therm_bulk_read', 'w') as bulk: | |
bulk.write('trigger\n') | |
bulk_read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment