here's the errors ( In Files GrowRoomController_v1.pde:42: \arduino-1.0.2-windows\arduino-1.0.2\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for 'virtual void NewSoftSerial::write(uint8_t)'
\arduino-1.0.2-windows\arduino-1.0.2\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)' ) why is this happening ?? how can I fix this?? here's the code
Code: Select all
/*
* GreenRoomController.pde
*
* This program keeps track of the current time, date,
* temperature and humidity. It controls the enviroment
* using a light, a heater and an exhast fan. The light is
* turned on and off using the TimeAlarms library along with
* a DS1307 RTC. Temperature is controlled using maxmimum
* and minimum thesholds that turn on the designated appliances.
* The user is given a warning message when the current
* humidity is outside the nominal range. A LCD display is used
* to show the current time, sensor readings and appliance power
* states. Update messages are sent over the serial port when the
* a terminal if available. When a SD card is attached
* data and events are logged onto CSV files that are
* organized like so:'Year/Month/Date/file.csv'
*
* 2011 Nickolas K. Grillone
* Email: [email protected]
*/
#include <stdlib.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include <SHT1x.h>
#include <SLCD.h>
#include <NewSoftSerial.h>
#include <SD.h>
//Define CS pin for SD card and the ethernet board
#define SD_PIN 4
// Control pins for the light, fan and heater
#define LIGHT_PIN 30
#define FAN_PIN 31
#define HEATER_PIN 32
// Serial LCD has 2x16 character display
// **The RX pin from the SLCD display connects to pin 8**
#define numRows 2
#define numCols 16
// Start the Serial LCD instance
SLCD lcd = SLCD(numRows, numCols);
//LCD Message Delay Time
int lcdDelay = 2000;
// Create Controller Structure, one of these is needed for each appliance
struct Controller
{
int pin; //The pin that the relay that controlls the appliance is connected to
int invert; // 0 - heater, humidifier, etc; 1 - Air Conditioner, dehumifier, etc.
int turnPoint; //The maximum (minimum if inverted) the sensor reading can be before turning on
int status; // 0 - off; 1 - on
String label; // The name of the appliance (ex: Heater)
String controlLabel; // The reading that is being controlled (ex: Temperature)
};
// Create controller for both heater and Fan
Controller Heater;
Controller Fan;
// String to pass on to controlLabel for Fan and Heater
String tempString = "Temperature";
// CSV box Seperator
String boxSeperator = String(", ");
// Message strings for powering on and off appliances
char powerOnMsg[16] = "Powering ON: ";
char powerOffMsg[16] = "Powering OFF: ";
// Variables to store the power state of the light, fan and heater
boolean lightState = false;
// Specify data and clock connections and instantiate SHT1x object
#define dataPin 2
#define clockPin 3
SHT1x sht1x(dataPin, clockPin);
// Variable to store temperature and humidity readings
float temp_f;
float humidity;
// Hours that the light is switched on and off
int LightOnHour = 20;
int LightOffHour = 11;
// Maximum and minimum temperature and humidity
int maxTemp = 75;
int minTemp = 65;
int maxHumi = 75;
int minHumi = 40;
// Previous Date for keeping track of log files
int prevDate = 0;
// File object for the data log file
File dataFile;
// True if SD card was able to initilize
boolean SDavailable = false;
/************************************
* Setup *
************************************/
void setup()
{
// Start the serial port to communicate to the PC at 9600 baud
Serial.begin(9600);
// Start up the LCD display
lcd.init();
lcd.clear();
lcd.print("Starting up...");
// Get the time from the RTC
setSyncProvider(RTC.get);
// Report whether the Arduino was able to communicate with the RTC
if(timeStatus()!= BANNED)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
// See if the card is present and can be initialized
if (!SD.begin(SD_PIN)) {
Serial.println("SD card failed to initialize");
}
else {
Serial.println("SD card initialized.");
SDavailable = true;
}
// Read values from the sensor
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
// Save a reading to the current log file
LogData();
// Log the time of Startup in the current event Log
String startMsg = "Device Startup";
LogEvent(startMsg);
// Create alarms that turn on and off the light
Alarm.alarmRepeat(LightOnHour,00,0, LightOnAlarm); // 8:00pm every day
Alarm.alarmRepeat(LightOffHour,00,0,LightOffAlarm); // 11:00am every day
// Retrive sensor readings and turn off/on appliances as needed
Alarm.timerRepeat(10, CalibrateEnviromentControlAlarm);
// Update the time displayed on the LCD every 60 seconds
Alarm.timerRepeat(60, LCDtimeRefresh);
// Set controller variables for Heater
Heater.pin = HEATER_PIN;
Heater.invert = 1;
Heater.turnPoint = minTemp;
Heater.status = 0;
Heater.label = "Heater";
Heater.controlLabel = tempString;
// Set controller variables for Fan
Fan.pin = FAN_PIN;
Fan.invert = 0;
Fan.turnPoint = maxTemp;
Fan.status=0;
Fan.label = "Fan";
Fan.controlLabel = tempString;
pinMode(LIGHT_PIN, OUTPUT); // set pin as an output for light control
pinMode(FAN_PIN, OUTPUT); // set pin as an output for fan control
pinMode(HEATER_PIN, OUTPUT); // set pin as an output for heater control
pinMode(SD_PIN, OUTPUT); // set chip seldect pin as an output
digitalWrite(SD_PIN, HIGH);
// If the light is supposed to be on turn it on
if(hour()<LightOffHour || hour()>=LightOnHour)
{
digitalWrite(LIGHT_PIN, HIGH);
lightState = true;
}
// Check whether the Heater or the Fan have passed their turn point.
// If so turn on the required appliance
CheckController(temp_f, Heater);
CheckController(temp_f, Fan);
// Update LCD Screen
LCDrefresh();
}
/*********************************
* Loop *
*********************************/
void loop()
{
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}
/*************************************
* Light Control Alarms *
*************************************/
void LightOffAlarm()
{
// Turn off the light, update lightStatus, report the change
// over Serial, in the current eventLog and on the LCD screen
String msg = powerOffMsg;
msg += "Light";
char charMsg[20];
msg.toCharArray(charMsg,20);
digitalWrite(LIGHT_PIN, LOW);
lightState = false;
lcd.clear();
lcd.print(charMsg,0,0);
Serial.println(msg);
LogEvent(msg);
Alarm.delay(lcdDelay);
LCDrefresh();
}
void LightOnAlarm()
{
// Turn on the light, update lightStatus, report the change
// over Serial, in the current eventLog and on the LCD screen
String msg = powerOnMsg;
msg += "Light";
char charMsg[20];
msg.toCharArray(charMsg,20);
digitalWrite(LIGHT_PIN, HIGH);
lightState = true;
lcd.clear();
lcd.print(charMsg,0,0);
Serial.println(msg);
LogEvent(msg);
Alarm.delay(lcdDelay);
LCDrefresh();
}
/*******************************************
* Calibrate Enviroment Alarm *
*******************************************/
void CalibrateEnviromentControlAlarm()
{
// Display message over Serial
Serial.println("Taking Sensor Readings");
// Read values from the sensor
temp_f = sht1x.readTemperatureF();
humidity = sht1x.readHumidity();
// Print the temperature and humidity readings over the serial port
Serial.print("Temperature: ");
Serial.print(temp_f, DEC);
Serial.print("F. Humidity: ");
Serial.print(humidity);
Serial.println("%");
// Check whether the Heater or the Fan have passed their turn point.
// If so turn on the required appliance
CheckController(temp_f, Heater);
CheckController(temp_f, Fan);
// If the Humidity has passed the minimum threshold report it over the Serial port
if(humidity < minHumi)
{
Serial.println("Humidity has passed minumum theshold");
}
// If the Humidity has passed the maximum threshold report it over the Serial port
if(humidity > maxHumi)
{
Serial.println("Humidity has passed maximum theshold");
}
// Write Data Entry to SD Card
LogData();
// Refresh the sensor readings and the status indicators on the LCD screen
LCDstatusRefresh();
LCDsensorRefresh();
}
void CheckController(int sensorReading, struct Controller &c)
{
// If inverted, check if sensorReading is below the turn point
if(c.invert)
{
if(sensorReading<=c.turnPoint)
{
// Report that sensorReading is below the turnpoint
Serial.print(c.controlLabel);
Serial.println(" is BELOW nominal range");
// If the appliance is powered off turn it on, update
// the controller status and report it over serial
if(c.status==0)
{
// Display "Powering ON: 'LABEL'" on LCD screen
char buf[16];
c.label.toCharArray(buf,16);
lcd.clear();
lcd.print(powerOnMsg,0,0);
lcd.print(buf,1,0);
// Set appliance control pin to HIGH
digitalWrite(c.pin, HIGH);
c.status=1;
// Log event on SD card
String event = powerOnMsg;
event += c.label;
LogEvent(event);
// Display "Powering ON: 'LABEL'" over Serial
Serial.print(powerOnMsg);
Serial.println(c.label);
Alarm.delay(lcdDelay);
LCDrefresh();
}
// Else, report that it is already powered on
else
{
Serial.print(c.label);
Serial.println(" is powered ON");
}
}
else
{
// If the sensorReading is not below the turn point power
// the appliance off if needed, update the controller status
// and report it over serial
if(c.status==1 && sensorReading >= (c.turnPoint+5))
{
// Display "Powering OFF: 'LABEL'" on LCD screen
char buf[16];
c.label.toCharArray(buf,16);
lcd.clear();
lcd.print(powerOffMsg,0,0);
lcd.print(buf,1,0);
// Set appliance control pin to LOW
digitalWrite(c.pin, LOW);
c.status=0;
// Log event on SD card
String event = powerOffMsg;
event += c.label;
LogEvent(event);
// Display "Powering OFF: 'LABEL'" over Serial
Serial.print(powerOffMsg);
Serial.println(c.label);
Alarm.delay(lcdDelay);
LCDrefresh();
}
else
{
// Else, report that it is already powered off
Serial.print(c.label);
Serial.println(" is powered OFF");
}
}
}
//if not inverted...
else
{
// If inverted, check if sensorReading is above the turn point
if(sensorReading>=c.turnPoint)
{
// Report that sensorReading is above the turnpoint
Serial.print(c.controlLabel);
Serial.println(" is ABOVE nominal range");
// If the appliance is powered off turn it on, update
// the controller status and report it over serial
if(c.status==0)
{
// Display "Powering ON: 'LABEL'" on LCD screen
char buf[16];
c.label.toCharArray(buf,16);
lcd.clear();
lcd.print(powerOnMsg,0,0);
lcd.print(buf,1,0);
// Set appliance control pin to HIGH
digitalWrite(c.pin, HIGH);
c.status=1;
// Log event on SD card
String event = powerOnMsg;
event += c.label;
LogEvent(event);
// Display "Powering ON: 'LABEL'" over Serial
Serial.print(powerOnMsg);
Serial.println(c.label);
Alarm.delay(lcdDelay);
LCDrefresh();
}
// Else, report that it is already powered on
else
{
Serial.print(c.label);
Serial.println(" is powered ON");
}
}
// If the sensorReading is not below the turn point power
// the appliance off if needed, update the controller status
// and report it over serial
else
{
if(c.status==1 && sensorReading <= (c.turnPoint-5))
{
// Display "Powering OFF: 'LABEL'" on LCD screen
char buf[16];
c.label.toCharArray(buf,16);
lcd.clear();
lcd.print(powerOffMsg,0,0);
lcd.print(buf,1,0);
// Set appliance control pin to LOW
digitalWrite(c.pin, LOW);
c.status=0;
// Log event on SD card
String event = powerOffMsg;
event += c.label;
LogEvent(event);
// Display "Powering OFF: 'LABEL'" over Serial
Serial.print(powerOffMsg);
Serial.println(c.label);
Alarm.delay(lcdDelay);
LCDrefresh();
}
// Else, report that it is already powered off
else
{
Serial.print(c.label);
Serial.println(" is powered OFF");
}
}
}
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(month());
printDigitsDate(day());
printDigitsDate(year());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void printDigitsDate(int digits)
{
// utility function for digital clock display: prints preceding ":" and leading 0
Serial.print("/");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
void LCDsensorRefresh()
{
// Create a small buffer for itoa fuction
char buf[3];
// Clear the bottom line of the LCD screen
lcd.print(" ",1,0);
// If temperature reading is more or equal to 100,
// display the characters one space to the right to
// fit the reading, should look like this:
// T:1XXF RH:XX% X
if(temp_f>=100)
{
lcd.print("T:1",1,0);
lcd.print(itoa(((temp_f-100)/10),buf,10),1,3);
lcd.print(itoa(((int)temp_f%10),buf,10),1,4);
lcd.print("F",1,5);
lcd.print("RH:",1,8);
lcd.print(itoa(((int)humidity/10),buf,10),1,11);
lcd.print(itoa(((int)humidity%10),buf,10),1,12);
lcd.print("%",1,13);
//If the humidity is outside its nominal range print "!" on the LCD
if((int)humidity>maxHumi || (int)humidity<minHumi)
{
lcd.print("!",1,14);
}
}
// If temperature reading is not more or equal to 100,
// display the characters to fit the reading
// it should look like this:
// T:XXF RH:XX% X
else
{
lcd.print("T:",1,0);
lcd.print(itoa(((int)temp_f/10),buf,10),1,2);
lcd.print(itoa(((int)temp_f%10),buf,10),1,3);
lcd.print("F",1,4);
lcd.print("RH:",1,7);
lcd.print(itoa(((int)humidity/10),buf,10),1,10);
lcd.print(itoa(((int)humidity%10),buf,10),1,11);
lcd.print("%",1,12);
//If the humidity is outside its nominal range print "!" on the LCD
if(humidity>maxHumi || humidity<minHumi)
{
lcd.print("!",1,14);
}
}
}
void LCDtimeRefresh() {
// Get the current hour and minute
int displayHour = hour();
int displayMinute = minute();
// PM indicator, 0-AM ; 1-PM
int PM = 0;
// Create a small buffer for itoa function
char buf[3];
// If it is past noon, it is PM and subtract 12 from the display hour
if(displayHour>12)
{
PM = 1;
displayHour = displayHour-12;
}
// if it is midnight display 12 as the display hour and it is AM
if(displayHour==0)
{
displayHour=12;
PM = 0;
}
// If it is noon it is PM
if(hour()==12) PM=1;
// Clear the section of the LCD that displays the time
lcd.print(" ",0,0);
// If displayHour is more or equal to 10, format the time on
// the screen to fit the extra integer, Exaple: "HH:MMXM" where XM= AM/PM
if(displayHour<=10)
{
lcd.print(itoa(displayHour,buf,10),0,0);
lcd.print(":",0,1);
if(displayMinute<10)
{
lcd.print("0",0,2);
lcd.print(itoa(displayMinute,buf,10),0,3);
}
else
{
lcd.print(itoa((displayMinute/10),buf,10),0,2);
lcd.print(itoa((displayMinute%10),buf,10),0,3);
}
// If PM is true, display "P" else display "A"
if(PM==1)
{
lcd.print("P",0,4);
}
else
{
lcd.print("A",0,4);
}
lcd.print("M",0,5);
}
// If displayHour is not more or equal to 10, display the time
// accordingly, Example: "H:MMXM" where XM = AM/PM
else
{
lcd.print(itoa((displayHour/10),buf,10),0,0);
lcd.print(itoa((displayHour%10),buf,10),0,1);
lcd.print(":",0,2);
if(displayMinute<10)
{
lcd.print("0",0,3);
lcd.print(itoa(displayMinute,buf,10),0,4);
}
else
{
lcd.print(itoa((displayMinute/10),buf,10),0,3);
lcd.print(itoa((displayMinute%10),buf,10),0,4);
}
// If PM is true, display "P" else display "A"
if(PM==1)
{
lcd.print("P",0,5);
}
else
{
lcd.print("A",0,5);
}
lcd.print("M",0,6);
}
}
void LCDstatusRefresh()
{
//Light Status
if(lightState == true)
{
lcd.print("L+",0,8);
}
else
{
lcd.print("L-",0,8);
}
//Exhast Fan Status
if(Fan.status)
{
lcd.print("F+",0,11);
}
else
{
lcd.print("F-",0,11);
}
//Heater Status
if(Heater.status)
{
lcd.print("H+",0,14);
}
else
{
lcd.print("H-",0,14);
}
}
void LCDrefresh()
{
// Clear the LCD and refresh all indicators
lcd.clear();
LCDtimeRefresh();
LCDstatusRefresh();
LCDsensorRefresh();
}
/***********************************
* Data Logging Fuctions *
***********************************/
String CurrentDirectory()
{
String dirString;
// Assemble the directory string
dirString = String(year());
dirString += "/";
dirString += String(month());
dirString += "/";
dirString += String(day());
dirString += "/";
Serial.print("Current Logging Directory: ");
Serial.println(dirString);
return dirString;
}
File OpenCurrentLog()
{
// If the SD card is not present report it over serial and do nothing
if (!SDavailable) {
Serial.println("SD card failed to initialize");
}
else {
// Create String and buffer for the file string
String dirString = CurrentDirectory();
char dirBuf[32];
String fileString;
char fileBuf[32];
String header = "Time, Temperature(F), Humidity";
// Convert dirString to character array
dirString.toCharArray(dirBuf,20);
//If any branch off the directory don't exist create it or them
if(!SD.exists(dirBuf))
{
Serial.print(dirString);
Serial.println(" does not exist");
Serial.print("Creating: ");
Serial.println(dirBuf);
SD.mkdir(dirBuf);
}
else
{
// If it already exist report so over the Serial port
Serial.print(dirBuf);
Serial.println(" exists");
}
// Assemble the file string
fileString = dirString;
fileString += "datalog.csv";
Serial.print("Current Logging File: ");
Serial.println(fileString);
fileString.toCharArray(fileBuf, 30);
//Open or Create the log file
File logFile = SD.open(fileBuf, FILE_WRITE);
//Check if header is already present, if not write it
CheckFileHeader(logFile, header, fileString);
// Return the logFile object
return logFile;
}
}
void LogData()
{
// If the SD card is not present report it over serial and do nothing
if (!SDavailable) {
Serial.println("SD card failed to initialize");
}
else
{
// If the day has changed report so over Serial, close the old file
// and open a new DataLog the current dates directory
if(prevDate != day())
{
Serial.println("The Date has Changed");
Serial.println("Opening New Log File");
dataFile.close();
dataFile = OpenCurrentLog();
prevDate = day();
}
Serial.println("Preparing Data Entry...");
// Get current temperature and humidity
int temp = int(temp_f);
int humid = int(humidity);
// Log Date Entry Ex: "HH:MM:SS, TT, RH"
PrintTimeSD(dataFile);
dataFile.print(temp_f);
dataFile.print(boxSeperator);
dataFile.println(humidity);
//Display the data entry over serial
Serial.print("Data Entry: ");
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(boxSeperator);
Serial.print(temp_f);
Serial.print(boxSeperator);
Serial.println(humidity);
}
}
void LogEvent(String &msg)
{
char fileBuf[32];
String fileString = CurrentDirectory();
String header = "Time,Event"; //header for the file
fileString += "eventlog.csv"; // assemble the file string
fileString.toCharArray(fileBuf,32); // load to character array
// Close the dataLog and open the eventLog file
dataFile.close();
File eventFile = SD.open(fileBuf, FILE_WRITE);
// If the header has not been placed yet write it to the file
CheckFileHeader(eventFile, header, fileString);
// Print the message as follows: "HH:MM:SS, 'MESSAGE'"
PrintTimeSD(eventFile);
eventFile.println(msg);
//close the eventLog
eventFile.close();
// Reopen the dataLog
dataFile = OpenCurrentLog();
}
void CheckFileHeader(File &logFile, String &header, String &fileString)
{
// If this is a new file write the header at the top
if(logFile) {
if(logFile.size() == 0)
{
logFile.println(header);
Serial.println("New File Detected, Writing Header");
}
// If log file already exists display the size and
// begin writing to the end of the file
else
{
char fileSize[12];
itoa(logFile.size(), fileSize, 10);
logFile.seek(logFile.size());
Serial.print(fileString);
Serial.print(" size: ");
Serial.println(fileSize);
Serial.println("Writing to end of the file");
}
}
// If the file is unavailable report it over serial
else {
Serial.print("Error opening: ");
Serial.println(fileString);
}
}
void PrintTimeSD(File &file)
{
// Print the current time of the day as follows to the current File:
// "HH:MM:SS, "
file.print(hour());
printDigitsSD(minute(), file);
printDigitsSD(second(), file);
file.print(boxSeperator);
}
void printDigitsSD(int digits, File &file)
{
// function for digital clock display: prints preceding colon and leading 0
file.print(":");
if(digits < 10)
file.print('0');
file.print(digits);
}