5860浏览
查看: 5860|回复: 3

[已解决] 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  NPC

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

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

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

SHT1x_1.0.rar

4.42 KB, 下载次数: 1209

回复

使用道具 举报

骏胡  见习技师
 楼主|

发表于 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%
这样的结果明显和实际情况不符。
请帮忙看看有什么问题,多谢!

例程如下:
  1. /**
  2. * ReadSHT1xValues
  3. *
  4. * Read temperature and humidity values from an SHT1x-series (SHT10,
  5. * SHT11, SHT15) sensor.
  6. *
  7. * Copyright 2009 Jonathan Oxer <<a href="mailto:jon@oxer.com.au">jon@oxer.com.au</a>>
  8. * <a href="http://www.practicalarduino.com" target="_blank">www.practicalarduino.com</a>
  9. */
  10. #include <SHT1x.h>
  11. // Specify data and clock connections and instantiate SHT1x object
  12. #define dataPin  10
  13. #define clockPin 11
  14. SHT1x sht1x(dataPin, clockPin);
  15. void setup()
  16. {
  17.    Serial.begin(38400); // Open serial connection to report values to host
  18.    Serial.println("Starting up");
  19. }
  20. void loop()
  21. {
  22.   float temp_c;
  23.   float temp_f;
  24.   float humidity;
  25.   // Read values from the sensor
  26.   temp_c = sht1x.readTemperatureC();
  27.   temp_f = sht1x.readTemperatureF();
  28.   humidity = sht1x.readHumidity();
  29.   // Print the values to the serial port
  30.   Serial.print("Temperature: ");
  31.   Serial.print(temp_c, DEC);
  32.   Serial.print("C / ");
  33.   Serial.print(temp_f, DEC);
  34.   Serial.print("F. Humidity: ");
  35.   Serial.print(humidity);
  36.   Serial.println("%");
  37.   delay(2000);
  38. }
复制代码
电路连接按照产品库中的图例连接的。
回复

使用道具 举报

骏胡  见习技师
 楼主|

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

是连接问题,我用了Screw Shield V2接线柱扩展板(DFR0171 ),没想到数字IO一侧是没有电源的,传感器没有供电所以出现上述运行结果,连接电源后正常了,精度不错
与以太网盾连接后,已经可以正常实现网络访问获取温湿度
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies |上传

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail