ESP8266 WIFI模块 & NodeMCUpython开发esp8266

Controlling 1-wire devices ( DS

2017-12-17  本文已影响29人  gaoshine

继续学习 micropython for esp8266的编程,本文将编写控制 one wire总线读取 DS18x20温度传感器的代码.

WechatIMG222.jpeg
import time
import machine
import onewire, ds18x20

# the device is on GPIO12
dat = machine.Pin(12)

# create the onewire object
ds = ds18x20.DS18X20(onewire.OneWire(dat))

# scan for devices on the bus
roms = ds.scan()
print('found devices:', roms)

# 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:
        print(ds.read_temp(rom), end=' ')
    print()

屏幕快照 2017-12-17 下午8.00.11.png
上一篇 下一篇

猜你喜欢

热点阅读