Skip to content

Instantly share code, notes, and snippets.

@Elwell
Created February 21, 2024 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elwell/87a94ba4b3390fbb0761adcca8a9aacb to your computer and use it in GitHub Desktop.
Save Elwell/87a94ba4b3390fbb0761adcca8a9aacb to your computer and use it in GitHub Desktop.
1-Wire bulk read
#!/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