Hi Bill, You're quickly becoming my favorite admin ;)
Quick question: Is there any reason why an LCD screen (standard 16x2) would not work simultaneously with the datalogger? I am able to run it easily with the code I had shown. then I added in all the code needed to run the adafruit data logging shield, and the characters on the display are not showing up correctly. I know it is not a hardware issue, If I stitch back to my first code, it works fine.
Code: Select all
#include "DHT.h"
#define Type DHT22
#include <LiquidCrystal.h>
#include "SD.h"
#include <Wire.h>
#include "RTClib.h"
//Datalogging
#define LOG_INTERVAL 1000 // mills between entries
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
RTC_PCF8523 RTC;
const int chipSelect = 10;
#define greenLEDpin 4
File logfile;
//LCD
int rs=6; //LCD Pins are 6 through 12
int en=7;
int d4=8;
int d5=9;
int d6=11;
int d7=12;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int htPin=2;
int lightPin=A0;
int sensorValue;
DHT HT(htPin,Type);
float humidity;
float tempC;
float tempF;
int setupTime=500;
int dt=15000;
//int vPin=3;
int LCDdelay=3000;
long SerialInterval = 1000; // 10 minutes
long lastSerialDisplayTime= 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.print("Initializing SD card...");
HT.begin();
delay(setupTime);
lcd.begin(16,2);
lcd.clear();
//pinMode(vPin, OUTPUT);
pinMode(chipSelect, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
pinMode(A0, INPUT);
pinMode(2, INPUT);
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);
//Starting Wire
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("temperature,Humidity,Light");
}
// pinMode(redLEDpin, OUTPUT);
//pinMode(greenLEDpin, OUTPUT);
// If you want to set the aref to something other than 5v
//analogReference(EXTERNAL);
void loop() {
// digitalWrite(vPin, HIGH);
humidity=HT.readHumidity();
tempC=HT.readTemperature();
tempF=HT.readTemperature(true);
sensorValue=analogRead(lightPin);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Current Temp");
lcd.setCursor(0,1);
lcd.print(tempF);
lcd.print(" F");
delay(LCDdelay);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Current Humidity");
lcd.setCursor(0,1);
lcd.print(humidity);
lcd.print(" %");
delay(LCDdelay);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Light Level");
lcd.setCursor(0,1);
lcd.print(sensorValue);
lcd.print(" units");
delay(LCDdelay);
if (millis() - lastSerialDisplayTime >= SerialInterval)
{lastSerialDisplayTime = millis();
Serial.print(tempF);
Serial.print(",");
Serial.print(humidity);
Serial.print(",");
Serial.println(sensorValue);
logfile.print(tempF);
logfile.print(",");
logfile.print(humidity);
logfile.print(",");
logfile.print(sensorValue);
logfile.print(",");
}
//digitalWrite(greenLEDpin, LOW);
}
As you can see, I've started to try debugging by commenting out lines of code, but no luck.