阿正的网易云音乐 - 创建于 2017

一个大学生的学习心得,与君共勉。

u8g2库的相关资料

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中文社区---传送门

我的资料备份

  1 #include <Arduino.h>
  2 #include <SPI.h>
  3 #include <U8g2lib.h>
  4 #include <dht11.h>
  5 dht11 DHT11;
  6 #define DHT11PIN A2
  7 //U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 4, /* data=*/ 5, /* cs=*/ 3, /* dc=*/ 6, /* reset=*/ 7);//多脚显示屏
  8 U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ A4, /* data=*/ A5, /* reset=*/ U8X8_PIN_NONE);   // 四角显示屏
  9 double Fahrenheit(double celsius)
 10 {
 11 return 1.8 * celsius + 32;
 12 }    //摄氏温度度转化为华氏温度
 13 
 14 double Kelvin(double celsius)
 15 {
 16 return celsius + 273.15;
 17 }     //摄氏温度转化为开氏温度
 18 
 19 // 露点(点在此温度时,空气饱和并产生露珠)
 20 // 参考: http://wahiduddin.net/calc/density_algorithms.htm
 21 double dewPoint(double celsius, double humidity)
 22 {
 23 double A0= 373.15/(273.15 + celsius);
 24 double SUM = -7.90298 * (A0-1);
 25 SUM += 5.02808 * log10(A0);
 26 SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
 27 SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
 28 SUM += log10(1013.246);
 29 double VP = pow(10, SUM-3) * humidity;
 30 double T = log(VP/0.61078);   // temp var
 31 return (241.88 * T) / (17.558-T);
 32 }
 33 
 34 // 快速计算露点,速度是5倍dewPoint()
 35 // 参考: http://en.wikipedia.org/wiki/Dew_point
 36 double dewPointFast(double celsius, double humidity)
 37 {
 38 double a = 17.271;
 39 double b = 237.7;
 40 double temp = (a * celsius) / (b + celsius) + log(humidity/100);
 41 double Td = (b * temp) / (a - temp);
 42 return Td;
 43 }
 44 void setup(void) {
 45   u8g2.begin();   //选择U8G2模式,或者U8X8模式
 46   Serial.begin(9600);
 47 Serial.println("DHT11 TEST PROGRAM ");
 48 Serial.print("LIBRARY VERSION: ");
 49 Serial.println(DHT11LIB_VERSION);
 50 Serial.println();
 51 }
 52 
 53 void loop(void) {
 54   u8g2.firstPage();
 55   do {
 56      u8g2.setFont(u8g2_font_5x7_tr); //设置字体//font_ncenB14_tr
 57      u8g2.setCursor(0, 15);    //设置光标处
 58      u8g2.print("H:");  //输出内容
 59      u8g2.setCursor(0,30);    //设置光标处
 60      u8g2.print("T:");  //输出内容
 61   } while ( u8g2.nextPage() );
 62   
 63  
 64 
 65 
 66 
 67   Serial.println("\n");
 68 
 69 int chk = DHT11.read(DHT11PIN);
 70 
 71 Serial.print("Read sensor: ");
 72 switch (chk)
 73 {
 74 case DHTLIB_OK:
 75 Serial.println("OK");
 76 break;
 77 case DHTLIB_ERROR_CHECKSUM:
 78 Serial.println("Checksum error");
 79 break;
 80 case DHTLIB_ERROR_TIMEOUT:
 81 Serial.println("Time out error");
 82 break;
 83 default:
 84 Serial.println("Unknown error");
 85 break;
 86 }
 87 
 88 Serial.print("Humidity (%): ");
 89 Serial.println((float)DHT11.humidity, 2);
 90 
 91 Serial.print("Temperature (oC): ");
 92 Serial.println((float)DHT11.temperature, 2);
 93 
 94 Serial.print("Temperature (oF): ");
 95 Serial.println(Fahrenheit(DHT11.temperature), 2);
 96 
 97 Serial.print("Temperature (K): ");
 98 Serial.println(Kelvin(DHT11.temperature), 2);
 99 
100 Serial.print("Dew Point (oC): ");
101 Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
102 
103 Serial.print("Dew PointFast (oC): ");
104 Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
105 do {
106      u8g2.setFont(u8g2_font_5x7_tr); //设置字体
107      u8g2.setCursor(40,15);    //设置光标处
108      u8g2.print((float)DHT11.humidity);  //输出内容
109      u8g2.setCursor(40,30);    //设置光标处
110      u8g2.print((float)DHT11.temperature);  //输出内容
111   } while ( u8g2.nextPage() );
112 delay(2000);
113 }

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

 

 

 

posted @ 2017-12-01 18:52  阿♛正  阅读(2159)  评论(0编辑  收藏  举报