Uno data logging DS18B20 daisy chained sensors

Hi,
I have been trying to get a data logging program to work. First I was able to finally get the code to communicate with the SD and make a file with data which I do not know from where the data came.

There are two base code examples I have been working to try and utilise which I combined. If I remove all SD parts the code prints to serial port the temperatures quite well. I tried posting the seperate original code but file to large.

Lastly is my attempt to combine the code to take the daisy chained temperature sensors and log to an SD card which is not quite there yet!

/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
  Connections:
  DS18B20 Pinout (Left to Right, pins down, flat side toward you)
  - Left   = Ground
  - Center = Signal (Pin 2):  (with 3.3K to 4.7K resistor to +5 or 3.3 )
  - Right  = +5 or +3.3 V

   Questions: terry@yourduino.com 
   V1.01  01/17/2013 ...based on examples from Rik Kretzinger
   
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>

#include <SD.h>

#include <SPI.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

const int chipSelect = 4;

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
DeviceAddress Probe02 = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
DeviceAddress Probe03 = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
DeviceAddress Probe04 = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
DeviceAddress Probe05 = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
DeviceAddress Probe06 = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
DeviceAddress Probe07 = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
DeviceAddress Probe08 = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
DeviceAddress Probe09 = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
DeviceAddress Probe10 = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };



