Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
micropython class for reading temperature using DS18B20
import machine, onewire, ds18x20, time
class DS18B20:
def __init__(self, ds_pin: int = 4):
self.ds_pin = machine.Pin(ds_pin, machine.Pin.IN)
self.ds_sensor = ds18x20.DS18X20(onewire.OneWire(self.ds_pin))
def read_temperature(self, verbose: bool = False) -> float:
if verbose == True:
elif verbose == False:
for rom in self.roms:
return self.ds_sensor.read_temp(rom)
def scan_sensor(self, verbose: bool = False) -> None:
self.roms = self.ds_sensor.scan()
if verbose == True:
print("Found DS devices: ", self.roms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment