micropython读取AHT20温湿度数据

micropython读取AHT20温湿度数据

硬件:
合宙esp32-c3,aht20, 杜邦线,面包板
接线:
在这里插入图片描述
vin----16(5v)
gnd—14
scl----22
sda—21
每次循环需要调用一下scan(),否者会报错OSError: [Errno 19] ENODEV,对排阵重新焊接后该问题解决,可以去掉i2c.scan()语句,应该是接触不好导致的,但是原因比较费解。

示例代码如下:

from utime import sleep
from machine import Pin, I2C,SoftI2C
import ahtx0


i2c = SoftI2C(scl = Pin(6) ,sda = Pin(10), freq = 100000)

while True:
    
    #i2c.scan()
    sensor = ahtx0.AHT20(i2c)
    fahrenheit = sensor.temperature * 9 / 5 + 32
    wendu=(fahrenheit-32)/1.8
    print("\nTemperature: %0.2f F" % fahrenheit)
    print(wendu)
    print("Humidity: %0.2f %%" % sensor.relative_humidity)
    
    sleep(5)

ahtx0代码如下:

# The MIT License (MIT)
#
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
# Copyright (c) 2020 Andreas Bühl
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值