insert new file testing with ds18b20 temperature sensor
This commit is contained in:
parent
c21de176ca
commit
c617b06bd4
19
Scripts/temperature-sensor.py
Normal file
19
Scripts/temperature-sensor.py
Normal file
@ -0,0 +1,19 @@
|
||||
import machine, onewire, ds18x20, time
|
||||
|
||||
ds_pin = machine.Pin(22)
|
||||
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
|
||||
|
||||
roms = ds_sensor.scan()
|
||||
print('Found DS devices: ', roms)
|
||||
|
||||
while True:
|
||||
ds_sensor.convert_temp()
|
||||
time.sleep_ms(750)
|
||||
for rom in roms:
|
||||
print(rom)
|
||||
tempC = ds_sensor.read_temp(rom)
|
||||
tempF = tempC * (9/5) +32
|
||||
print('temperature (ºC):', "{:.2f}".format(tempC))
|
||||
print('temperature (ºF):', "{:.2f}".format(tempF))
|
||||
print()
|
||||
time.sleep(5)
|
||||
Loading…
x
Reference in New Issue
Block a user