problem with ds1307 shield and arduino ethernet shield

Hi i'm new in this forum and in the arduino world!
however i'd buy an arduino uno, an ethernet shield w5100 and a ds1307 module. When i use the rtc module with uno all works fine but if i add the ethernet shield the same code doesn't work. I use the standard time library founded in the arduino.cc site.

Someone can help me or have the same problem? Thanks

In order to get help, you are probably going to need to post the code you're using. It would also be helpful to know what shield you are using (where you bought it) and what ds1307 module you are using (where you bought it).

OK, frist of all: thank you for your reply!
the rtc module is an "Arduino Tiny RTC DS1307 Shield V2.0 Without DS18B20" that can be found on www.emartee.com.
the ethernet shield is "Ethernet Shield 05 for Arduino UNO, Mega, 1280, 2560, use w5100" found on ebay.

the code is very simple:

#include <Wire.h>

#include <Time.h>

#include <DS1307RTC.h>

time_t timeNow;

void setup() {

pinMode(4, OUTPUT);

digitalWrite(4, HIGH);

Serial.begin(9600);
}

void loop()
{

timeNow = (DS1307RTC::get());

Serial.print(day(timeNow));
Serial.print(":");
Serial.print(month(timeNow));
Serial.print(":");
Serial.print(year(timeNow));
Serial.println();

delay(100);

}

When the rtc module is connected only to the arduino uno, the code print the correct date but with ethernet shield the value is uncorrect.

time and date of the ds1307 was set frist.

thanks.

noone can help me????? :~

According to the schematics, it appears there is a pin conflict with the two devices on the A4 and A5 pins on that model ethernet shield (v5). It is the connector J2 that has the additional connections on the v5 ethernet shield. Those are the same pins used by the Wire library for TWI.

The ethernet shield version 6 does not have the A4 and A5 pin connections.

add: I would try some "pin bending" on the ethernet shield's A4 and A5 pins if it were mine. Then connect the RTC directly to the Arduino A4 and A5 pins.

Thank you for your suggestions!

I tried to link the rtc module directly to UNO board a5,a4, (a3 and a2 was used for supply voltage) this pins was bended and don't pass through the ethernet shield;
The ethernet shield was connected to the others pins of UNO;

