LCD + SD (Shield) + DHT22

Hi Folks,

Hopefully you all can help me. I'm using arduino to create a Temp/Humidity sensor that prints data onto an LCD screen and also logs it onto an SD card. This will allow the Museum I work for to both instantly see Temperature/Humidity, and collect data to look at long-term trends.

For equipment, I have:
an Arduino UNO
ethernet shield w/ SD card
DHT22 sensor
LCD 1602 module w/ pin header
10K Potentiometer

all running through a breadboard

I am starting to wrap my head around how the code works, and how wiring works, and have used many tutorials here and elsewhere, so thanks for that!

Here's my problem...I can get the DHT22 sensor to print to LCD, and I can get it to save to an SD card, but I cannot get it to do both at the same time. What usually happens is that when I initialize the arduino, and open up the serial monitor (to check that things are saving), I see temp and humidity data on the serial monitor (and on the card, when I take it out to check), but the LCD screen says "DDDDDDDDDDDD" and then goes blank.

I've printed my code below. Any help would be much appreciated.

#include "DHT.h"
#include "SD.h"
#include "LiquidCrystal.h"
#include "SPI.h"
#define DHTPIN A0

#define DHTTYPE DHT22
const int chipSelect = 4;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

DHT sensor(DHTPIN, DHTTYPE);

void setup(){
lcd.begin(16,2);
Serial.begin(9600);
sensor.begin();
Serial.print("Initializing SD card...");
pinMode(4,OUTPUT);

if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");

}

void loop()
{
float humidity = sensor.readHumidity();
float temperature_C = sensor.readTemperature();
float temperature_F = sensor.readTemperature(true);
if (isnan(humidity) || isnan(temperature_C) || isnan(temperature_F)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//print to LCD screen
lcd.clear();
lcd.setCursor(0,1);
lcd.print("T = ");
lcd.print(temperature_F);
lcd.setCursor(0,1);
lcd.print("H = ");
lcd.print(humidity);
delay(1000);

File sdcard_file = SD.open("data.txt", FILE_WRITE);

// if the file is available, write to it:

if (sdcard_file) {

sdcard_file.print(" Temperature in F: ");
sdcard_file.print(temperature_F);
sdcard_file.print(" Humidity: ");
sdcard_file.print(humidity);
sdcard_file.println("");
sdcard_file.close();

// print to the serial port too:

Serial.print(" Temperature in F: ");
Serial.print(temperature_F);
Serial.print(" Humidity: ");
Serial.print(humidity);
Serial.println("");
delay(1000);
}
// if the file isn't open, pop up an error:

else {

Serial.println("error opening datalog.txt");

}

}

U'll need to move LCD away from pins 12 and 11.
The SD.interface uses pins 11,12,13 + one CS pin. It also requires pin 10 to be output
If possible, use pin 10 for CS or avoid using this pin.
.........
The schematic for the ethernet add-on will show which pins are uses by the card

That worked perfectly! Thanks. Now I just have to figure out how to either include a RTC or do a milli convert to log the date and time.

get the compile time from your PC

uint32_t targetTime = 0;// for next 1 second timeout
uint8_t hh,mm,ss;  //containers for current time

static uint8_t conv2d(const char* p) 
{
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9') v = *p - '0';
  return 10 * v + *++p - '0';
}

void setup(void) 
{
  hh = conv2d(__TIME__);
  mm = conv2d(__TIME__+3);
  ss = conv2d(__TIME__+6);
  targetTime = millis() + 1000; 
}

void loop() 
{
  if (targetTime < millis()) 
  {
    targetTime = millis()+1000;
    ss++; 
    if (ss >59) 
    {
      ss = 0; mm++;
      if(mm > 59) 
      {
        mm = 0; hh++;
        if (hh > 23) hh = 0;
      }
    }
  }
}