Go Down

Topic: hard time to use a DS1302 (Read 5423 times) previous topic - next topic


Jan 12, 2013, 08:31 pm Last Edit: Jan 12, 2013, 08:39 pm by erwanl Reason: 1
Hi There,

I bought a DS1302 (see here : http://dx.com/p/ds1302-real-time-clock-module-with-battery-cr2032-126453 ).
I use this piece of code : http://playground.arduino.cc/Main/DS1302 (or also a library from here : https://github.com/msparks/arduino-ds1302/blob/master/DS1302.h).

However, I am getting wierd result.
The time I see is not one the one I read afterwards.
When setting time for exemple, it affects the date...

Here below my sketch.

Anyone has ideas?

I get this as output : "08:17:09 21.09.2001 Sun" whereas my code sets :   rtc.setDOW(SATURDAY);   rtc.setTime(16, 1, 3);    rtc.setDate(7, 9, 13);  


Code: [Select]

// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
// I assume you know how to connect the DS1302 and LCD.
// DS1302:  CE pin    -> Arduino Digital 12
//          I/O pin   -> Arduino Digital 11
//          SCLK pin  -> Arduino Digital 10
// LCD:     DB7       -> Arduino Digital 7
//          DB6       -> Arduino Digital 6
//          DB5       -> Arduino Digital 5
//          DB4       -> Arduino Digital 4
//          E         -> Arduino Digital 8
//          RS        -> Arduino Digital 9

#include <LiquidCrystal.h>
#include <DS1302.h>

// Init the DS1302
//DS1302(ce, data, clock);
DS1302 rtc(12,11,10);

// Init the LCD
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

void set_time() {
 rtc.setDOW(SATURDAY);    //
 rtc.setTime(16, 1, 3);     //
 rtc.setDate(7, 9, 13);   //

void setup()
 // Set the clock to run-mode, and disable the write protection
 // Setup LCD to 16x2 characters
 lcd.begin(16, 2);

 // The following lines can be commented out to use the values already stored in the DS1302


void loop()
 // Display time centered on the upper line
 lcd.setCursor(4, 0);
 // Display abbreviated Day-of-Week in the lower left corner
 lcd.setCursor(0, 1);
 // Display date in the lower right corner
 lcd.setCursor(6, 1);

 // Wait one second before repeating :)
 delay (1000);


fixed it...
seems I need to unplug VCC (the module then works on battery) when setting the time.

dont understand why. found it by luck :)

anyway, now works !



this is the italian sub-section of the forum  ;)
We (mostly) understand english but it's not the default language to use here  ;)


Oops sorry :)
Can this topic be moved to the right place?

I'll pay more attention next time,

Grazie mille !


Oops sorry :)
Can this topic be moved to the right place?

Hope a mod will do the job  ;)


I'll pay more attention next time,

Grazie mille !

Ciao  :D

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131