是什么类型的错误在Arduino的意思

人气:485 发布:2022-09-15 标签: weather arduino

问题描述

我建立用我朋友的code气象站。不过,他的Arduino的一个更老的版本,我有麻烦找出原因。我是新来编程,所以我不知道什么是'DHT没有指定类型的意思?我使用Arduino的1.04和我的朋友codeD上Arudino他气象站0022我的问题是,为什么不是我的验证能够编译?我在做什么错误?

下面是我的code:

 的#include< dht.h>DHT DHT;#定义DHT22_PIN 2#包括LT&;&Wire.h GT;#定义BMP085_ADDRESS 0x77 // I2C BMP085地址const的无符号字符OSS = 3; //设置过采样//标定值INT AC1;INT AC2;INT AC3;无符号整型AC4;无符号整型AC5;无符号整型AC6;INT B1;INT B2;INT MB;INT MC;诠释MD;// B5在bmp085GetTemperature计算(...),这个变量也bmp085Get pressure使用(...)//所以...温(...)之前,必须调用... pressure(...)。长B5;短期温度;长pressure;无效设置(){  pinMode(2,输入);  Wire.begin();  bmp085Calibration();  Serial.begin(115200);  analogReference(内部);}空隙环(){  //读数据  浮bat_read = analogRead(6);  // bat_read = analogRead(BAT_voltage);  浮CHK = DHT.read22(DHT22_PIN);  //显示数据  Serial.print(bat_read,DEC);  Serial.print(,);  Serial.print(DHT.humidity,2);  Serial.print(,);  温度= bmp085GetTemperature(bmp085ReadUT());  pressure = bmp085Get pressure(bmp085ReadUP());  Serial.print(温度,DEC);  Serial.print(,);  Serial.println(pressure,DEC);  延迟(1000);} 

的错误是:

 错误:DHT没有指定类型sketch_jul05a.ino:在功能无效循环()':错误:DHT在此范围中未声明 

解决方案

有关特定的错误,你应该

  

的DHT没有指定类型的

这意味着你有字 DHT 不是在一个地方,编译器能理解你的意思。

  

的如何将其更改为一个类型?的

您不希望它变成一个类型,你要解决你得到的编制问题。

  

的是什么类型呢?的

您应该阅读 K&安培;对的主题。 A型是一个规则,限制你进入制作code是一致的。

你应该在你的问题复制你得到完整的错误,我们与您更好的帮助。

假设错误是以下行:

 的#include< dht.h>DHT DHT; 

编译器不知道什么是 DHT ,因为它从来没有看到过被定义。我认为, dht.h 应当被包含的头需要应该包含 DHT 类型定义。你应该看看,如果你有 dht.h 在文件系统中,并在草图目录推。最后修改的#include< dht.h> 的#includedht.h,所以看起来了 dht.h 在你的本地目录中。

编辑:对不起,我不认为我不能帮你在这里比我刚才说的更多。问题是,你不明白我要告诉你解决你的问题,它给你解释将会给你一个C程序设计课。所以,你应该首先开始阅读的K&放大器; R ,去一些C / C ++ / Arduino的编程课程(也许在您的本地众创?),和/或托朋友帮你的并解释你发生了什么的

I am building a weather station using my friend's code. However, he an older verison of Arduino and I'm having trouble figuring out why. I am new to programming, so I don't know what "'dht' does not name a type" means? I'm using Arduino 1.04 and my friend coded his weather station on Arudino 0022. My question is, why isn't my verification able to compile? What am I doing incorrectly?

Here's my code:

#include <dht.h>
dht DHT;  
#define DHT22_PIN 2
#include <Wire.h>
#define BMP085_ADDRESS 0x77  // I2C address of BMP085

const unsigned char OSS = 3;  // Oversampling Setting

// Calibration values
int ac1;
int ac2; 
int ac3; 
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1; 
int b2;
int mb;
int mc;
int md;

// b5 is calculated in bmp085GetTemperature(...), this variable is also used in      bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5; 
short temperature;
long pressure;

void setup()
{
  pinMode(2, INPUT); 
  Wire.begin();
  bmp085Calibration();
  Serial.begin(115200);
  analogReference(INTERNAL);
}

void loop() {
  // READ DATA
  float bat_read=analogRead(6);
  //bat_read = analogRead(BAT_voltage);
  float chk = DHT.read22(DHT22_PIN);

  // DISPLAY DATA
  Serial.print(bat_read, DEC);
  Serial.print(", "); 
  Serial.print(DHT.humidity, 2);
  Serial.print(", ");
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  Serial.print(temperature, DEC);
  Serial.print(", "); 
  Serial.println(pressure, DEC);
  delay(1000);
}

The errors are:

error: 'dht' does not name a type

sketch_jul05a.ino: In function 'void loop()': error: 'DHT' was not declared in this scope

解决方案

About your specific bug you should

'dht' does not name a type

That means you have the word dht that is not at a place where the compiler could understand what you mean.

how do i change it to a type?

You do not want to change it into a type, you want to solve the compiling issue you're getting.

what does a type mean?

You should read the K&R on the subject. A type is a rule that constraints you into making code that is coherent.

You should copy in your question the full error you're getting, for us to better help you.

Let's assume the error is on the following line:

#include <dht.h>
dht DHT;  

The compiler does not know what is the dht, as it has never seen that being defined before. I assume, dht.h shall be a header to be included that needs should contain dht type definition. You should look if you have dht.h in your filesystem, and push it in your sketch's directory. And finally change the #include <dht.h> into #include "dht.h", so it looks up the dht.h in your local directory.

EDIT: I'm sorry I don't think I can't help you here more than what I just said. The problem is that you don't understand what I'm telling you to solve your problem, and explaining it to you would be giving you a C programming lesson. So you should first begin to read the K&R, go to some C/C++/Arduino programing courses (maybe in your local hackerspace?), and/or ask your friend to help you out and explaining to you what is happening.

175