准备材料:
1.硬件:Arduino uno, DHT11/22温湿度传感器,OLED0.96英寸显示屏幕
2.软件:arduino-1.0
本次实验使用温湿度传感器,通过合并字符串让oled显示两个量,并且定时刷新。
注意:请注意自己温湿度传感器的版本是否正确,液晶显示器上电的电压是否正确,否则会出现数值读取异常或显示器烧坏!
此实验也算是uno编程里面一个比较简单的实验了 ,OLED接线方式如下图:
3.3v | vcc |
GND | GND |
SCL | SCL |
SDA | SDA |
是不是很简单,基本不用动脑子,下图是DHT11的接线图:
D5直接连接到uno上的D5接口就可以了。
现在我们的硬件准备工作就基本上做完了,将Arduino软件连接到uno主板上后(这个应该不用教,这个不会网络上有教程)输入以下代码:
/*!
* MindPlus
* uno
*
*/
#include <DFRobot_DHT.h>
#include <DFRobot_SSD1306_I2C.h>
// 静态常量
const chCode chBuf[] = {
{0x6e29,0xe6b8a9,0xCEC2,{0x00,0x00,0x23,0xf8,0x12,0x08,0x12,0x08,0x83,0xf8,0x42,0x08,0x42,0x08,0x13,0xf8,0x10,0x00,0x27,0xfc,0xe4,0xa4,0x24,0xa4,0x24,0xa4,0x24,0xa4,0x2f,0xfe,0x00,0x00}},
{0x5ea6,0xe5baa6,0xB6C8,{0x01,0x00,0x00,0x80,0x3f,0xfe,0x22,0x20,0x22,0x20,0x3f,0xfc,0x22,0x20,0x22,0x20,0x23,0xe0,0x20,0x00,0x2f,0xf0,0x24,0x10,0x42,0x20,0x41,0xc0,0x86,0x30,0x38,0x0e}},
{0x6e7f,0xe6b9bf,0xCAAA,{0x00,0x00,0x27,0xf8,0x14,0x08,0x14,0x08,0x87,0xf8,0x44,0x08,0x44,0x08,0x17,0xf8,0x11,0x20,0x21,0x20,0xe9,0x24,0x25,0x28,0x23,0x30,0x21,0x20,0x2f,0xfe,0x00,0x00}}
};
// 创建对象
DFRobot_SSD1306_I2C oled12864;
DFRobot_DHT dht11_5;
// 主程序开始
void setup() {
dht11_5.begin(5, DHT11);
oled12864.setChCode(chBuf);
oled12864.begin(0x3c);
}
void loop() {
oled12864.setCursorLine(1);
oled12864.printLine((String("温度") + String(dht11_5.getTemperature())));
oled12864.setCursorLine(2);
oled12864.printLine((String("湿度") + String(dht11_5.getHumidity())));
delay(4000);
}
在以上代码中,我们将OLED显示器的地址初始化到0x3c,每隔4秒读取传感器数据并发送到液晶屏幕上,如下图所示:
本片文章就到这里,如有不足之处敬请批评指出。
标签:0x08,0xf8,温湿度,0x20,0x00,测量,oled12864,uno From: https://blog.csdn.net/weixin_55357256/article/details/136823668