Using the DS1302

Hello, I am working on an arduino project using the DS1302 clock module and a 16x2 lcd screen. I programmed the arduino to read the clock data then output it to the LCD screen, but it now only shows a string of zeros without showing the time. I have been using this library here to program the clock:

http://www.henningkarlsen.com/electronics/library.php?id=5

Could anyone point me in the right direction or tell me why it is doing this?

This is the code I was using:

//for this clock, RST = CE pin, DAT = IO pin, and SCLK = CLK pin

// include the library code:
#include <LiquidCrystal.h>
#include <DS1302.h>


DS1302 rtc(8, 9, 10);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup() {
  // set up the LCD's number of columns and rows: 
  
  lcd.begin(16, 2);
  
  
  rtc.halt(false);
  
  rtc.writeProtect(false);
  
  rtc.setDOW(WEDNESDAY); // Set Day-of-Week to FRIDAY
  
  rtc.setTime(11, 32, 00); // Set the time to 12:00:00 (24hr format)
  
  rtc.setDate(23, 7, 2014); // Set the date to August 6th, 2010


}

void loop() {
  lcd.setCursor(0,1);
  
  lcd.print(rtc.getTimeStr());
  
  
  
 delay(1000);
 
}

The code seems good to me, so, I think that the problem is on the connections.

Can you post some pictures of the connections?

PS.: edit the post and add the code tags to the code (select the code and press the button ' # ' of the tool bar)

Here are the photos of my project. I included a second one as a closeup of some of the connections on the lcd

Does your sketch run as intended when you use serial output instead of the lcd?

It did. I tested it with a sketch that outputted to serial monitor before trying to use an lcd screen.

The string of zeros is an unusual error condition with properly running code and an improperly wired lcd.

Can you run a simple "Hello World" sketch on the lcd as it is now wired?

Found the problem for the 0 string, it was a code error on my part. Correcting makes little difference, and now it flashes back and forth from the time (which is not even correct), to the zero string. Attached is a video of what I am describing.

IMG_1245.mov (1.25 MB)

Can you please post your current code using code tags?

I haven't been able to get at the library you are working with which has the rtc.getTimeStr() function. If serial.print accepts and prints out that function, lcd.print might not be able to do so. Perhaps you can try break the code down into simpler call for separate hour, minute, seconds and pass these to the lcd.

There is another DS1302 library on git hub GitHub - msparks/arduino-ds1302: Arduino library for the DS1302 Real Time Clock chip, and you might try using that one.

The seconds work OK? By seeing the video I've not sure.

EDIT: Did you try to way for longer than 1000ms? Did it work in the same way?

I found the problem, it turned out to be a connection problem. Apparently 5 volts is too much for this clock, as I discovered when connecting it to 3.3v, it worked perfectly! Thank you everybody for advice.

:smiley:

It did. I tested it with a sketch that outputted to serial monitor before trying to use an lcd screen.

I found the problem, it turned out to be a connection problem. Apparently 5 volts is too much for this clock, as I discovered when connecting it to 3.3v, it worked perfectly! Thank you everybody for advice.

So how did it work properly with the serial monitor?

The data I have seen on the DS1302 indicates that is should work at 5v. Do you have some sort of module with a 3.6v battery, or just the chip and a crystal oscillator? You might be able help others if you post some specifics of your setup.

The module includes a backup battery. Correct me if I wrong, but I think maybe the battery + USB power was too much for the clock.

It should have worked fine.

The chip may be some sort of cheapo clone and doesn't work properly. If the external Vcc is supposed to "trickle charge" the battery than I guess that's not going to happen.