Sorry... It's a Uno (non R3)
I'm beginning to think that I am running out of memory... I have moved some stuff around and tried to reduce size where I could. The sketch as it appears here is 27090 bytes.
Code in full
/*
Base only code...
*/
#include <serialGLCDlib.h>
#include <avr/pgmspace.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
//#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#include <SD.h>
//#define DHTPIN 2 // DHT Pin
//#define DHTTYPE DHT22 // DHT 22
//DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
#define P(name) const prog_uchar name[] PROGMEM // declare a PROGMEM string
#define LOG_INTERVAL 1000
#define SYNC_INTERVAL 1000
uint32_t syncTime = 0;
const int chipSelect = 10;
// the logging file
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
// red LED indicates error
// digitalWrite(redLEDpin, HIGH);
while(1);
}
// Avoid spurious warnings
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
RF24 radio(8,9); //Radio pins 3(to8),4(to9)
RF24Network network(radio);
// Our node address
const int this_node = 0;
// The message that we send is just an unsigned int, containing a sensor reading.
struct message_t
{
int temp_reading;
int humid_reading;
int voltage_reading;
int reset_reading;
message_t(void): temp_reading(0), humid_reading(0), voltage_reading(0), reset_reading(0) {}//ADD VOLTAGE READING!!!!
};
bool lcdCount = 0;
int tempf = 0;
int humidrh = 0;
int voltage = 0;
int reset = 0;
char nodereset[3] = "RS";
char nodetemp1[4] = "ND";
char humid1[4] = "ND";
char voltage1[4] = "ND";
char nodetemp2[4] = "ND";
char humid2[4] = "ND";
char voltage2[4] = "ND";
char nodetemp3[4] = "ND";
char humid3[4] = "ND";
char voltage3[4] = "ND";
int nodetemp4 = 0;
int humid4 = 0;
P(batstat1) = "Odr Bat Low!";
P(batstat2) = "Idr Bat Low!";
P(batstat3) = "Atc Bat Low!";
P(sysStat) = "Sys Stus:";
P(sysStatc) = "All Ok ";
//-------------------------------------------------------------------------------
void setup(void)
{
//
// Print preamble
//
Serial.begin(115200);
delay(5000);
//
// Pull node address out of eeprom
//
//
//DHT sensor
//
// dht.begin();
Wire.begin();
RTC.begin();
// 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)) {
error("Card failed, or not present");
}
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);
logfile.println("millis,stamp,datetime,light,temp,vcc");
//
// Bring up the RF network
//
SPI.begin();
radio.begin();
network.begin(/*channel*/ 92, /*node address*/ this_node);
}
serialGLCD lcd; // initialisation
//------------------------------------------------------------------------------------
void loop(void)
{
// lcd.reverseColor();
if ( lcdCount == 0 ){
lcd.clearLCD();
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
// log milliseconds since starting
//uint32_t m = millis();
//logfile.print(m); // milliseconds since start
//logfile.print(", ");
//----------------------- time shit -------------------------------------------
// fetch the time
now = RTC.now();
// log time
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print("/");
logfile.print(now.year(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
logfile.print('"');
lcd.gotoLine(7);
Serial.print(" ");
delay(10);
lcd.gotoLine(7);
Serial.print(now.month(), DEC);
Serial.print("/");
delay(10);
Serial.print(now.day(), DEC);
Serial.print("/");
delay(10);
Serial.print(now.year(), DEC);
Serial.print(" ");
delay(10);
Serial.print(now.hour(), DEC);
Serial.print(":");
delay(10);
Serial.print(now.minute(), DEC);
Serial.print(" Now");
lcd.gotoLine(8);
Serial.print(" ");
delay(10);
lcd.gotoLine(8);
Serial.print(now.month(), DEC);
Serial.print("/");
delay(10);
Serial.print(now.day(), DEC);
Serial.print("/");
delay(10);
Serial.print(now.year(), DEC);
Serial.print(" ");
delay(10);
Serial.print(now.hour(), DEC);
Serial.print(":");
delay(10);
Serial.print(now.minute(), DEC);
Serial.print(" Start");
delay(10);
// Print title information
lcd.gotoLine(1);
Serial.print("Local Temp RH% Bat");
lcd.gotoLine(4);
Serial.print(" BOOTING UP ");
lcdCount = 1;
}
//humid4 = dht.readHumidity();
//int t = dht.readTemperature();
nodetemp4 = (1.8 + 32); //ADD t BACK IN!!!!!
// Pump the network regularly
network.update();
// If we are the base, is there anything ready for us?
while ( network.available() )
{
// If so, grab it and print it out
RF24NetworkHeader header;
message_t message;
network.read(header,&message,sizeof(message));
//------------------- Converting and Storing radio data ---------------------------------
tempf = (message.temp_reading * 1.8 + 32);
humidrh = (message.humid_reading);
voltage = (message.voltage_reading);
reset = (message.reset_reading);
//--------------------Storing Node Number for sorting use -----------------------------------
int nodedump = header.from_node;
//------------------------- Sorting received information from radio ---------------------------
switch(nodedump) // If node dump reads "1" through blah is node. Need to assign Attic, Outdoor, etc.
{
case 1: // no "0" because we will hard code it in.
itoa(tempf, nodetemp1,4); //converting tempf to nodetemp1 for display and storage
itoa(humidrh, humid1, 4); //converting humidrh to humid1 for display and storage
itoa(voltage, voltage1, 4);
break;
case 2:
humidrh = humidrh - 2; //calibration indoor sensor humid is +2
itoa(tempf, nodetemp2, 4);
itoa(humidrh, humid2, 4);
itoa(voltage, voltage2, 4);
break;
case 3:
humidrh = humidrh - 5; //calibration attic sensor humid is +5
itoa(tempf, nodetemp3, 4);
itoa(humidrh, humid3, 4);
itoa(voltage, voltage3, 4);
break;
default :
break;
}
//------------------------- Battery Warning -------------------------------
if (voltage < 25){
switch(nodedump)
{
case 1:
if (voltage < 25){
lcd.gotoLine(6);
Serial.print(" ");
delay(10);
lcd.gotoLine(6);
printP(sysStat);
delay(10);
printP(batstat1);
delay(10);
}
break;
case 2:
if (voltage < 25){
lcd.gotoLine(6);
Serial.print(" ");
delay(10);
lcd.gotoLine(6);
printP(sysStat);
delay(10);
printP(batstat2);
delay(10);
}
break;
case 3:
if (voltage < 25){
lcd.gotoLine(6);
Serial.print(" ");
delay(10);
lcd.gotoLine(6);
printP(sysStat);
delay(10);
printP(batstat3);
delay(10);
}
break;
default :
break;
}
}
else
{
lcd.gotoLine(6);
Serial.print(" ");
delay(10);
lcd.gotoLine(6);
printP(sysStat);
delay(10);
printP(sysStatc);
delay(10);
}
//------------------------- Reset -------------------------------
switch(nodedump)
{
case 1:
if(reset == 1){
strcpy(nodetemp1, nodereset);
strcpy(humid1, nodereset);
//sdWrite();
}
break;
case 2:
if(reset == 1){
strcpy(nodetemp2, nodereset);
strcpy(humid2, nodereset);
//sdWrite();
}
break;
case 3:
if(reset == 1){
strcpy(nodetemp3, nodereset);
strcpy(humid3, nodereset);
//sdWrite();
}
break;
default :
break;
}