u8g2库的相关资料

时间:2024-05-19 00:06:02

2017-12-1309:13:32更新51论坛上的帖子,大神自己写的库文件,待调试!

http://www.51hei.com/bbs/forum.php?mod=viewthread&tid=92967&extra=page%3D7&mobile=2

2017-12-1209:33:56更新资料

关于内存不足的问题摘要:http://www.arduino.cn/thread-32109-1-1.html

还在解决中,一直找不到原因。

链接arduino中文社区---传送门

我的资料备份

 #include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN A2
//U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 4, /* data=*/ 5, /* cs=*/ 3, /* dc=*/ 6, /* reset=*/ 7);//多脚显示屏
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ A4, /* data=*/ A5, /* reset=*/ U8X8_PIN_NONE); // 四角显示屏
double Fahrenheit(double celsius)
{
return 1.8 * celsius + ;
} //摄氏温度度转化为华氏温度 double Kelvin(double celsius)
{
return celsius + 273.15;
} //摄氏温度转化为开氏温度 // 露点(点在此温度时,空气饱和并产生露珠)
// 参考: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(, (11.344*(-/A0)))-) ;
SUM += 8.1328e-3 * (pow(,(-3.49149*(A0-)))-) ;
SUM += log10(1013.246);
double VP = pow(, SUM-) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
} // 快速计算露点,速度是5倍dewPoint()
// 参考: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/);
double Td = (b * temp) / (a - temp);
return Td;
}
void setup(void) {
u8g2.begin(); //选择U8G2模式,或者U8X8模式
Serial.begin();
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
} void loop(void) {
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_5x7_tr); //设置字体//font_ncenB14_tr
u8g2.setCursor(, ); //设置光标处
u8g2.print("H:"); //输出内容
u8g2.setCursor(,); //设置光标处
u8g2.print("T:"); //输出内容
} while ( u8g2.nextPage() ); Serial.println("\n"); int chk = DHT11.read(DHT11PIN); Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
} Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, ); Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, ); Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), ); Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), ); Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity)); Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
do {
u8g2.setFont(u8g2_font_5x7_tr); //设置字体
u8g2.setCursor(,); //设置光标处
u8g2.print((float)DHT11.humidity); //输出内容
u8g2.setCursor(,); //设置光标处
u8g2.print((float)DHT11.temperature); //输出内容
} while ( u8g2.nextPage() );
delay();
}

显示屏买了两次才发现4线的最好用,因为利用的IO口比较少,节省资源易操作。

u8g2库的相关资料

相关文章