单片机教程网

电脑版
提示:原网页已由神马搜索转码, 内容由www.51hei.com提供.
查看:3985|回复:2

arduino oled+dht11显示

[复制链接]
ID:232530发表于 2017-12-23 12:53|显示全部楼层
在网上找了很久,都没有找到有关的资料。就自己改了程序库文件什么的都在压缩包了
#include< Arduino.h>
#include< U8g2lib.h>
#include< dht11.h>
dht11 DHT11;
#define DHT11PIN D6  //可改接口,这是我D1开发板的
#ifdef U8X8_HAVE_HW_SPI
#include< SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include< Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ D3, /* data=*/ D4, /* reset=*/ U8X8_PIN_NONE);   // ESP32 Thing, pure SW emulated I2C
void setup(void) {
   Serial.begin(9600);
   u8g2.begin();  
   u8g2.enableUTF8Print();     // enable UTF8 support for the Arduino print() function  
}  

void loop(void) {  
   int chk = DHT11.read(DHT11PIN);
   Serial.print("Humidity (%): ");
   Serial.println((float)DHT11.humidity, 2);

   Serial.print("Temperature (oC): ");
   Serial.println((float)DHT11.temperature, 2);
delay(2000);
   u8g2.setFont(u8g2_font_unifont_t_chinese2);  // use chinese2 for all the glyphs of "你好世界"  
   u8g2.setFontDirection(0);  
   u8g2.clearBuffer();  
   u8g2.setCursor(0, 15);  
   u8g2.print("Humidity (%):");  
   u8g2.setCursor(0, 28);  
   u8g2.print((float)DHT11.humidity, 2);  
   u8g2.setCursor(0, 40);  
   u8g2.print("Temperature (oC): ");     // Chinese "Hello World"  
   u8g2.setCursor(0, 60);  
   u8g2.print((float)DHT11.temperature, 2);     // Chinese "Hello World"  
   u8g2.sendBuffer();  

   delay(1000);  
}  

原理图: 无
仿真: 无
代码: 代码.7z(3.04 MB, 下载次数: 41)

评分

黑币 +50
收起理由
+ 50
共享资料的黑币奖励!

查看全部评分

ID:1109487发表于 2024-1-17 13:18|显示全部楼层
request for member 'read' in 'DHT11', which is of non-class type 'const uint8_t' {aka 'const unsigned char'}
ID:1109487发表于 2024-1-17 13:19|显示全部楼层
request for member 'read' in 'DHT11', which is of non-class type 'const uint8_t' {aka 'const unsigned char'}什么原因吖

手机版|小黑屋|51黑电子论坛|51黑电子论坛6群QQ管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网