void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
  //while (!serial){
  //  ; // wait for serial port to connect. Needed for Leonardo only.
  //}
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  Serial.print("Initialising SD card...");
  // make sure that the default chip select pin is set to 
  // output, even if you dont use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialised:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // Dont do anything more:
    return;
  }
  Serial.println("Card Initialised.");
  
  
  
  
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  // make a string for assembling the data to log:
  String dataString = "";
  // read sensors and append to the string:
  for (int digitalPin = 2; digitalPin < 3; digitalPin++)
  {
    int sensor = digitalRead(digitalPin);
    dataString += String(sensor);
    if (digitalPin < 2)
                      {
                      dataString += ",";
                      }
  }
  delay(3000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print(" Probe 01:   "); //Will print accross the line i.e. //Serial.print();
  //Serial.print(" Probe 01:   "); was changed to Serial.print(""); and results in just the temperature value being printed.
   printTemperature(Probe01);
    //The code below tells it to print a line then go down to next line.
  //Serial.println();
   

  Serial.print(" Probe 02:   ");
  printTemperature(Probe02);
  //Serial.println();
 
  Serial.print(" Probe 03:   ");
  printTemperature(Probe03);
 //Serial.println();
   
  Serial.print(" Probe 04:   ");
  printTemperature(Probe04);
  //Serial.println();
  
  Serial.print(" Probe 05:   ");
  printTemperature(Probe05);
  //Serial.println();
  
  Serial.print(" Probe 06:   ");
  printTemperature(Probe06);
  //Serial.println();

  Serial.print(" Probe 07:   ");
  printTemperature(Probe07);
  //Serial.println();
 
  Serial.print(" Probe 08:   ");
  printTemperature(Probe08);
  //Serial.println();
   
  Serial.print(" Probe 09:   ");
  printTemperature(Probe09);
  //Serial.println();
  
  Serial.print(" Probe 10:   ");
  printTemperature(Probe10);
  Serial.println();
  
  // Open the file. Note only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  
  // If the file is available, write to it:
  if (dataFile) 
              { 
               dataFile.println (dataString);
               dataFile.close();
               // Print to the serial port too:
               //Serial.println(dataString);
              }
               // If the file isn't open, pop up an error:
               else {
                 Serial.println("Error opening datalog.txt");
               //}
              }   
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   //Serial.print("C: ");
   Serial.print(tempC);
   //Serial.print(" F: ");
  // Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

Now the pin I have been using is digital 2 so I amended from the original code (AO) and substituted the analogRead etc for digitalRead etc. This still logged a value but i think it was just from Ao A1 and A2 as per the code. I did try plugging into AO but no change.

So in summation the temperature code example works printing to serial port but am unable to incorporate the SD code to log the data.

If there are any pointers I thank you in advance.

Regards,

Wayne

Also the way the UNO and SD are connected follows;
The daisy chain sensors have a 4.7k resistor across data and power.
CS 10
MOSI 11
SCK 13
MISO 12

When the code is working and printing to serial the data is to digital 2.

cont int chipSelect = 4

You will be better off sending the same data in the same manner to the various destinations - serial, LCD, SD. There is no need to mess about with the data once you have it for one.

Essentially
For serial it is Serial.print(Tempreading);
For LCD it is lcd.print(Tempreading);
For SD it is myfile.print(Tempreading);

Below is a typical datalogger that exemplifies this principle. Strip out what you don’t need. I suspect you are trying to adapt the datalogger by Igoe in the IDE examples. It seems to me to be the kiss of death, and I’m struggling to work out why it is in the public domain.

/* 
//  This Arduino sketch reads DS18B20 "1-Wire" digital temperature sensors.
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

 */
#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 tempC, 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();

  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(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[])
{
  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();
   sprintf(filename, "%02d%02d%02d.txt", now.year(), now.month(), now.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 "); 
}
*/

Hi Nick, Thanks for the code!
I have tried to amend to fit what I am trying to achieve, below is as far as I have been able to get but the code is not compiling.

Any tips will be appreciated from anyone!

Regards,

Wayne

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h> 
#include <SD.h> 
#include <string.h> 

const int chipSelect = 4;

File myFile;
char filename[] = "00000000.CSV";


/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2
/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//const int chipSelect = 4;

float tempC, Probe01, Probe02, Probe03, Probe04, Probe05, Probe06, Probe07, Probe08, Probe09, Probe10;

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

byte Probe01[8] = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
byte Probe02[8] = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
byte Probe03[8] = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
byte Probe04[8] = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
byte Probe05[8] = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
byte Probe06[8] = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
byte Probe07[8] = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
byte Probe08[8] = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
byte Probe09[8] = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
byte Probe10[8] = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };

char sensorId01[] = "Probe01";
char sensorId02[] = "Probe02";
char sensorId03[] = "Probe03";
char sensorId04[] = "Probe04";
char sensorId05[] = "Probe05";
char sensorId06[] = "Probe06";
char sensorId07[] = "Probe07";
char sensorId08[] = "Probe08";
char sensorId09[] = "Probe09";
char sensorId10[] = "Probe10";


void setup()   /****** SETUP: RUNS ONCE ******/
{
  
  Wire.begin();
  // start serial port to show results
  Serial.begin(9600);
  delay(300);//Wait for newly restarted system to stabilize
  Serial.println("Initializing Temperature Control Library");
  Serial.println("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);
  pinMode(SS, OUTPUT);
  
    // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
  }
  Serial.println("card initialized.");
  delay(300);
    getFileName();
    Serial.println(filename);
  
  // Open up the file we're going to log to!
  myFile = SD.open("datalog.txt", FILE_WRITE);
  if (! myFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }
  
  // Initialize the Temperature measurement library
  
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(1000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures(); 
 
  Probe01 = (sensorValue(Probe01}};
  Probe02 = (sensorValue(Probe02}};
  Probe03 = (sensorValue(Probe03}};
  Probe04 = (sensorValue(Probe04}};
  Probe05 = (sensorValue(Probe05}};
  Probe06 = (sensorValue(Probe06}};
  Probe07 = (sensorValue(Probe07}};
  Probe08 = (sensorValue(Probe08}};
  Probe09 = (sensorValue(Probe09}};
  Probe10 = (sensorValue(Probe10}};
 
  
  
  Serial.print(Probe01);
  Serial.print(" , ");
  Serial.print(Probe02);
  Serial.print(" , ");
  Serial.print(Probe03);
  Serial.print(" , ");
  Serial.print(Probe04);
  Serial.print(" , ");
  Serial.print(Probe05);
  Serial.print(" , ");
  Serial.print(Probe06);
  Serial.print(" , ");
  Serial.print(Probe07);
  Serial.print(" , ");
  Serial.print(Probe08);
  Serial.print(" , ");
  Serial.print(Probe09);
  Serial.print(" , ");
  Serial.print(Probe10);
  Serial.print(" , ");

 
   
  myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(Probe01);
  myFile.print(",");
  myFile.print(Probe02);
  myFile.print(",");
  myFile.print(Probe03);
  myFile.print(",");  
  myFile.print(Probe04);
  myFile.print(",");
  myFile.print(Probe05);
  myFile.print(",");
  myFile.print(Probe06);
  myFile.print(",");
  myFile.print(Probe07);
  myFile.print(",");  
  myFile.print(Probe08);
  myFile.print(",");
  myFile.print(Probe09);
  myFile.print(",");
  myFile.print(Probe10);
  myFile.print(",");
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
       
  delay(850);
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
  }
  byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
  }
  
//*********( THE END )***********

You appear to have a conflict by calling the Probes twice - wrong nomenclature. Try thjis…

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>                  
#include <SD.h>                  // SD card
#include "Wire.h"                // SD card

File myFile;
char filename[] = "Testfile.CSV";

#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

const int chipSelect = 4;

float tempC, Temp01, Temp02, Temp03, Temp04, Temp05, Temp06, Temp07, Temp08, Temp09, Temp10;   

byte Probe01[8] = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
byte Probe02[8] = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
byte Probe03[8] = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
byte Probe04[8] = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
byte Probe05[8] = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
byte Probe06[8] = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
byte Probe07[8] = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
byte Probe08[8] = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
byte Probe09[8] = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
byte Probe10[8] = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };


// Define the strings for our datastream IDs
char sensorId01[] = "Probe01";
char sensorId02[] = "Probe02";
char sensorId03[] = "Probe03";
char sensorId04[] = "Probe04";
char sensorId05[] = "Probe05";
char sensorId06[] = "Probe06";
char sensorId07[] = "Probe07";
char sensorId08[] = "Probe08";
char sensorId09[] = "Probe09";
char sensorId10[] = "Probe10";

void setup() { 
  Wire.begin();
  Serial.begin(9600);

  delay(300);//Wait for newly restarted system to stabilize

  Serial.print("Initializing");
  delay(2000);

  pinMode(10, OUTPUT);

 if (!SD.begin(chipSelect)) 
  {
  Serial.print("failed!");
    delay (2000);
    return;
  }
  Serial.println("init. OK!");

  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
}

void loop() {
  //get the values from the DS8B20's 
  sensors.requestTemperatures();
  
  Serial.print(Temp01);
  Serial.print(" ,  ");
  Serial.print(Temp02);
  Serial.print(" ,  ");
  Serial.print(Temp03);
  Serial.print(" ,  ");
  Serial.println(Temp04);
  
      myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(Temp01);
  myFile.print(",");
  myFile.print(Temp02);
  myFile.print(",");
  myFile.print(Temp03);
  myFile.print(",");
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
 
  delay(850);
}  // loop ends here

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

Thanks Nick,

I had a look as well as loaded and ran the code you provided. It runs and creates an excel file and records 3 lines of data, all zero's.
I was wondering yesterday after many hours on this if the problem lies in creating data strings and converting them?
I was able to replicate what you showed at some stage yesterday creating the excel file but again no data.

The sensors appear to be still set up fine so cant see an issue with them atm.

Am thinking to post what I have from yesterday asking for help with strings and see if that gets a response. Will prob do after work today here.

Regards,

Wayne

tynawg9:
It runs and creates an excel file and records 3 lines of data, all zero's.

OK, what about the output to serial? Be assured, the code I originally posted is definitely kosher

I was wondering yesterday after many hours on this if the problem lies in creating data strings and converting them?

Definitely not. The only time you have to have anything to do with strings is when you are sending data to some programme that demands strings, and I only know of one such programme.

The sensors appear to be still set up fine so cant see an issue with them atm

