Skip to content

Instantly share code, notes, and snippets.

@eydam-prototyping
Created February 16, 2021 15:46
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 eydam-prototyping/071e6044d80f4842317d84d89c4b5f5a to your computer and use it in GitHub Desktop.
Save eydam-prototyping/071e6044d80f4842317d84d89c4b5f5a to your computer and use it in GitHub Desktop.
>>> import onewire
>>> import ds18x20
>>> import machine
>>> ow = onewire.OneWire(machine.Pin(4)) # Bus initialisieren auf GPIO4
>>> ds = ds18x20.DS18X20(ow)
>>> roms = ds.scan() # nach angeschlossenen Slaves suchen
>>> roms
[bytearray(b'(!a\x85\x13\x19\x01\xb5')] # Liste mit Slaves, hier nur einer
>>> import ubinascii
>>> ubinascii.hexlify(roms[0]) # die Seriennummer lesbar
b'28216185131901b5'
>>> ds.convert_temp() # allen angeschlossenen Slaves den Befehl zum messen geben
>>> ds.read_temp(roms[0]) # Temperatur auslesen
22.625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment