Go Down

Topic: Problem with DS1302 real time clock (Read 438 times) previous topic - next topic

Luca02

Problem
Hi.

I connected a DS1302 as suggested in almoust all the available documentation.
I tried to compile the examples but I got some errors like this:

Quote
Arduino\libraries\DS1302\examples\DS1302_RAM_Demo\DS1302_RAM_Demo.pde: In function 'void loop()':
and then a long list of errors:

Quote
C:\Users\Luca\Documents\Arduino\libraries\DS1302\examples\DS1302_RAM_Demo\DS1302_RAM_Demo.pde:52:30: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   bufferDump("Initial buffer");
etc....

I don't understand what is the problem.
I am using an Arduino UNO that doesn't have any other mulfunctioning.

Any suggestion would be very appreciated.
Thanks

Regards

el_supremo

That's not an error, it's a warning. It says so. Ignore it or put (char *) in front of the strings that it complains about.

Pete
Don't send me technical questions via Private Message.

Luca02

Thank you very much for your answer.
You are right: the sketch is downloaded anyway. But the examples don't work  :smiley-confuse:

I got random results like these:

Quote
oday is the 0. day of xxxxxxxxx in the year 2000.
It is the 0. day of the week (counting monday as the 1th), and it has passed 0 hour(s), 0 minute(s) and 0 second(s) since midnight.
  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
Today is the 41. day of January in the year 2023.
It is the 1. day of the week (counting monday as the 1th), and it has passed 8 hour(s), 23 minute(s) and 1 second(s) since midnight.
  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
Today is the 0. day of xxxxxxxxx in the year 2000.
It is the 0. day of the week (counting monday as the 1th), and it has passed 0 hour(s), 0 minute(s) and 0 second(s) since midnight.
  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

pylon

Post the failing code! And provide a link to the library (DS1302) you're using as it's not available in the Library Manager of the IDE.

Luca02

Thanks for your help.
This is the code:

Quote
// DS1302_Serial_Hard
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS1302-library to
// retrieve time- and date-date for you to manipulate.
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

// Init a Time-data structure
Time t;

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
 
  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  //rtc.setTime(18, 26, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(3, 11, 2017);   // Set the date to August 6th, 2010
}

void loop()
{
  // Get data from the DS1302
  t = rtc.getTime();
 
  // Send date over serial connection
  Serial.print("Today is the ");
  Serial.print(t.date, DEC);
  Serial.print(". day of ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" in the year ");
  Serial.print(t.year, DEC);
  Serial.println(".");
 
  // Send Day-of-Week and time
  Serial.print("It is the ");
  Serial.print(t.dow, DEC);
  Serial.print(". day of the week (counting monday as the 1th), and it has passed ");
  Serial.print(t.hour, DEC);
  Serial.print(" hour(s), ");
  Serial.print(t.min, DEC);
  Serial.print(" minute(s) and ");
  Serial.print(t.sec, DEC);
  Serial.println(" second(s) since midnight.");

  // Send a divider for readability
  Serial.println("  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -");
 
  // Wait one second before repeating :)
  delay (1000);
}
Actually I don't know where I downloaded the library !!!

pylon

That's not the code that produced the output in post #2! And use code tags (the </> button in the editor), no quote tags.

As the hardware is relevant, post a wiring diagram of your setup.

Luca02

Tomorrow I'll draw a sketch of the hardware connections.
Regarding the code, there are 4 examples that probably came with the library. Two of them use hardware that I don't have (like a display). The other two examples provide outputs that look random. I suppose that the output in post #2 is the one related to the code in the other post. Why do you think that it is not so ?

Luca02

I tried also with an Arduino Mega but the output is the same and it's the output of the code I posted before.
Regarding the hardware connections, I realize that my DS1302 has a different naming for the pins.
They are called: Vcc, GND, CLK, DAT and RST.

I connected Vcc and GND at the Arduino output 5V and GND.

Then I connected CLK to pin 4,
DAT to pin 3
and
RST to pin 2.

In the exampe code I see that the pins ( apart from Vcc and GND) are named:
CE,  I/O and SCLK.

Maybe my connections are wrong !

pylon

Quote
I tried also with an Arduino Mega but the output is the same and it's the output of the code I posted before.
Did you edit that post? I could swear that I saw another code when I wrote my reply... Might be me seeing ghost images. Please excuse.

Anyway, the hardware seems not to work.

Quote
Then I connected CLK to pin 4,
DAT to pin 3
and
RST to pin 2.

In the exampe code I see that the pins ( apart from Vcc and GND) are named:
CE,  I/O and SCLK.
RST is CE, I/O is DAT and CLK is SCLK, so these pins seems OK.

As you have names on the pins it seems that you don't use the DS1302 chip but some breakout. Please post a link to that breakout as the rest of the components may influence the functionality.

Luca02

Hi,
this is the link to the site where I found the information:
Quote
http://www.adrirobot.it/rtc_module/rtc_module_with_ds1302.htm
Thanks

edugimeno

Don't trust that RTC...I had a bunch of them for a real application and they all failed to keep the time after some days. Use DS3231 instead, same wiring, same code and libraries, but MUCH more accurate

pylon

Hi,
this is the link to the site where I found the information:
Thanks
Is your module exactly looking like that one? In this case it doesn't include pull-ups for the I2C signal lines. The internal ones that are activated by the Wire library are quite weak and usually are not efficient enough for external wires. Try 4k7 pull-ups for SDA and SCL.

Luca02

Hi,
I would try with the pull-up resistors but my pins are named CLK, DAT and RST.
So I don't know where to connect the resistors.

Regards.
Thanks

pylon

Excuse me, I was wrong, that are not I2C lines. My mind was in the wrong context when I wrote my lines.

hammy

I'd agree the ds3231 is a much better clock , but shouldn't be the cause of your errors
Btw - did you set the time in your clock by uncommebting the setup lines ??

Go Up