SHT1x温湿度传感器提供的库文件中的例程无法通过编译
2013-04-227931
AI 快速预览详细
本文介绍了如何解决SHT1x温湿度传感器库文件在Arduino平台上编译失败的问题。具体报错为WProgram.h: No such file or directory和expected ',' or '...' before numeric constant。解决方法是将WProgram.h替换为Arduino.h,并检查代码中的常量定义。通过这些步骤,您可以快速解决问题,避免自行排查的时间成本。
|
我购买了一个SHT1x温湿度传感器,从DFRobot产品网页上(https://www.dfrobot.com.cn/index.php?route=product/product&filter_name=SHT1x&product_id=114)下载了库文件(http://www.dfrobot.com/image/data/DFR0066/SHT1x_Arduino.zip),解压后存放在Arduino安装目录下(D:\arduino-1.0.4\libraries),然后调用例程:D:\arduino-1.0.4\libraries\SHT1x\examples\ReadSHT1xValues,编译时失败,出现如下提示: In file included from ReadSHT1xValues.pde:11: D:\arduino-1.0.4\libraries\SHT1x/SHT1x.h:15:22: error: WProgram.h: No such file or directory In file included from ReadSHT1xValues.pde:16: D:\arduino-1.0.4\hardware\arduino\cores\arduino/Arduino.h:111: error: expected ',' or '...' before numeric constant D:\arduino-1.0.4\hardware\arduino\cores\arduino/Arduino.h:112: error: expected ',' or '...' before numeric constant 请问这是什么原因?如何解决? 多谢! |





与以太网盾连接后,已经可以正常实现网络访问获取温湿度
可是,我使用新的库文件和其附带的例程,虽然可以编译了,却得到如下运行结果:
Starting up
Temperature: -40.0099983215C / -40.0180015563F. Humidity: -4.44%
Temperature: -40.0099983215C / -40.0180015563F. Humidity: -4.44%
Temperature: -40.0099983215C / -40.0180015563F. Humidity: -4.44%
Temperature: -40.0099983215C / -40.0180015563F. Humidity: -4.44%
这样的结果明显和实际情况不符。
请帮忙看看有什么问题,多谢!
例程如下:[code]/**
* ReadSHT1xValues
*
* Read temperature and humidity values from an SHT1x-series (SHT10,
* SHT11, SHT15) sensor.
*
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
* www.practicalarduino.com
*/
#include
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
void setup()
{
Serial.begin(38400); // Open serial connection to report values to host
Serial.println("Starting up");
}
void loop()
{
float temp_c;
float temp_f;
float humidity;
// Read values from the sensor
temp_c = sht1x.readTemperatureC();
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
// Print the values to the serial port
Serial.print("Temperature: ");
Serial.print(temp_c, DEC);
Serial.print("C / ");
Serial.print(temp_f, DEC);
Serial.print("F. Humidity: ");
Serial.print(humidity);
Serial.println("%");
delay(2000);
}[/code]电路连接按照产品库中的图例连接的。