my project uses a arduino Uno with xbee , a memory card and a RTC DS1307, when my code is running the files are not opening and when I remove the RTC +5v pin I can open the file and write into it
,cant we connect three serial devices to arduino please help me, the below is my code
#include <SPI.h>
#include<SD.h>
#include<SoftwareSerial.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
File file;
int CS_PIN=10;
SoftwareSerial chat(2,3); //Rx,Tx
void setup()
{
Serial.begin(9600);
chat.begin(9600);
delay(1000);
initializeSD();
delay(1000);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(2015,6,2,9,31,0));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
delay(1000);
}
void loop()
{
int x;
DateTime now = rtc.now();
delay(1000);
createFile("stack.txt");
]
if (chat.available()>0)
{
while (chat.available()>0)
{
x=chat.read();
Serial.println(x);
delay(1000);
switch(x)
{
case 49:
{
Serial.println(file);
// if the file is available, write to it:
if (file==0) {
file.println(" Mrs.K.HARIPRIYA EMBEDED SYSTEMS ");
file.close();
// print to the serial port too:
Serial.println(" Mrs.K.HARIPRIYA EMBEDED SYSTEMS ");
}
break;
}
case 50:
{
// if the file is available, write to it:
if (file) {
file.println(" Mrs.N.Parijatham CONTROL SYSTEMS");
file.close();
// print to the serial port too:
Serial.println(" Mrs.N.Parijatham CONTROL SYSTEMS");
}
break;
}
case 51:
{
// if the file is available, write to it:
if (file) {
file.println(" Mr.K.Praveen DSP ");
file.close();
// print to the serial port too:
Serial.println(" Mr.K.Praveen DSP ");
}
break;
}
case 52:
{
// if the file is available, write to it:
if (file) {
file.println(" Mr.TSRCH Murthy DC ");
file.close();
// print to the serial port too:
Serial.println(" Mr.TSRCH Murthy DC ");
}
break;
}
case 53:
{
// if the file is available, write to it:
if (file) {
file.println(" Mr.BALA KRISHNA OOPS ");
file.close();
// print to the serial port too:
Serial.println(" Mr.BALA KRISHNA OOPS ");
}
break;
}
case 73:
{
Serial.println(file);
// if the file is available, write to it:
if (file) { Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
file.print(now.year(), DEC);
file.print('/');
file.print(now.month(), DEC);
file.print('/');
file.print(now.day(), DEC);
file.print(' ');
file.print(now.hour(), DEC);
file.print(':');
file.print(now.minute(), DEC);
file.print(':');
file.print(now.second(), DEC);
file.println();
file.close();
// print to the serial port too:
}
break;
}
case 69:
{
// if the file is available, write to it:
if (file) {
file.print(now.hour(), DEC);
file.print(':');
file.print(now.minute(), DEC);
file.print(':');
file.print(now.second(), DEC);
file.println();
file.close();
// print to the serial port too:
}
break;
}
}
}
}}
void initializeSD()
{
Serial.println("Initializing SD card...");
pinMode(CS_PIN, OUTPUT);
if (SD.begin())
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
}
int createFile(char filename[])
{
file = SD.open(filename, FILE_WRITE);
if (file)
{
Serial.println("File created successfully.");
return 1;
} else
{
Serial.println("Error while creating file.");
return 0;
}
}