您的当前位置:首页正文

micropython ESP-01+DHT11+OLED 实现

来源:华拓网

0.准备

零件 数量
ESP-01 x1
DHT11 x1
128x64 OLED I2C x1
AMS1117-3.3V电源模块 -
导线 -
万能板 -
其他.. -

2.写入固件

2.焊接

电路 焊接示例

3.程序:

代码:

from machine import reset
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C

import dht
import time
import sys
import os 

i2c = I2C(scl=Pin(0), sda=Pin( 2))
oled = SSD1306_I2C(128, 64, i2c)
d = dht.DHT11(Pin( 2))  # 声明用到类库中的函数,并设置参数   
while True: 
    d.measure()  # 调用DHT类库中测量数据的函数 
    temp_ = str(d.temperature())#读取measure()函数中的温度数据
    hum_ = str(d.humidity())  # 读取measure()函数中的湿度数据 
    '''print('temp:'+ temp_+"C", 0, 0)
    print('hum:'+ hum_+"%", 0, 8) '''
    oled.fill(0)
    oled.text('temp:'+ temp_+"C", 0, 0)
    oled.text('hum:'+ hum_+"%", 0, 8)
    oled.show()
    time.sleep(1)
效果示例

大家自由发挥吧!!!