This means wiring and correct addresses. You might try testing the system with just one sensor.

Hi and again thanks for your persistence in helping, it is much appreciated.

Just now the first thing I confirmed is the earlier code is getting the temperature sensor readings in degrees C and printing to serial port. The code follows. I have been thinking to return and work with this code as it is working, plus I can do the SD and create a csv file now. Just not yet able to print the temp to SD yet.

/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
  Connections:
  DS18B20 Pinout (Left to Right, pins down, flat side toward you)
  - Left   = Ground
  - Center = Signal (Pin 2):  (with 3.3K to 4.7K resistor to +5 or 3.3 )
  - Right  = +5 or +3.3 V

   Questions: terry@yourduino.com 
   V1.01  01/17/2013 ...based on examples from Rik Kretzinger
   
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
DeviceAddress Probe02 = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
DeviceAddress Probe03 = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
DeviceAddress Probe04 = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
DeviceAddress Probe05 = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
DeviceAddress Probe06 = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
DeviceAddress Probe07 = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
DeviceAddress Probe08 = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
DeviceAddress Probe09 = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
DeviceAddress Probe10 = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };



void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(3000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
 
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();
   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();
  
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();
  
  Serial.print("Probe 06 temperature is:   ");
  printTemperature(Probe06);
  Serial.println();

  Serial.print("Probe 07 temperature is:   ");
  printTemperature(Probe07);
  Serial.println();
 
  Serial.print("Probe 08 temperature is:   ");
  printTemperature(Probe08);
  Serial.println();
   
  Serial.print("Probe 09 temperature is:   ");
  printTemperature(Probe09);
  Serial.println();
  
  Serial.print("Probe 10 temperature is:   ");
  printTemperature(Probe10);
  Serial.println();
   
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   //Serial.print(" F: ");
  // Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

I tried to post a screen shot of results printed to serial port but unable. The card SD initialises and 10 sensors are found on the bus and all temperatures are printed to serial port so not and address or wiring issue. I have left everything set up much to my long suffering wife’s disgust so can simply run and re run etc. I am a mature student and uni just finished leaving time ti fill.

I had been asking the Google god for code and a lot referenced data strings hence my thoughts there.

The three outputs to serial are also all zero’s. I would post but limitation on size of post prevents this but I am about to check again and will reply again to this post.

Regards,

Wayne

Just to confirm I have run the code posted yesterday and it does print to serial port but again zero's, and also creates the excel file with same data as zero's.
Serial port has 4 lines where as the excel file has 3!

Nick this is the 3rd reply today so if you have time please see the others for context.

I have run the alternative code based on your first reply which I tried to adapt. I have just run it and it initialised the SD and prints to serial port accross one line, due to altering the print command, all 10 temperature sensor readings.

This code follows,

/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
  Connections:
  DS18B20 Pinout (Left to Right, pins down, flat side toward you)
  - Left   = Ground
  - Center = Signal (Pin 2):  (with 3.3K to 4.7K resistor to +5 or 3.3 )
  - Right  = +5 or +3.3 V

   Questions: terry@yourduino.com 
   V1.01  01/17/2013 ...based on examples from Rik Kretzinger
   
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>

#include <SD.h>

#include <SPI.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

const int chipSelect = 4;

/*-----( Declare Variables )-----*/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
DeviceAddress Probe02 = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
DeviceAddress Probe03 = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
DeviceAddress Probe04 = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
DeviceAddress Probe05 = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
DeviceAddress Probe06 = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
DeviceAddress Probe07 = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
DeviceAddress Probe08 = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
DeviceAddress Probe09 = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
DeviceAddress Probe10 = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };



void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
  //while (!serial){
  //  ; // wait for serial port to connect. Needed for Leonardo only.
  //}
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  Serial.print("Initialising SD card...");
  // make sure that the default chip select pin is set to 
  // output, even if you dont use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialised:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // Dont do anything more:
    return;
  }
  Serial.println("Card Initialised.");
  
  
  
  
  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  // make a string for assembling the data to log:
  String dataString = "";
  // read sensors and append to the string:
  for (int digitalPin = 2; digitalPin < 3; digitalPin++)
  {
    int sensor = digitalRead(digitalPin);
    dataString += String(sensor);
    if (digitalPin < 2)
                      {
                      dataString += ",";
                      }
  }
  delay(3000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print(" Probe 01:   "); //Will print accross the line i.e. //Serial.print();
  //Serial.print(" Probe 01:   "); was changed to Serial.print(""); and results in just the temperature value being printed.
   printTemperature(Probe01);
    //The code below tells it to print a line then go down to next line.
  //Serial.println();
   

  Serial.print(" Probe 02:   ");
  printTemperature(Probe02);
  //Serial.println();
 
  Serial.print(" Probe 03:   ");
  printTemperature(Probe03);
 //Serial.println();
   
  Serial.print(" Probe 04:   ");
  printTemperature(Probe04);
  //Serial.println();
  
  Serial.print(" Probe 05:   ");
  printTemperature(Probe05);
  //Serial.println();
  
  Serial.print(" Probe 06:   ");
  printTemperature(Probe06);
  //Serial.println();

  Serial.print(" Probe 07:   ");
  printTemperature(Probe07);
  //Serial.println();
 
  Serial.print(" Probe 08:   ");
  printTemperature(Probe08);
  //Serial.println();
   
  Serial.print(" Probe 09:   ");
  printTemperature(Probe09);
  //Serial.println();
  
  Serial.print(" Probe 10:   ");
  printTemperature(Probe10);
  Serial.println();
  
  // Open the file. Note only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  
  // If the file is available, write to it:
  if (dataFile) 
              { 
               dataFile.println (dataString);
               dataFile.close();
               // Print to the serial port too:
               //Serial.println(dataString);
              }
               // If the file isn't open, pop up an error:
               else {
                 Serial.println("Error opening datalog.txt");
               //}
              }   
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   //Serial.print("C: ");
   Serial.print(tempC);
   //Serial.print(" F: ");
  // Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

Hi Nick or anyone who may have a suggestion!

The code below prints all 10 temperature sensors to the serial port also confirmed by randomly touching different ones and seeing the temperature change.

I tested file CSV is created logging 3 excel cells of data but all zero’s every few seconds as per the code.

I tested the creation of the excel file by running with no SD which did not work and deleting the excel file on the SD and running again a few times to confirm a new file is being created, it seems to be doing fine with that!

The code below feels more comfortable as opposed to the code using bytes.

So lastly it appears the last obstacle is in getting the temperature sensor data to print to the SD card CSV file!

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>                  
#include <SD.h>

File myFile;
char filename[] = "Testfile.CSV";

#define ONE_WIRE_BUS_PIN 2
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

const int chipSelect = 4;

float tempC, Temp01, Temp02, Temp03, Temp04, Temp05, Temp06, Temp07, Temp08, Temp09, Temp10;

DeviceAddress Probe01 = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
DeviceAddress Probe02 = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
DeviceAddress Probe03 = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
DeviceAddress Probe04 = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
DeviceAddress Probe05 = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
DeviceAddress Probe06 = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
DeviceAddress Probe07 = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
DeviceAddress Probe08 = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
DeviceAddress Probe09 = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
DeviceAddress Probe10 = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };



