繁体   English   中英

'dht' 不命名类型

[英]'dht' does not name a type

我正在运行这段代码,它一直给我这个错误。 下面我放代码。 这是一个气象站的arduino代码。 我已经添加并导入了库,但我不断收到相同的错误。

#include <stdlib.h>
#include <SoftwareSerial.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#define SSID "DroidSpot" //replace XXXXX by your router SSID
#define PASS "gggg" //replace YYYYY by your router password
#define IP "184.106.153.149" // thingspeak.com IP
#define DHT22_PIN 2
String GET = "GET /update?key=GDQ0LAAXLDGYMXW1&field1="; //replace ZZZZZ by your ThingSpeak channel write key
SoftwareSerial monitor(10, 11); //Serial communication to ESP8266 module (RX, TX)


dht DHT;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

.....
    
    //read other sensors
    char buffer[10];
    //light sensor
    float luminance = analogRead(luminancePin);
    //UV sensor
    float uv = analogRead(uvPin);
    uv = uv * 0.0049; //convert values to volts
    uv = uv * 307; //convert to mW/m²
    uv = uv/200; //calculate UV index
    //temperature and humidity
    int chk = DHT.read22(DHT22_PIN);
    float humidity = DHT.humidity;
    float temperature = DHT.temperature;
    //pressure and temperature1
    sensors_event_t event;
    bmp.getEvent(&event);
    float pressure = 0;
    float temperature1 = 0;
    if (event.pressure)
    {
      pressure = event.pressure;
      bmp.getTemperature(&temperature1);
    }


错误在dht DHT; 线。 这是:

'dht' does not name a type

检查您正在使用哪个库。 您可能会尝试使用两个不同的库来组合两个不同的源代码示例。


您的代码正文似乎表明您想要一个不同的库。 该库定义了您想要的类型: https : //github.com/RobTillaart/DHTstable ,其中包含 Juraj 指出的适当字段。

你必须改变你的头(S)为好,如这里 尤其:

#include <dht.h>

如果您确实打算使用 Adafruit 库,正如您的包含内容所暗示的那样:

  • 正如错误所说, dht没有类或类型定义。 类名是DHT ,而不是dht

    请参阅 Github 存储库中的DHT.h ,以及同一存储库中的此示例

切换令牌:

DHT dht;

并将所有其他DHT重构为dht 您还需要确保调用了正确的类方法,因为read22未在此库中定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM