TPYBoard v202 | DS18B20扩展板 |
3.3V | VCC |
G4 | DO |
GND | GND |
import machine import time,onewire,ds18x20 from machine import Pin def GetTemp(): roms = ds.scan()#扫描总线上的设备 ds.convert_temp()#获取采样温度 time.sleep_ms(750) for rom in roms: print(ds.read_temp(rom))#得到温度 if __name__=='__main__': ow=onewire.OneWire(Pin(4))#创建onewire总线 引脚4(G4) ds=ds18x20.DS18X20(ow) while True: GetTemp() time.sleep(2) |
更多回帖