gabscar:
All outputs are printed to the serial monitor correctly.
I understand you are deriving the temperatures as floats
If you can do that and print them to serial, that should be all you need to know. The number is the same and the procedure is more or less the same, for serial, display, and recording.
Serial.print(InTemp); // Serial port
lcd.print(InTemp); // LCD
myFile.print(InTemp); // SD
The following code is actually for three temperature sensors but demonstrate all this and has a date as filename. Strip out what you don't need.
/*
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
// Serial print commands are for PLX-DAQ
size 22 894
*/
#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.setCursor (0,2);
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);
lcd.print(" ");
lcd.setCursor(20,5);
if( second==0)
{
lcd.print(" ");
lcd.setCursor(20,5);
}
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
lcd.print(":");
lcd.print(second);
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(){
// Turns file_today_name into date.txt format Seems to work OK!
sprintf(file_today_name, "%02d%02d%02d.csv", now.day(), now.month(), now.year());
}
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 ");
lcd.setCursor(8,4);
lcd.print("PLX to Excel");
}