ok... The amount of ram used by:
dht = 33b
sd = 787b
nRF = 303b
With everything up and running except the nRF the amount of ram free is only 450b
Where can I go from here? With the nRF there is only 147b left. And if I really need 500b for the sd to init then I need to find at least 353b.
Thanks guys.
Revised code with some of the offenders striped out.
/*
Base only code...
*/
#include <serialGLCDlib.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 SYNC_INTERVAL 15000
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);
}
//RF24 radio(8,9); //Radio pins 3(to8),4(to9)
//RF24Network network(radio);
// Our node address
byte this_node;
// 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;
bool 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;
int syncSwitch = 0;
int nodetemp1;
int humid1;
int voltage1;
int nodetemp2;
int humid2;
int voltage2;
int nodetemp3;
int humid3;
int voltage3;
int nodetemp4;
int humid4;
//-------------------------------------------------------------------------------
void setup(void)
{
//
// Print preamble
//
Serial.begin(115200);
delay(5000);
// Which node are we?
this_node = 0;
//
//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("datetime,BaseTemp,BaseHumid,IndorTemp,IndorHumid,AtticTemp,AtticHumid,OutdrTemp,OutdrHumid");
//
// Bring up the RF network
//
SPI.begin();
// radio.begin();
// network.begin(/*channel*/ 92, /*node address*/ this_node);
}
serialGLCD lcd; // initialisation
//------------------------------------------------------------------------------------
void loop(void)
{
DateTime now;
now = RTC.now();
// lcd.reverseColor();
if ( lcdCount == 0 ){
lcd.clearLCD();
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;
}
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('"');
humid4 = dht.readHumidity();
int t = dht.readTemperature();
nodetemp4 = (t * 1.8 + 32);
// 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 -----------------------------------
byte nodedump = 0; //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.
nodetemp1 = tempf; //converting tempf to nodetemp3 for display and storage
humid1 = humidrh; //converting humidrh to humid3 for display and storage
voltage1 = voltage;
break;
case 2:
humidrh = humidrh - 2; //calibration indoor sensor humid is +2
nodetemp2 = tempf;
humid2 = humidrh;
voltage2 = voltage;
break;
case 3:
humidrh = humidrh - 5; //calibration attic sensor humid is +5
nodetemp3 = tempf;
humid3 = humidrh;
voltage3 = voltage;
break;
default :
break;
}
//------------------------- Reset -------------------------------
switch(nodedump)
{
case 1:
if(reset == 1){
nodetemp1 = 0;
humid1 = 0;
syncSwitch = 1;
sdWrite();
}
break;
case 2:
if(reset == 1){
nodetemp2 = 0;
humid2 = 0;
syncSwitch = 1;
sdWrite();
}
break;
case 3:
if(reset == 1){
nodetemp3 = 0;
humid3 = 0;
syncSwitch = 1;
sdWrite();
}
break;
default :
break;
}
//------------------------ Data to SD ---------------------------
logfile.print(", ");
logfile.print(nodetemp4);
logfile.print(", ");
logfile.print(humid4);
logfile.print(", ");
logfile.print(nodetemp2);
logfile.print(", ");
logfile.print(humid2);
logfile.print(", ");
logfile.print(nodetemp3);
logfile.print(", ");
logfile.print(humid3);
logfile.print(", ");
logfile.print(nodetemp1);
logfile.print(", ");
logfile.print(humid1);
logfile.println();