骏胡 发表于 2013-4-22 23:14:50

SHT1x温湿度传感器提供的库文件中的例程无法通过编译

我购买了一个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

请问这是什么原因?如何解决?

多谢!

mickey 发表于 2013-4-23 11:25:47

本帖最后由 mickey 于 2013-4-23 14:02 编辑

该库文件是老版本IDE使用的,不支持1.0.4版本,以下附件是最新的库文件。

骏胡 发表于 2013-4-24 21:25:20

多谢提供新的库文件。
可是,我使用新的库文件和其附带的例程,虽然可以编译了,却得到如下运行结果:
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%
这样的结果明显和实际情况不符。
请帮忙看看有什么问题,多谢!

例程如下:/**
* ReadSHT1xValues
*
* Read temperature and humidity values from an SHT1x-series (SHT10,
* SHT11, SHT15) sensor.
*
* Copyright 2009 Jonathan Oxer <<a href="mailto:jon@oxer.com.au">jon@oxer.com.au</a>>
* <a href="http://www.practicalarduino.com" target="_blank">www.practicalarduino.com</a>
*/

#include <SHT1x.h>

// Specify data and clock connections and instantiate SHT1x object
#define dataPin10
#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);
}电路连接按照产品库中的图例连接的。

骏胡 发表于 2013-5-7 23:30:42

是连接问题,我用了Screw Shield V2接线柱扩展板(DFR0171 ),没想到数字IO一侧是没有电源的,传感器没有供电所以出现上述运行结果,连接电源后正常了,精度不错
与以太网盾连接后,已经可以正常实现网络访问获取温湿度
页: [1]
查看完整版本: SHT1x温湿度传感器提供的库文件中的例程无法通过编译