门户网站建设工作汇报,怎么接网站开发外包,旅游网站wordpress,上门做网站哪里有0、结果
说明#xff1a;先来看看拍摄的显示结果#xff0c;如果是你想要的#xff0c;可以接着往下看。
1、外观
说明#xff1a;本次使用的oled是0.96寸的#xff0c;别的规格的屏幕不一定适用本教程#xff0c;一般而言有显示白色、蓝色和蓝黄一起显示的#xff0…0、结果
说明先来看看拍摄的显示结果如果是你想要的可以接着往下看。
1、外观
说明本次使用的oled是0.96寸的别的规格的屏幕不一定适用本教程一般而言有显示白色、蓝色和蓝黄一起显示的虽然dht11温湿度模块形态各异但是代码都是适用的因为它们的模块都是一样的。 2、连线
说明只需要连接三根线。
uno————dht11 5V--------------VCC GND--------------GND D7--------------DATA
说明只需要连接四根线。
uno————oled 0.96 5V--------------VCC GND--------------GND SCL--------------SCL SDA--------------SDA
3、源程序
说明采用非阻塞方式编写一定时间检测和显示一次温湿度数据并将对应功能进行函数化方便移植。
/****************************************dht11 part****************************************/
#include dht11.h //include library
#define dht11Pin 7 //Define DHT11 sensor connection pins
#define dht11TimeInterval 1000 //Detect the time interval of a tripdht11 DHT11; //Instantiate an object
unsigned long dht11Times 0; //Record the device running time
int dhtTemp 0, dht11Humi 0; //Storage temperature //Storage humidity
/****************************************oled96 part****************************************/
#include Arduino.h //include library
#include U8g2lib.h //include library
#include Wire.h //include libraryU8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset*/ U8X8_PIN_NONE);#define oledTimeInterval 1000 //Detect the time interval of a trip
unsigned long oledTimes 0; // Record the device running time/****************************************set up and loop part*********************************/
void setup() {u8g2.begin(); //Example Initialize the IIC
}
void loop() {getTempData(); //Obtain the temperature and humidity valuesoledDisplayMath(); //Display math
}
/****************************************oled96 part****************************************/
/*Display math*/
void oledDisplayMath() {if (millis() - oledTimes oledTimeInterval) { //This command is executed once in a whileoledTimes millis();u8g2.setFont(u8g2_font_ncenB14_tr); //u8g2_font_6x12_tru8g2.setFontDirection(0);u8g2.firstPage();do {u8g2.setCursor(0, 15); //0 means start at the first column and 15 means end at row 15u8g2.print(Temp:);u8g2.setCursor(64, 15); //0 means start at the first column and 15 means end at row 15u8g2.print(dhtTemp);u8g2.setCursor(96, 15); //0 means start at the first column and 15 means end at row 15u8g2.print( C);u8g2.setCursor(0, 31); //0 means start at the first column and 15 means end at row 15u8g2.print(Humi: );u8g2.setCursor(64, 31);u8g2.print(dht11Humi);u8g2.setCursor(96, 31); //0 means start at the first column and 15 means end at row 15u8g2.print( %);} while ( u8g2.nextPage() );}
}
/****************************************dht11 part****************************************/
/*Obtain the temperature and humidity values*/
void getTempData() {if (millis() - dht11Times dht11TimeInterval) {dht11Times millis();DHT11.read(dht11Pin); //Update all sensor informationdhtTemp DHT11.temperature;dht11Humi DHT11.humidity;Serial.print(Temperature: );Serial.print(dhtTemp);Serial.print( (C), );Serial.print(Humidity: );Serial.print(dht11Humi);Serial.println( (%).);}
}
4、注意事项
说明需要在线下载u8glib.h库文件和dht11.h库文件。