如何在arduino库中包含多个目录

时间:2019-09-05 23:28:43

标签: c++ arduino

我有arduino库文件夹,其中包含一个名为DHT_sensor_Library的库。在此文件夹中,我还有另一个名为DHT_U的文件夹。在此文件夹中,我有DHT_U.ccp和DHT_U.h。

问题是当我在arduino IDE中包含DHT_U.h时:

#include "DHT_U.h"

错误提示:     Tempreture_Humidity_Sensor:2:19:错误:DHT_U.h:没有这样的文件或目录

compilation terminated.

exit status 1
DHT_U.h: No such file or directory

我已经尝试过 #include "DHT_U/DHT_U.h"#include "DHT_U\DHT_U.h"#include ..\DHT_U.h"。这些都不起作用。

这是我的代码的片段:

#include "DHT.h"
#include "DHT_U.h"
#include "LiquidCrystal.h"
#include "DHT.h"

完整代码可在此处显示:

#include <DHT.h>
#include <DHT_U.h>

// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"

// set the DHT Pin
#define DHTPIN 8

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  dht.begin();

  // Print a message to the LCD.
  lcd.print("Temp:  Humidity:");
}

void loop() {
  delay(500);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // read humidity
  float h = dht.readHumidity();
  //read temperature in Fahrenheit
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

  lcd.print(f);
  lcd.setCursor(7,1);
  lcd.print(h);  
}

我该如何解决?

2 个答案:

答案 0 :(得分:0)

尝试包括诸如"/home/your_username/arduino/lib/foo.h"之类的孔路径。您确定它是.h文件而不是.hpp吗?

答案 1 :(得分:0)

要考虑的一件事是,在使用#include方法时需要小心。

如果DHT_U.h.ino文件位于同一方向,则可以在其中添加该文件:

#include "DHT_U.h"

但是,如果您使用Arduino IDE中的库管理器安装了库,则应该执行以下操作:

#include <DHT_U.h>

如果这些都不起作用,请确保已正确安装了磁带库。您可以尝试使用已安装的库通过Arduino IDE测试示例。