-2

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
zmo
  • 24,463
  • 4
  • 54
  • 90
Artemis F
  • 72
  • 3
  • 4
  • 19
  • No magic. `'dht' does not name a type` means that you were trying to use the identifier `dht` where a type is expected, but apparently it wasn't a type. –  Jul 05 '13 at 08:10
  • 1
    @userXXX If you don't know what a type is in context of the C programming language, then there are serious problems. Grab K&R and read and learn it. –  Jul 05 '13 at 10:34

3 Answers3

1

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.

zmo
  • 24,463
  • 4
  • 54
  • 90
  • how should I go about fixing it? – Artemis F Jul 05 '13 at 09:19
  • I changed the #include to #include so it match the sketch's directory. But still the error still persists. After I got rid of dht DHT; the error became: DHT is not declared in this scope. – Artemis F Jul 05 '13 at 10:24
  • of course it does, `DHT` is an instance that being used in your code! You need to find the `dht.h` that contains the `DHT` class definition. And you should really learn the basics of C/C++, so you can understand what you are doing... – zmo Jul 05 '13 at 11:07
  • ok i think i corrected the problem. But then another one came up. http://stackoverflow.com/questions/17488039/what-is-core-amain-cpp-o-error-in-arduino – Artemis F Jul 05 '13 at 11:40
  • i just realized my computer doesn't recognize the "DHT22.h" at the beginning of the code. It says there's no file or directory like that. However, I've created a separate library with both the .h and .cpp files. So, there must be a problem with the Arduino program itself, right? – Artemis F Jul 05 '13 at 12:15
  • I'm sorry, but I don't think you can get help from SO. Your problem is too specific to your current situation, and you don't have any clues where to begin looking. You should first get a C programing lesson and/or ask your friend for help. – zmo Jul 05 '13 at 12:51
  • I fixed the problem. The library for dht was saved in the wrong place, so Arduino couldn't recognize the type dht. The type dht was defined in the dht.h file. – Artemis F Jul 09 '13 at 05:50
1

I had this exact same issue yesterday while updating a sketch using the DHT22 sensor that was written in Arduino 0022. I was trying to edit it in the Arduino 1.0.5 IDE. Multiple compile errors, particularly with the function millis(). I think it might have worked if I'd just opened the 0022 IDE, but I thought it was time to bring the sketch into this decade ;)

I downloaded the Adafruit DHT22 library from Github and re-wrote the sketch slightly to use the library's methods. It was pretty much drop-in. There is an example sketch included with the library that you can derive to make everything fit.

In my sketch, I got things going with:

#include "DHT.h"
#define DHTPIN 7 // what pin we're connected to on the Arduino UNO

#define DHTTYPE DHT22 // DHT 22 (AM2302)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}

A difference between the old version and the updated version was the 'dht.begin();' statement in the setup block.

The Adafruit library isn't quite as robust as the previous library I'd been using, particularly with error handling, but it just worked after maybe 45 minutes of fiddling.

May doG help me if the XBee library stops working in a future Arduino IDE release!

dynamo_hum
  • 11
  • 3
0

A 'type' describes what your variable is. Like an integer (5), a string("Hello world"), a character("a"), a boolean (true or false), or a float (3.1415).

It looks like 'dht' is supposed to be a type but the arduino IDE does not recognize it since it isnt a normal type. This should be solved by importing a library that creates that type. Then the arduino can recognize it.

This is where your "#include " comes in. I would recommend changing it to "#include "dht.h".

Also, double check to make sure that dht.h is indeed a file that the arduino can access.

Bbovenzi
  • 1
  • 2