Controlling 1-wire devices ( DS18S20 or DS18B20 temperature sensor)

继续学习 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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,916评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,845评论 18 139
  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,522评论 7 249
  • ​​​本文主要介绍嵌入式系统的一些基础知识,希望对各位有帮助。 嵌入式系统基础 1、嵌入式系统的定义 (1)定义:...
    OpenJetson阅读 3,340评论 0 13
  • 我把睡眠丢了 丢在布满荆棘的路上 人世繁茂 夕阳贫穷 黑暗是虚无的掩体 它却令我着迷 我把自己丢了 丢在黑暗的真实...
    一个嬉皮阅读 191评论 0 0