void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
    delay(300);//Wait for newly restarted system to stabilize
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
    Serial.print("Initializing");
  delay(2000);

  pinMode(10, OUTPUT);

 if (!SD.begin(chipSelect)) 
  {
  Serial.print("failed!");
    delay (2000);
    return;
  }
  Serial.println("  init. OK!");

  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(3000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
 
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();
   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();
  
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();
  
  Serial.print("Probe 06 temperature is:   ");
  printTemperature(Probe06);
  Serial.println();

  Serial.print("Probe 07 temperature is:   ");
  printTemperature(Probe07);
  Serial.println();
 
  Serial.print("Probe 08 temperature is:   ");
  printTemperature(Probe08);
  Serial.println();
   
  Serial.print("Probe 09 temperature is:   ");
  printTemperature(Probe09);
  Serial.println();
  
  Serial.print("Probe 10 temperature is:   ");
  printTemperature(Probe10);
  Serial.println();
  
        myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(Temp01);
  myFile.print(",");
  myFile.print(Temp02);
  myFile.print(",");
  myFile.print(Temp03);
  myFile.print(",");
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
  
   
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   //Serial.print(" F: ");
  // Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

The issue is that you never assign anything to any of your Temp01 - Temp10 variables, so when you write them to the SD card, they are always zero.

Thanks for taking the time to reply, much appreciated,, but the assignment of Temp01 etc was the last advice received and not understood so agree but am not sufficiently experienced with code to rectify. If you could expand that would be great as have tried putting in Probe01 etc but not to any success.

Regards,

Wayne

Here's an ugly way to do it:
Change this:

float tempC = sensors.getTempC(deviceAddress);

To this:

tempC = sensors.getTempC(deviceAddress);

And change each of these:

  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

To

  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();
  Temp01=tempC;

Changing out Temp01 in each case to match which ever probe number you're looking at.

Thank you! I will chew over this over the next day or so and apply then run changes to see how it changes.

The code I put up works to date, to a point, and your suggestions I hope , get it past the sticking point.

Regards,

Wayne

Just make the changes as given to start with (in a new copy of your sketch for preference), forget the other sensors. You should immediately see Temp01 data instead of zeroes in your csv file. Once that hurdle is behind you, you can fix the rest of it at your leisure.

Given the level of difficulty you're having, this is premature advice I think, but at some point you should really read up on arrays. Any time you have variables called Thing01, Thing02... it's screaming: ARRAYS!

IT WORKED!!!
I tried a few different things this afternoon based on the last suggestion from wildbill which did not work, BUT, then I realised the code I was working with was from yesterday afternoon earlier which had not saved the changes I made. I then copied the code I posted and made the changes…IT WORKED!!! well with some more tweaking.

Thank you wildbill and Nick for taking the time to assist!

Next I will be adding humidity, RTC, controlling devices etc so hope for more input!

Working code below for 10 daisy chained DS18B20 Temperature sensors to SD card.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>                  
#include <SD.h>

File myFile;
char filename[] = "Testfile.CSV";

#define ONE_WIRE_BUS_PIN 2
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

const int chipSelect = 4;

float tempC, Temp01, Temp02, Temp03, Temp04, Temp05, Temp06, Temp07, Temp08, Temp09, Temp10;

DeviceAddress Probe01 = { 0x28, 0x27, 0x26, 0x51, 0x05, 0x00, 0x00, 0x2B }; 
DeviceAddress Probe02 = { 0x28, 0x1A, 0x9B, 0x40, 0x05, 0x00, 0x00, 0x98 };
DeviceAddress Probe03 = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
DeviceAddress Probe04 = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
DeviceAddress Probe05 = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
DeviceAddress Probe06 = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 }; 
DeviceAddress Probe07 = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
DeviceAddress Probe08 = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
DeviceAddress Probe09 = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
DeviceAddress Probe10 = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };



void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);
    delay(300);//Wait for newly restarted system to stabilize
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
    Serial.print("Initializing");
  delay(2000);

  pinMode(10, OUTPUT);

 if (!SD.begin(chipSelect)) 
  {
  Serial.print("failed!");
    delay (2000);
    return;
  }
  Serial.println("  init. OK!");

  
  // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(3000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();
  Temp01 = tempC;

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
  Temp02 = tempC;
 
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();
  Temp03 = tempC;
   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();
  Temp04 = tempC;
  
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();
  Temp05 = tempC;
  
  Serial.print("Probe 06 temperature is:   ");
  printTemperature(Probe06);
  Serial.println();
  Temp06 = tempC;

  Serial.print("Probe 07 temperature is:   ");
  printTemperature(Probe07);
  Serial.println();
  Temp07 = tempC;
 
  Serial.print("Probe 08 temperature is:   ");
  printTemperature(Probe08);
  Serial.println();
  Temp08 = tempC;
   
  Serial.print("Probe 09 temperature is:   ");
  printTemperature(Probe09);
  Serial.println();
  Temp09 = tempC;
  
  Serial.print("Probe 10 temperature is:   ");
  printTemperature(Probe10);
  Serial.println();
  Temp10 = tempC;
  
        myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(Temp01);
  myFile.print(",");
  myFile.print(Temp02);
  myFile.print(",");
  myFile.print(Temp03);
  myFile.print(",");
  myFile.print(Temp04);
  myFile.print(",");
  myFile.print(Temp05);
  myFile.print(",");
  myFile.print(Temp06);
  myFile.print(",");
  myFile.print(Temp07);
  myFile.print(",");
  myFile.print(Temp08);
  myFile.print(",");
  myFile.print(Temp09);
  myFile.print(",");
  myFile.print(Temp10);
  myFile.print(",");
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
  
   
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   //Serial.print(" F: ");
  // Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

Thanks for sharing this code! I just started my datalogger with two DS18x20 sensors (I just commented the rest of the code).
The world of sensing and analysing on spreadsheet is now open to me! :smiley:

I added the RTC functionnality, here is my code:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>                 
#include <SD.h>
#include <RTClib.h>
#include <TimeLib.h>

File myFile;
char filename[] = "DATA.CSV";

#define ONE_WIRE_BUS_PIN 4
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

RTC_DS1307 rtc;

const int chipSelect = 10;

float tempC, Temp01, Temp02, Temp03, Temp04, Temp05, Temp06, Temp07, Temp08, Temp09, Temp10;

DeviceAddress Probe01 = { 0x10,0xEF,0x0F,0x24,0x01,0x08,0x00,0x3A};
DeviceAddress Probe02 = { 0x28,0xD9,0x97,0x1F,0x00,0x00,0x80,0x84};
DeviceAddress Probe03 = { 0x28, 0x06, 0x2A, 0x41, 0x05, 0x00, 0x00, 0xB3 };
DeviceAddress Probe04 = { 0x28, 0xDB, 0xD9, 0x50, 0x05, 0x00, 0x00, 0x62 };
DeviceAddress Probe05 = { 0x28, 0xED, 0x1C, 0x51, 0x05, 0x00, 0x00, 0x42 };
DeviceAddress Probe06 = { 0x28, 0x16, 0xC5, 0x40, 0x05, 0x00, 0x00, 0xD2 };
DeviceAddress Probe07 = { 0x28, 0xA4, 0x1B, 0x41, 0x05, 0x00, 0x00, 0xC8 };
DeviceAddress Probe08 = { 0x28, 0xF0, 0xDC, 0x40, 0x05, 0x00, 0x00, 0xC6 };
DeviceAddress Probe09 = { 0x28, 0xC1, 0x94, 0x40, 0x05, 0x00, 0x00, 0xCB };
DeviceAddress Probe10 = { 0x28, 0xB5, 0xE6, 0x40, 0x05, 0x00, 0x00, 0x61 };



void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);Serial.println("--- Serial started ---");
    delay(300);//Wait for newly restarted system to stabilize
  
   if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
 
    Serial.print("Initializing");
  delay(2000);

  pinMode(10, OUTPUT);

if (!SD.begin(chipSelect))
  {
  Serial.print("failed!");
    delay (2000);
    return;
  }
  Serial.println("  init. OK!");

 
  // Initialize the Temperature measurement library
  sensors.begin();
 
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  sensors.setResolution(Probe03, 12);
  sensors.setResolution(Probe04, 12);
  sensors.setResolution(Probe05, 12);
  sensors.setResolution(Probe06, 12);
  sensors.setResolution(Probe07, 12);
  sensors.setResolution(Probe08, 12);
  sensors.setResolution(Probe09, 12);
  sensors.setResolution(Probe10, 12);

}//--(end setup )---

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(5000);
  Serial.println();
  Serial.print("Date: ");
  Serial.println(get_RTC());

  Serial.println();
  Serial.print("Number of Devices found on bus = "); 
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... "); 
  Serial.println();   
 
  // Command all devices on bus to read temperature 
  sensors.requestTemperatures(); 
 
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();
  Temp01 = tempC;

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
  Temp02 = tempC;