the problem persists in the same way!!! =(

I can't understand how the ethernet shield can alterate the comunication "I2c" without the connection of a4 and a5 pins!! :fearful:

If you have another suggestion, please reply!

Otherwise , i think to change hardware to an "arduino ethernet" but at this point i don't know if the problem persist with s board!!
There is someone that have used an rtc module whit this board????

thanks a lot. XD

I also take the same problem: I can save data to SD into ethernet shield; however, when I reopen this file to send on FTP, the serial announce that it can not open the file. I think there is a trouble between I2C of RTC and SPI of ethernet shield, but I dont know why. Here is my code:

#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#define FTPWRITE
//const int chipSelect = 4;
const int ACSPin = A3; // Define analog input pin

File dataFile;
char fileName[13] = "datalog.csv"; // filename to save to

double Current;
const double StandbyCurrent = 0.01;
// *************************** this must be unique *******************************************
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// ************************* change to your server *******************************************
IPAddress server( 172, 23, 152, 2 );

EthernetClient client;
EthernetClient dclient;

char outBuf[128];
char outCount;

//************************************** Set up Function *************************************
void setup()
{
Serial.begin(9600);
while (!Serial) ; // wait for serial
//SPI.begin();
//SPI.setBitOrder(MSBFIRST);
//SPI.setDataMode(SPI_MODE0);
// initialize the SD card:
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);
// see if the card is present and can be initialized:
if (SD.begin(4))
{
Serial.println("SD initialized.");
/*
dataFile = SD.open(fileName, FILE_WRITE);
// open the file:
if (dataFile)
{
dataFile.print(" Status,Current,Date(dd/mm/yy),Time(hh:mm:ss)");
dataFile.println();
dataFile.close();
}
/
}
delay(2000);
// start the Ethernet connection:
if (Ethernet.begin(mac) != 0)
{
Serial.println("Success to configure Ethernet using DHCP");
}
// give the Ethernet shield a second to initialize:
digitalWrite(10,HIGH);
delay(2000);
// initial RTC
//SPI.setDataMode(SPI_MODE0);
setSyncProvider(RTC.get); // the function to get the time from the RTC
delay(2000);
}
//
******************************* Main Function***************************************************
void loop()
{
Current = currentSensor(analogRead(ACSPin));
if (Current > StandbyCurrent)
{
rtcsd();
delay(2000);
}
else
{

if(upload()) Serial.println(F("FTP OK"));
else Serial.println(F("FTP FAIL"));
delay(2000);
}
}

//***********************************************************************************************************

byte upload()
{
//SPI.setDataMode(SPI_MODE0);
#ifdef FTPWRITE
dataFile = SD.open(fileName,FILE_READ);
#else
SD.remove(fileName);
dataFile = SD.open(fileName,FILE_WRITE);
#endif

if(!dataFile)
{
Serial.println(F("SD open fail"));
return 0;
}

#ifndef FTPWRITE
if(!dataFile.seek(0))
{
Serial.println(F("Rewind fail"));
dataFile.close();
return 0;
}
#endif

Serial.println(F("SD opened"));

if (client.connect(server,21)) {
Serial.println(F("Command connected"));
}
else {
dataFile.close();
Serial.println(F("Command connection failed"));
return 0;
}

if(!eRcv()) return 0;

client.println(F("USER myuser"));

if(!eRcv()) return 0;

client.println(F("PASS mypassword"));

if(!eRcv()) return 0;

client.println(F("SYST"));

if(!eRcv()) return 0;

client.println(F("PASV"));

if(!eRcv()) return 0;

char *tStr = strtok(outBuf,"(,");
int array_pasv[6];
for ( int i = 0; i < 6; i++) {
tStr = strtok(NULL,"(,");
array_pasv = atoi(tStr);

  • if(tStr == NULL)*

  • {*

  • Serial.println(F("Bad PASV Answer")); *

  • }*

  • }*

  • unsigned int hiPort,loPort;*

  • hiPort = array_pasv[4] << 8;*

  • loPort = array_pasv[5] & 255;*

  • Serial.print(F("Data port: "));*

  • hiPort = hiPort | loPort;*

  • Serial.println(hiPort);*

  • if (dclient.connect(server,hiPort)) {*

  • Serial.println(F("Data connected"));*

  • }*

  • else {*

  • Serial.println(F("Data connection failed"));*

  • client.stop();*

  • dataFile.close();*

  • return 0;*

  • }*
    #ifdef FTPWRITE

  • client.print(F("STOR "));*

  • client.println(fileName);*
    #else

  • client.print(F("RETR "));*

  • client.println(fileName);*
    #endif

  • if(!eRcv())*

  • {*

  • dclient.stop();*

  • return 0;*

  • }*
    #ifdef FTPWRITE

  • Serial.println(F("Writing"));*

  • byte clientBuf[64];*

  • int clientCount = 0;*

  • while(dataFile.available())*

  • {*

  • clientBuf[clientCount] = dataFile.read();*

  • clientCount++;*

  • if(clientCount > 63)*

  • {*

  • dclient.write(clientBuf,64);*

  • clientCount = 0;*

  • }*

  • }*

  • if(clientCount > 0) dclient.write(clientBuf,clientCount);*
    #else

  • while(dclient.connected())*

  • {*

  • while(dclient.available())*

  • {*

  • char c = dclient.read();*

  • dataFile.write(c); *

  • Serial.write(c);*

  • }*

  • }*
    #endif

  • dclient.stop();*

  • Serial.println(F("Data disconnected"));*

  • if(!eRcv()) return 0;*

  • client.println(F("QUIT"));*

  • if(!eRcv()) return 0;*

  • client.stop();*

  • Serial.println(F("Command disconnected"));*

  • dataFile.close();*

  • Serial.println(F("SD closed"));*

  • return 1;*
    }
    byte eRcv()
    {

  • byte respCode;*

  • byte thisByte;*

  • while(!client.available()) delay(1);*

  • respCode = client.peek();*

  • outCount = 0;*

  • while(client.available())*

  • { *

  • thisByte = client.read(); *

  • Serial.write(thisByte);*

  • if(outCount < 127)*

  • {*

  • outBuf[outCount] = thisByte;*

  • outCount++; *

  • outBuf[outCount] = 0;*

  • }*

  • }*

  • if(respCode >= '4')*

  • {*

  • efail();*

  • return 0; *

  • }*

  • return 1;*
    }
    void efail()
    {

  • byte thisByte = 0;*

  • client.println(F("QUIT"));*

  • while(!client.available()) delay(1);*

  • while(client.available())*

  • { *

  • thisByte = client.read(); *

  • Serial.write(thisByte);*

  • }*

  • client.stop();*

  • Serial.println(F("Command disconnected"));*

  • dataFile.close();*

  • Serial.println(F("SD closed"));*
    }
    _//**************************************************************************** _
    void rtcsd()
    {

  • //SPI.setDataMode(SPI_MODE1);*

  • tmElements_t tm;*

  • RTC.read(tm);*

  • //SPI.setDataMode(SPI_MODE0);*

  • // open the file*

  • dataFile = SD.open(fileName, FILE_WRITE);*

  • // if the file is available, write to it:*

  • if (dataFile)*

  • {*

  • dataFile.print("ON ");*

  • dataFile.print(" , ");*

  • dataFile.print(Current);*

  • dataFile.print(" , "); *

  • dataFile.print(tm.Day);*

  • dataFile.print("/");*

  • dataFile.print(tm.Month);*

  • dataFile.print("/");*

  • dataFile.print(tmYearToCalendar(tm.Year));*

  • dataFile.print(" , ");*

  • if (tm.Hour <10) dataFile.print('0');*

  • dataFile.print(tm.Hour);*

  • dataFile.print(":");*

  • if (tm.Minute <10) dataFile.print('0');*

  • dataFile.print(tm.Minute);*

  • dataFile.print(":");*

  • dataFile.print(tm.Second); *

  • dataFile.println(" "); *

  • dataFile.close(); *

  • }*
    }
    //Calculate current and print current Function************************
    double currentSensor(int RawADC) {

  • int Sensitivity = 66; // mV/A*

  • double ZeroCurrentVcc = 2.5;*
    _ double SensedVoltage = RawADC * 0.0049;_

  • double Difference = SensedVoltage - ZeroCurrentVcc;*

  • double SensedCurrent = Difference / Sensitivity;*

  • return SensedCurrent; // Return the Current*
    }

@duytinvo: What Arduino are you using? If it is a Mega, you should be ok. If an Uno, you may be running out of SRAM. That will cause SD.open() to fail.

Try using the F() macro to keep those static strings in program memory. That will save you some SRAM.

    // change this
    Serial.println("SD initialized.");
    // to this
    Serial.println(F("SD initialized."));

And do the same to all the other static strings.

Oh, thanks SurferTim so much.

Yes, the project announce that can not open file and then FTP fail.Currently, I have use UNO board, but I also have MEGA one. So, I will try with MEGA.

You mean that the project can work right on UNO when I use F() function to reduce SRAM????

Maybe. If you can reduce the SRAM use down to where the Uno can handle it, it will.

Thanks SurferTim so much,

My project has worked well now. However, It can not run on the Uno because its sketch size ran out.hic.
So, I must buy the Mega.hihi.

I have a Mega for that reason. However, you can save some program memory by reducing the length of your static strings. Maybe you can recover enough memory to squeeze it into an Uno. For example

   // Change this
   Serial.println(F("Success to configure Ethernet using DHCP"));
   // to this
   Serial.println(F("DHCP ok"));

Hi, although this topic is very old, I’m seeing the question of NAD69YC:
arduino uno, an ethernet shield w5100 and a ds1307 module. When i use the rtc module with uno all works fine but if i add the ethernet shield the same code doesn't work. I use the standard time library founded in the arduino.cc site
don’t have a response.

After all this time I have the same problem and I try to resolve it but I don’t find a solution.

There is someone that know which is the way to conect an rduino uno,a ethernet shield and a RTC module???