import machine #pour accéder aux GPIOs
import onewire, ds18x20 #pour lire la sonde 1-wire
import time
dat = machine.Pin(12)
ds = ds18x20.DS18X20(onewire.OneWire(dat)) #On crée l'objet OneWire
roms = ds.scan() #On scanne le bus pour trouver toutes les sondes
print('found devices:', roms)
# (°F - 32) x 5/9 = °C or in plain english, First subtract 32, then multiply by 5,
# (°C × 9/5) + 32 = °F or in plain English, Multiple by 9, then divide by 5, then add 32.
# loop 10 times and print all temperatures
for i in range(10):
print('temperatures:', end=' ')
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
degreeF=ds.read_temp(rom)
degreeC=(degreeF-32)*5/9
print(degreeF,'F', degreeC ,'C', end=' ')
print()
alex@alex-PC MINGW64 /d/mini3/onewire
$ ampy --port COM13 run DS1820.py
found devices: [bytearray(b'(\xff\xe0\x88\x90\x15\x04\r')]
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
temperatures: 85.0 F 29.44444 C
alex@alex-PC MINGW64 /d/mini3/onewire
$
沒有留言:
張貼留言