how to connect RTC and SD card to data logger

Hi

I am trying to build a data logger with time stamp

the result should be a file like this “DD/MM/YYYY HH/MM/SS DATA1 DATA2 …”

I am using Arduino Uno with SparkFun DeadOn RTC Breakout - DS3234, Basic 16x2 Character LCD - Red on Black 5V and SparkFun microSD Shield.

and sampling the Data from A0

I try this sketch:

#include <SPI.h>

#include <SD.h>

#include <SparkFunDS3234RTC.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd( 2, 3, 5, 6, 7, 8);

void setup() {

SD.begin(4) ;

lcd.begin(16, 2);

#define DS13074_CS_PIN 10

SPI.setDataMode(SPI_MODE1);

rtc.begin(DS13074_CS_PIN);

rtc.set24Hour();

lcd.clear();

lcd.setCursor(0, 0);

lcd.print (“DATA LOGGER”);

lcd.setCursor(0, 1);

lcd.print (“Ready To Start”);

delay (3000);

lcd.clear();

lcd.setCursor(0, 0);

}

void loop() {

float sddata ;

String dnt ;

String dntlcd ;

String alog0 ;

String alog0lcd ;

lcd.clear();

lcd.setCursor(0, 1);

rtc.update() ;

dnt=“” ;

dntlcd=“” ;

//build Date And Time Strings dateandtime for sd card and dtlcd to display on lcd

dnt=dnt + String(rtc.date()) + “/” + String(rtc.month()) + “/” + String(rtc.year()) + " " + String(rtc.hour()) + “:” ;

if (rtc.minute() < 10)

dnt=dnt + “0”; // Print leading ‘0’ for minute

dnt=dnt + String(rtc.minute()) + “:” ; // Print minutes

if (rtc.second() < 10)

dnt=dnt + “0”; // Print leading ‘0’ for minute

dnt=dnt + String(rtc.second()) + " " ; // Print secondes

dntlcd=dntlcd + String(rtc.date()) + “/” + String(rtc.month()) + " " + String(rtc.hour()) + “:” ;

if (rtc.minute() < 10)

dntlcd=dntlcd + “0”; // Print leading ‘0’ for minute

dntlcd=dntlcd + String(rtc.minute()) + “:” ; // Print minutes

if (rtc.second() < 10)

dntlcd=dntlcd + “0”; // Print leading ‘0’ for minute

dntlcd=dntlcd + String(rtc.second()) + " " ; // Print secondes

// Finsh building tame and date Strings and building date strings

// read sensor date

// read the input on analog pin 0:

float sensorValue0 = analogRead(A0);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

float voltage0 = sensorValue0 * (5.0 / 1023.0);

alog0=String(voltage0,4) ;

alog0lcd=“s1: " + alog0 + " Volt”;

//finish the data strings

//writing to SD

// Open DataFile On SD:

File myFile;

myFile=SD.open(“data.txt”, FILE_WRITE);

myFile.println(dnt+" "+alog0);

myFile.close();

//finish wring to SD

//printing to lcd

lcd.clear();

lcd.setCursor(0, 0);

lcd.print (dntlcd);

lcd.setCursor(0, 1);

lcd.print (alog0lcd);

delay (1000);

}

But the RTC and The SD does not work together without the sd the time is accurate and without the time the i can Write to the SD

together (as in the sketch) the time is strange and it does not write to the sd

Can anyone help me?

what am i done wrong?

thank you