很奇怪,IDE版本导致DHT22输出异常
本帖最后由 suoma 于 2017-9-26 07:43 编辑早上使用1.0.5输出数据正常
同样的程序,换成1.8.1就出问题了
附DHT22库,大家试一下,
还有一个问题,
Serial.readBytes(&Databuf, __len) ////将_len长度存到Databuf开始的地址
上面语句在1.0.5编译报错,但是1.8.1通过,是低版本的不可以用Serial.readBytes()吗?该怎么该啊?因为DHT22和这个问题导致我不能在一个IDE版本实现想要的功能
原问题帖见
http://www.geek-workshop.com/thread-30994-1-1.html 您可以問這位樓主看看
http://www.geek-workshop.com/forum.php?mod=viewthread&tid=28380&highlight=DHT22 galaxy 发表于 2017-9-26 22:07
您可以問這位樓主看看
http://www.geek-workshop.com/forum.php?mod=viewthread&tid=28380&highlight=DH ...
谢谢回复,他的帖子是库的问题,我同样的库在两个IDE下串口输出不一样,你有硬件的话也可以试一下 本帖最后由 galaxy 于 2017-10-3 11:40 编辑
suoma 发表于 2017-9-29 20:43
谢谢回复,他的帖子是库的问题,我同样的库在两个IDE下串口输出不一样,你有硬件的话也可以试一下
可否分享您的庫~~
有空我試試看
謝謝您
不好意思:L ,我看到您分享的庫了.... 本帖最后由 galaxy 于 2017-10-3 12:46 编辑
小弟的
1.0.5-r2~~ok
1.8.1 ~~ok
都是使用庫裡面的範例來試的
小弟的環境 WIN 10
galaxy 发表于 2017-10-3 12:41
小弟的
1.0.5-r2~~ok
1.8.1 ~~ok
谢谢测试,你的温度有输出,但是为什么和我的不一样?是使用我提供的serial.ino例程吗?
本帖最后由 galaxy 于 2017-10-6 08:26 编辑
確實之前的測試小弟疏忽沒仔細注意,不好意思~:L
今再確認是使用了您提供的 serial.ino例程
弄了一早也是發生和您一樣的困擾~
1.0.5 是 ok 的
1.8.1 是不 ok 的 :funk:
例程上是使用 數字2 的腳位,我換了其它腳位一樣不能用
galaxy 发表于 2017-10-6 08:07
確實之前的測試小弟疏忽沒仔細注意,不好意思~
今再確認是使用了您提供的 serial.ino例程
现在这个问题就出来了,IDE对库的支持不一样?我当时以为传感器坏了,哈哈,我们一起探索,你知道原因了告诉我
suoma 发表于 2017-10-7 07:22
现在这个问题就出来了,IDE对库的支持不一样?我当时以为传感器坏了,哈哈,我们一起探索,你知道原因了 ...
OK若試出來了再來回報~~ 這兩個星期一直在試這個問題~
試出來了,這是 library (庫)的問題。以下是試了各種庫~
https://www.arduinolibraries.info/libraries/dht-sensor-library
用到了1.2.3的library 就好了。
arduino 使用 1.8.9
不好意思現在才回覆您 這是 dht 1.2.3 的範例
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22(AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
} galaxy 发表于 2019-3-25 13:02
這兩個星期一直在試這個問題~
試出來了,這是 library (庫)的問題。以下是試了各種庫~
https://www.arduinol ...
这么久了您还记得回复啊?谢谢您了,我看到了
页:
[1]