极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14967|回复: 2

求助!checksum error dht11 在线等!【新人贴】

[复制链接]
发表于 2016-2-13 13:47:13 | 显示全部楼层 |阅读模式
我在使用czad的timers多任务库(http://www.geek-workshop.com/thread-4852-1-1.html)时dht11出现了checksum error,请问为何?在线等!!!!
  1. double Fahrenheit(double celsius)
  2. {
  3.         return 1.8 * celsius + 32;
  4. }    //摄氏温度度转化为华氏温度

  5. double Kelvin(double celsius)
  6. {
  7.         return celsius + 273.15;
  8. }     //摄氏温度转化为开氏温度

  9. // 露点(点在此温度时,空气饱和并产生露珠)
  10. double dewPoint(double celsius, double humidity)
  11. {
  12.         double A0= 373.15/(273.15 + celsius);
  13.         double SUM = -7.90298 * (A0-1);
  14.         SUM += 5.02808 * log10(A0);
  15.         SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  16.         SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  17.         SUM += log10(1013.246);
  18.         double VP = pow(10, SUM-3) * humidity;
  19.         double T = log(VP/0.61078);   // temp var
  20.         return (241.88 * T) / (17.558-T);
  21. }

  22. // 快速计算露点,速度是5倍dewPoint()
  23. (double celsius, double humidity)
  24. {
  25.         double a = 17.271;
  26.         double b = 237.7;
  27.         double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  28.         double Td = (b * temp) / (a - temp);
  29.         return Td;
  30. }
  31. #include <Timers.h>
  32. #include <dht11.h>
  33. dht11 DHT11;
  34. #define DHT11PIN 2
  35. int sensor = 9;
  36. int ledPin = 13;
  37. void setup() {
  38.   Serial.begin(9600);
  39.   pinMode(sensor,INPUT);
  40.   pinMode(ledPin,OUTPUT);
  41.    TCs.AddFunc(0, DHT11PIN2, 1000);//定义一个任务,1000毫秒执行一次
  42.    TCs.AddFunc(1, SENSOR9, 1);//定义一个任务,1毫秒执行一次
  43.   // put your setup code here, to run once:

  44. }

  45. void loop() {
  46.   // put your main code here, to run repeatedly:

  47. }

  48. void DHT11PIN2()
  49. {
  50. Serial.println("\n");

  51.   int chk = DHT11.read(DHT11PIN);

  52.   Serial.print("Read sensor: ");
  53.   switch (chk)
  54.   {
  55.     case DHTLIB_OK:
  56.                 Serial.println("OK");
  57.                 break;
  58.     case DHTLIB_ERROR_CHECKSUM:
  59.                 Serial.println("Checksum error");
  60.                 break;
  61.     case DHTLIB_ERROR_TIMEOUT:
  62.                 Serial.println("Time out error");
  63.                 break;
  64.     default:
  65.                 Serial.println("Unknown error");
  66.                 break;
  67.   }

  68.   Serial.print("Humidity (%): ");
  69.   Serial.println((float)DHT11.humidity, 2);

  70.   Serial.print("Temperature (oC): ");
  71.   Serial.println((float)DHT11.temperature, 2);

  72.   Serial.print("Temperature (oF): ");
  73.   Serial.println(Fahrenheit(DHT11.temperature), 2);

  74.   Serial.print("Temperature (K): ");
  75.   Serial.println(Kelvin(DHT11.temperature), 2);

  76.   Serial.print("Dew Point (oC): ");
  77.   Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  78.   Serial.print("Dew PointFast (oC): ");
  79.   Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
  80. }

  81. void SENSOR9()
  82. {
  83. int val=digitalRead(sensor); //定义参数存储人体红外传感器读到的状态
  84. if(HIGH == val) //如果检测到有动物运动(在检测范围内),LED亮
  85. {
  86. digitalWrite(ledPin,HIGH);
  87. delay(5000);
  88. }
  89. else
  90. {
  91. digitalWrite(ledPin,LOW);
  92. }
  93. }
复制代码







回复

使用道具 举报

 楼主| 发表于 2016-2-13 14:14:35 | 显示全部楼层
好吧,用taskscheduler做出来了。
回复 支持 反对

使用道具 举报

发表于 2016-9-3 22:21:37 | 显示全部楼层
lz,也遇到同样问题,求分享怎么解决的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 02:03 , Processed in 0.111702 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表