/*
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();
  Temp03 = tempC;
   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();
  Temp04 = tempC;
 
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();
  Temp05 = tempC;
 
  Serial.print("Probe 06 temperature is:   ");
  printTemperature(Probe06);
  Serial.println();
  Temp06 = tempC;

  Serial.print("Probe 07 temperature is:   ");
  printTemperature(Probe07);
  Serial.println();
  Temp07 = tempC;

  Serial.print("Probe 08 temperature is:   ");
  printTemperature(Probe08);
  Serial.println();
  Temp08 = tempC;
   
  Serial.print("Probe 09 temperature is:   ");
  printTemperature(Probe09);
  Serial.println();
  Temp09 = tempC;
 
  Serial.print("Probe 10 temperature is:   ");
  printTemperature(Probe10);
  Serial.println();
  Temp10 = tempC;
 */
   Serial.println("Storing data to SD card... "); 
        myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(get_RTC());
  myFile.print(",");
  myFile.print(Temp01);
  myFile.print(",");
  myFile.print(Temp02);
 /* myFile.print(",");
  myFile.print(Temp03);
  myFile.print(",");
  myFile.print(Temp04);
  myFile.print(",");
  myFile.print(Temp05);
  myFile.print(",");
  myFile.print(Temp06);
  myFile.print(",");
  myFile.print(Temp07);
  myFile.print(",");
  myFile.print(Temp08);
  myFile.print(",");
  myFile.print(Temp09);
  myFile.print(",");
  myFile.print(Temp10);
  myFile.print(",");*/
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
  Serial.println("Data stored! ");  
   
 
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
// =========================================================================================================
String get_RTC() {
  String RTC_String;
  DateTime now = rtc.now();
   
  RTC_String+=now.day();RTC_String+='/'; RTC_String+=now.month();RTC_String+='/'; RTC_String+=now.year();RTC_String+=", ";
  if (now.hour()<10) RTC_String+='0'; RTC_String+=now.hour(); RTC_String+=':';
  if (now.minute()<10) RTC_String+='0'; RTC_String+=now.minute(); RTC_String+=':';
  if (now.second()<10) RTC_String+='0'; RTC_String+=now.second();

    return RTC_String;
}
// =========================================================================================================
void printTemperature(DeviceAddress deviceAddress)
{

tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00)
   {
   Serial.print("Error getting temperature  ");
   }
   else
   {
   Serial.print("C: ");
   Serial.print(tempC);
   //Serial.print(" F: ");
  // Serial.print(DallasTemperature::toFahrenheit(tempC));
   }
}// End printTemperature
//*********( THE END )***********

Ludovic

I think you can streamline that somewhat. If you want 10 bit resolution, you are not doing it, you are setting it for 12 bit. If you want 12 bit, you don’t need to write it, you get it by default. I think the returns can be simplified.

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

byte Thermo1[8] = {0x28, 0x39, 0xFD, 0x50, 0x04, 0x00, 0x00, 0X69};
byte Thermo2[8] = {0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};

float tempC,Temp1,Temp2; 

void setup(){
  Serial.begin(9600);
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures();  // call readings from the addresses
  Temp1 = sensorValue(Thermo1);
  Temp2 = sensorValue(Thermo2); 

  Serial.print("      Temp1 = ");
  Serial.print(Temp1);
  Serial.print("      Temp2 = ");
  Serial.println(Temp2);

  delay(1000);
}

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

I just wanted to thank all of you. I have been struggling through figuring out a very similar project and following this discussion and then using some of the code was the breakthrough finally! Thank you!!!