Data Logger Shield with DHT22 Issues

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Data Logger Shield with DHT22 Issues

Post by bcook65 »

Some time back I bought a Data Logger Shield and built the Light/Temp Logger and it worked great, no issues.. I had also purchased a dht22 sensor and set it up with a 7 segment display.. worked fine and had no issues with the code compiling or running.
recently decided to mount a DHT22 onto a Data Logger Shield from adafruit..
Got all components mounted per instructions on the site
I am having issues.. first off, the RTC displays everything but the "Day" correctly.. the day is about 7 days ahead of the actual day.


Per the instructions, I am using 5v, ground, and pin 2.

At some point would like to add an lcd display but need to get it working first. Also want to log and display temp in both F and C

Following the initial instructions, downloaded DHT Library and put in folder "DHT" under libraries. All files looked like they were there. And loaded the DHT_TESTER example, see below;

Code: Select all

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

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

void loop() {
  // Wait a few seconds between measurements.
  delay(60000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
}
Got the following errors
DHT_TESTER.cpp:1:17: err
DHT_TESTER.cpp:4:17: error: DHT.h: No such file or directory
DHT_TESTER:20: error: 'DHT' does not name a type
DHT_TESTER.cpp: In function 'void setup()':
DHT_TESTER:34: error: 'dht' was not declared in this scope
DHT_TESTER.cpp: In function 'void loop()':
DHT_TESTER:43: error: 'dht' was not declared in this scope


Thanks

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: Data Logger Shield with DHT22 Issues

Post by Franklin97355 »

DHT_TESTER.cpp:4:17: error: DHT.h: No such file or directory
Means the library is not where the IDE can find it. Take a look at this library install tutorial.

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

franklin97355 wrote:
DHT_TESTER.cpp:4:17: error: DHT.h: No such file or directory
Means the library is not where the IDE can find it. Take a look at this library install tutorial.
Thanks

Turned out that for whatever reason the path to the sketchbook was not correct.. Now I can load to my uno.. and it runs and displays in the serial monitor.
How do I get it to write to the sd card? I included the sd.h library but that didnt work, guessing it needs to be referenced somewhere?

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Data Logger Shield with DHT22 Issues

Post by adafruit_support_bill »

Take a look at the Light Temp Logger code. That shows how to open files and write to them.

https://learn.adafruit.com/adafruit-dat ... me-clock-3

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

adafruit_support_bill wrote:Take a look at the Light Temp Logger code. That shows how to open files and write to them.

https://learn.adafruit.com/adafruit-dat ... me-clock-3
Wow.. Awesome.. Love the lil code walk thru.. really nice job.. very helpful to me.. :) Still be a while before I understand it and am up writing code but looks like it will give me the ability to muddle thru till things start to become clearer.. :)

And sweet resistor thingy to show you not a bot.. that is genius

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

Okay, I'm not doing something right.. Copied and pasted the SD card sections of code from the light/temp logger code into the dht_tester. But apparently am missing something or did something wrong.

Code: Select all

#include <SD.h>

// initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);


// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor for normal 16mhz Arduino
//DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);


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

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
}



Getting the following errors


DHT_TESTER:3: error: expected constructor, destructor, or type conversion before '.' token
DHT_TESTER:6: error: expected constructor, destructor, or type conversion before '(' token
DHT_TESTER:9: error: expected unqualified-id before 'if'
DHT_TESTER:14: error: expected constructor, destructor, or type conversion before '.' token
DHT_TESTER:18: error: expected unqualified-id before 'for'
DHT_TESTER:18: error: expected constructor, destructor, or type conversion before '<' token
DHT_TESTER:18: error: expected constructor, destructor, or type conversion before '++' token

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Data Logger Shield with DHT22 Issues

Post by adafruit_support_bill »

This code has to be part of a function. It should go in your setup() function like it is in the logger example.

Code: Select all

// initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

May have misunderstood your comment on where the sd code should go.. the only setup I could see was the void setup(void)..
I placed the code between the parenthesis.. still got errors.. also placed it after the closing parenthesis and still got errors.


DHT_TESTER:33: error: expected initializer before 'Serial'
DHT_TESTER:36: error: expected constructor, destructor, or type conversion before '(' token
DHT_TESTER:39: error: expected unqualified-id before 'if'
DHT_TESTER:44: error: expected constructor, destructor, or type conversion before '.' token
DHT_TESTER:48: error: expected unqualified-id before 'for'

DHT_TESTER:48: error: expected constructor, destructor, or type conversion before '<' token
DHT_TESTER:48: error: expected constructor, destructor, or type conversion before '++' token

Copied and pasted the SD code from the light temp logger code to minimize typo's and pasted it in..

Code: Select all

#include <SD.h>

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

void setup(
// initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename); ) {
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
 
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
}



User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Data Logger Shield with DHT22 Issues

Post by adafruit_support_bill »

the only setup I could see was the void setup(void)..
Yes. That is where the initialization code should go.
I placed the code between the parenthesis..
You can't put it there. The parameter list for setup must be (void). Code goes between the 'curly braces' { and }

http://www.tutorialspoint.com/cplusplus ... ctions.htm

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

Thanks for the link mr Bill.. :) def bookmarked that one.. lol..
I placed the sd code between the braces and still its returning a lot of errors for it.. Will take a look at that link when I get home and see if I can find something..

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Data Logger Shield with DHT22 Issues

Post by adafruit_support_bill »

If you can't figure it out, post the code and the errors you are getting.

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

is it possible to get the arduino IDE to display line numbers to make it easier to navigate and find or identify sections of code more easily.. and for reference ??

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Data Logger Shield with DHT22 Issues

Post by adafruit_support_mike »

I don't think the IDE has that feature.

You can check over in the Arduino forums for an official answer though: http://forum.arduino.cc/

They're the people who wrote (and continue to develop) the IDE.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Data Logger Shield with DHT22 Issues

Post by adafruit_support_bill »

It is an option in File->Preferences:
Attachments
Capture.PNG
Capture.PNG (18.59 KiB) Viewed 794 times

User avatar
bcook65
 
Posts: 109
Joined: Sat Apr 03, 2010 1:25 pm

Re: Data Logger Shield with DHT22 Issues

Post by bcook65 »

Bill, what version is that screen shot from? didnt see it in my ide.. .. maybe I should look and see if an upgrade is available.. your screen shot shows a few extra options. usually get a prompt when an upgrade is ready.. thanks..

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”