RTC? OMG!!! How difficult can it be?

kenwood120s:
I use one sketch to set it and forget about it, then read it when necessary in other sketches...
...Mine's the one from Henning Karlsen.

Thanks. I'll take a look around and give that library a try - if I can find it.
I think I got a step closer tonight... I've gone back to using the DST1302RTC.h library, and started my sketch again from the ground up with debugging prints every step of the way. I can now see a return code of 255 when I do the RTC.set(t) command. This should be 0 for a successful write to the RTC, otherwise it returns the 'bus value' - whatever that means. So my bus value is 255... but I am no closer to finding out what that means or why I can't push a time to this thing. It is getting closer to finding its way into the bin.

Post a schematic, a link to the module, and photos of your connections to it. Cite an example sketch from a library that is known to work with your module. Then we might get somewhere.

smithg27:
Ironically - the DS1302 was to be the final step in a project to test various timekeeping mechanisms, starting from a basic delay loop, then delays with periodic adjustments to prevent drift, then using time.h, and finally introducing an RTC.

Here is a project I did which is kind of similar in spirit:
https://forum.arduino.cc/index.php?topic=408565.0

smithg27:
Thanks. I'll take a look around and give that library a try - if I can find it.

Henning Karlsen moved his site to here.

It would make life a lot easier if library writers (to whom we are all very grateful) would identify their libraries more closely than just the name of the product which it drives. So if Joe Soap wrote a library for the 1302 is could be named DS1302_JS_V01 or something, with the V number updated every time there's a new version.

Thanks Kenwood120s. I grabbed that library and installed it. I took one of his example sketches (DS1302_LCD) and loaded it straight into my IDE. I used all the rtc connections exactly as he specified them in the sketch, and even left the seed date, time, and DOW exactly as they were. The only change I had to make was to replace the LCD library with my I2C LCD library, and adjust the lcd declaration and begin statements.
It compiled, uploaded, and I saw.... junk. I have taken a few photos of the rtc module, showing pinout, and the connection of those pins to my Arduino, and a few seconds of video showing the utter garbage on the display. I'll try and post them separately, later this evening.

The sketch reads...
#include <LiquidCrystal_I2C.h>
#include <DS1302.h>
// DS1302_LCD
// 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 make a quick
// clock using a DS1302 and a 20x4 I2C LCD.
//
// I assume you know how to connect the DS1302 and LCD.
// DS1302: CE pin -> Arduino Digital 2
// I/O pin -> Arduino Digital 3
// SCLK pin -> Arduino Digital 4
// LCD I2C: SDA -> Arduino Analog 4
// SCL -> Arduino Analog 5

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

// Init the LCD
LiquidCrystal_I2C lcd(0x3F,20,4);

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

// Setup LCD
lcd.begin();

// 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(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
}

void loop()
{
// Display time centered on the upper line
lcd.setCursor(4, 0);
lcd.print(rtc.getTimeStr());

// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));

// Display date in the lower right corner
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());

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

Why don't you try the serial easy sketch; then all you need do is make sure it's the right baud rate and not have to worry about the problem being related to the lcd.

Diagnosis with one variable at a time makes things much simpler: right now you have a sketch which was (probably) known good, but you changed it. So is the problem in the sketch or the change?- you don't know.

Good point Kenwood120s.
I did just that - ran it straight out of the box, and got...

Monday 45.45.2125 -- 27:45:45
Monday 45.45.2125 -- 27:45:45
Monday 01.00.2010 -- 06:02:08
Monday 01.00.2010 -- 06:02:09
Monday 45.45.2125 -- 06:02:10
506:02:10 45.45.2125 -- 27:45:45
Monday 45.45.2125 -- 27:45:45
Monday 45.45.2125 -- 27:45:45
Monday 45.45.2125 -- 27:45:45

I think it is destined for the bin now. Damn - a whole dollar wasted! That's a quarter of a cup of coffee... :-o

Not to mention all your time. But one thing about hobbies (and I'm assuming this is a hobby project for you) is that wth, it's all good fun.

Seeing as you're going to get a new one, do y'self a favour and get a 3231 or at least a 1307.

As pointed out earlier in the thread, the DS1302 is neither SPI or I2C. While it is close to I2C the clock does not meet the I2C spec and the device will absolutely not function correctly with any library that uses the Wire library to drive it. There is only one way to make a 1302 work correctly and that is to bit bang it. Karlsen's library looks reasonable but I've never tested it.

I can say that I've extensively tested the library in the Arduino Playground (horrible name, btw)

https://playground.arduino.cc/Main/DS1302RTC

and can attest that it works correctly when using an ATMega328. You've never mentioned which board/processor you're running, it would be useful to know that.

The bottom line is this: If you're testing with a 5 volt, 16mhz ATMega328, the library above and it does not work, you have either bad wiring or a bad chip. End of discussion, no need to continue with unknown libraries.

If you want to see the correct way to drive the 1302, have a look a Maxim's own app note. While the demo code was written for the 8051, it's an easy port to AVR.

I'll add that while the DS3231 has superior time keeping ability, the 1302 has one feature that makes it useful for simple projects and that is 31 bytes of battery backed ram. With the DS3231, you must resort to EEPROM to persist data and while that is the preferred method for many, the battery backed ram is just flat out easy.

No different than vanilla and chocolate. Everybody has their own favorites.

avr_fred:
I'll add that while the DS3231 has superior time keeping ability, the 1302 has one feature that makes it useful for simple projects and that is 31 bytes of battery backed ram.

Yes, however the DS1307 also has it.

Thanks all for your inputs, comments, advice, and admonishments regarding having got a 1302 in the first place. Yeah - I know I was being a cheapskate... it was a late night ebay shopping binge and I thought "for a dollar, what the heck... let's just do it".
I think I can now happily concede (well, perhaps not 'happily'), that I've got a dud, so let's put this one to bed now. Perhaps I'll replace it in a while, but in the meantime, I have another project on the go, that does not require an RTC - so I'll divert my attentions to that for now.
And Kenwood120s - yes, I am an enthusiastic but very amateur hobbyist, only just starting out on this journey, so it was a dollar wasted, but many evenings gainfully spent researching and testing, which has taught me much much more than simply "not to buy the cheapest deals I can find on ebay".
All the best
Graham.
PS - yes, I forgot to mention what I am running it all on - almost embarrassed to say now... it is a cheap Chinese Uno clone, that cost me the grand sum of $4!!