JStainton:
it compiles to about 12k, of the 32k allowable so it shouldnt be a problem with the Static memory,
Indeed - and I consequently withdraw my suggestion! That's not the sort of figure I had in mind so, if the problem looks sorted by simply bringing in the Mega, it probably isn't, and is merely being put off till a more embarrassing time.
I submit you have only one goal at the moment, and that is to see sensible numbers on a screen. To this end you might try abandoning all thought of strings of any sort, do all the calcs in Arduino, and send rows of comma separated floats to the serial monitor. There is a good chance it will work first time - on the Uno!
One datalogging exercise is much the same as another, so the 24k of string-free code below might be useful. There is a swag of irrelevant stuff but the format should be similar. Yes, in this case the calc is required locally.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <PCD8544.h> // Nokia 5110
#include <SD.h> // SD card
#include <string.h> // from Date As Filename
#include "RTClib.h" // from Date As Filename
#include "Wire.h" // MUST HAVE lib for LCD disp, SD card, and serial
#define DS1307_ADDRESS 0x68
RTC_DS1307 RTC;
static PCD8544 lcd;
File myFile;
char filename[] = "00000000.CSV";
// Custom symbols
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };
static const byte SLASH_CHAR = 2;
static const byte slash_glyph[] = {0x00,0x20,0x10,0x08};
// Yellow group Lismore
byte InThermo[8] = {
0x28, 0x39, 0xFD, 0x50, 0x04, 0x00, 0x00, 0X69};
byte OutThermo[8] = {
0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
byte DrainThermo[8] = {
0x28, 0x62, 0xA5, 0x2D, 0x04, 0x00, 0x00, 0x21};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int second, minute, hour, weekDay, monthDay, month, year;
int k=0;
const int chipSelect = 4;
float InTemp, OutTemp, DrainTemp, diff;
// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
char sensorId2[] = "DrainThermo";
char calcId1[] = "diff";
void setup() {
lcd.begin(84, 48);
// Register the custom symbols...
lcd.createChar(DEGREES_CHAR, degrees_glyph);
lcd.createChar(SLASH_CHAR, slash_glyph);
Wire.begin();
Serial.begin(9600);
delay(300);//Wait for newly restarted system to stabilize
lcd.setCursor (0,0);
lcd.print("Initializing");
delay(2000);
lcd.setCursor (0,1);
pinMode(53, OUTPUT);
if (!SD.begin(chipSelect))
{
lcd.print("failed!");
delay (2000);
return;
}
lcd.println("init. OK!");
delay(2000);
getFileName();
lcd.println(filename);
delay(2000);
lcd.clear();
// First serial output "LABEL" is an Excel command, printed on reset
Serial.println("LABEL,Time,InTemp,OutTemp,diff,DrainTemp");
sensors.setResolution(InThermo, 12);
sensors.setResolution(OutThermo, 12);
sensors.setResolution(DrainThermo, 12);
running();
}
void loop() {
GetClock();
if (hour == 0 && minute == 0 && second <2)
{
getFileName();
}
//get the values from the DS8B20's
sensors.requestTemperatures();
InTemp = (sensorValue(InThermo));
OutTemp = (sensorValue(OutThermo));
DrainTemp = (sensorValue(DrainThermo));
diff = OutTemp - InTemp;
Serial.print("DATA,TIME,"); // Excel commands
Serial.print(InTemp);
Serial.print(" , ");
Serial.print(OutTemp);
Serial.print(" , ");
Serial.print(diff);
Serial.print(" , ");
Serial.println(DrainTemp);
lcd.setCursor(49,0);
lcd.print(InTemp);
lcd.setCursor(49,1);
lcd.print (OutTemp);
lcd.setCursor(49,2);
lcd.print(DrainTemp);
lcd.setCursor(49,3);
lcd.print(diff);
k=k+1;
if (k>9 )
{
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.print(second);
myFile.print(",");
myFile.print(InTemp);
myFile.print(",");
myFile.print(OutTemp);
myFile.print(",");
myFile.print(DrainTemp);
myFile.print(",");
myFile.println();
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
k=0;
}
delay(850);
} // loop ends here
//sensorValue function
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
return tempC;
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void GetClock(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void getFileName(){
DateTime now = RTC.now();
filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()
}
void running(){
lcd.setCursor(0,0);
lcd.print("In");
lcd.setCursor(31,0);
lcd.print("\001C ");
lcd.setCursor(0,1);
lcd.print("Out");
lcd.setCursor(31,1);
lcd.print("\001C ");
lcd.setCursor(0,2);
lcd.print("Drain");
lcd.setCursor(31,2);
lcd.print("\001C ");
lcd.setCursor(0,3);
lcd.print("diff");
lcd.setCursor(31,3);
lcd.print("\001C ");
}
I have just seen your last post. I'm afraid it is beyond me and I can't comment, but I still think what I have said above is valid!