Ds1302.h Library Zip

4 views
Skip to first unread message

Saundra Balock

unread,
Jul 25, 2024, 9:08:08 PM (2 days ago) Jul 25
to RestKit

First you will need to set the bit in the hours register has been noted in the previous post. You can use the library function writeRegister() to OR the new bits with the exitising value. Then you will have to modify the code (_decodeH) which reads the hour register to evaluate the 12-24 bit and the am-pm bit and report the hour and am/pm based on that.

You could also modify the library in a less fundamental way (#3), and that is to leave it in the 24 hour mode, and modify the hours section of the getTime() code to add add the conditional test code described.

Take a look at the library example code DS 1302_Serial_Hard. You want to be using the Time data structure t and the methods of that sketch to get access to t.hour. You can then work with an hour value to develop 12 hour format. You want to be working with the hour as a number rather than a character string.

You are making things hard for yourself by using this RTC and library. Why are you using the DS1302 instead of the more common i2c rtcs like the DS 3231 or DS1307. They are better documented and have more examples floating around.

Then use the t.hour & 0x1F. This is to remove the 24 hours and left the 12 hours only. In this way you do not have to do anything to the library. To set the clock for 12 hours you need to set bit 7 of the hour register. Then check bit 5 to see if = 1 then is PM and if bit 5 = 0 is AM. Also you can manually set the reg 3 to 12 hours. If it is 12 PM then you must set the bit 5.

I got it in 12 hour mode now the date it all meat up it is written as 18/10/16 and I would like it to be 10/18/16 I have looked in the library and haven't found how to fix it. It only started doing that after I put it in 12 hour mode.

The default argument for the rtc.getDateStr() function which you use is LITTLEENDIAN which will give you the 18/10/16 you saw. Why you see a / as a divider instead of a . is a mystery, as the default divider appears to be the latter.

Try changing SHORT to LONG which should give 16 and 2016 for the year.
Try the different ENDIAN options to see what they give.
Also try use ':' and '.' as well as '/' to see the possible dividers.

That is the point PaulRB, i don't know what funtions to use, i've also highligthed the part where the "actual" code must be placed. I'm a newbie if it comes to rtc and time funtions. So please don't call me a troll, just having a hard time to find the propper code

The switch takes a number and based on that number executes one of the cases. The number is one of the values kSunday .. kSaturday (probably defined in the DS1302 library). So if the number is kSunday, case Time::kSunday is executed and the dayAsString function returns the String (capital S) "Sunday".

The printTime function reads the RTC and creates a String based on the day using dayAsString. Next it uses a character array (buf), places time related information in that buffer (day, t.yr,..) using a specified format (%s %04d...) and next 'prints' the character array on the serial port; this is not strictly necessary but the format specifier allows you to format to your needs; e.g. %02d indicates to print a number with a leading zero. It might be simpler to understand if you use

switch explained. Note that the code presented is for a PC.
sprintf example. snprintf only differs in the one additional argument to limit the amount of characters stored in the string (lower case s).

I'm a beginner in the arduino and programming society and I'm having problems running DS1302 RTC module. I'm using the DS1302_Serial_Easy library. I can't figure out what's causing the issue. Google search gave no solution. So, I hope you can tackle the problem.

ukulele2:
Hi. Thank's for the reply. The library is in C:\Program Files\Arduino\libraries\DS1302_Serial_Easy. I think it is in the right place, I can expand the DS1302 code example from the sketches menu.

You were right, there was something wrong with the destination, I downloaded the DS1302 again and extracted it successfully, now I can write the sketch on the arduino., but there appears to be something wrong. Namely, I get an error : avrdude: stk500_getsync(): not in sync: resp=0x00

JimboZA thank's for the input in my thread. You've been a big help. Essentialy I've figured out what caused this error. My arduino board is Leonardo and the Arduino Sketch program had the UNO defined. I feel that I'm almost home with this thread, now I recieve data, but I have the day of the week and time interchanging

Another question. Is it possible to acquire the time in seconds from this sketch, for example, 12:00:00 is 43200 seconds. the rtc.setTime pointer bears this value somewhere and somehow any clues ? I would like to compare the RTC time with a dc motor that will run at a certain time. It would set itself to 1 and run when it would match the RTC time in seconds.

The DS1302 trickle-charge timekeeping chip contains a real-time clock/calendar and 31 bytes of static RAM. It communicates with a microprocessor via a simple serial interface. The real-time clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with an AM/PM indicator (The library only support the 24-hour mode).

Interfacing the DS1302 with a microprocessor is simplified by using synchronous serial communication. Only three wires are required to communicate with the clock/RAM: CE, I/O (data line), and SCLK (serial clock). Data can be transferred to and from the clock/RAM 1 byte at a time or in a burst of up to 31 bytes. The DS1302 is designed to operate on very low power and retain data and clock information on less than 1W.

The DS1302 is the successor to the DS1202. In addition to the basic timekeeping functions of the DS1202, the DS1302 has the additional features of dual power pins for primary and backup power supplies, programmable trickle charger for VCC1, and seven additional bytes of scratchpad memory.

For a program that work fine loading only either heltec.h or esp32_lorawan.h; i.e. the program compile and works if I load only the heltec.h library (and obviously, commenting out the references to lorawan, it will have display but not lorawan comms) or if I load only the esp32_lorawan (and commenting the displat directives out, it will have lorawan but no display).

So, we can comment out the call to Heltec.h and the display, and the comms will work, or we can comment out the comms stuff, and the display will work. But trying to use both will result on an error, as previously stated:

Seems to be the original example, and the problem is the conflict between the heltec library we use for the display and the lorawan library which uses the same library for lorawan display. Or perhaps I did not understand what you are suggesting.

I am having trouble with the Radiohead RFM95 encrypted client example, seems Speck.h shows as no such file or directory. I can find code for Speck.h but not as a file I can drop in my library. I imagine there is a way to create the right file type in VS but I am not familiar with how to do that, assuming that would even do the trick. I would appreciate a little help here as I am rather new to Arduino and C++.

I load your library and try it on two different boards, Nano and Uno, but still cant get any data from RTC module. However it works with sketch from link via Arduino IDE, so the module itself is fine.

If rts-wds is like nth-input, then the number 7 will go beyond nth-input, then it will still show Sunday, not Saturday.
image19201200 249 KB
So the error is not here. I have a guess that this is due to the year. The day of the week depends on the year.

Eliminate the internal debug, you should be able to simulate now, the error of the year is because I put 2020 and according to the datasheet the year record of the RTC is from 00 to 99.
hence the error and the need to add 1965.

By following these steps, you can successfully interface the DS1302 RTC module with Arduino and achieve accurate timekeeping in your projects. For more information and tutorials on Arduino and other related topics, explore our website .

Hi. Is there a way I could only get hours and minutes in some kind of variable. I need it for checking is time right for some actions to be performed. This is too complicated cause I dont know how time is stored, cuz I cant see the code inside the library.

excuse me sir i have the same problem as Nana, on the serial monitor it keeps showing RTC lost confidence in time and keeps showing that the time is 00/00/2000 00:00:01.
I use a 3V battery on the rtc module. I have checked the connections and and everything seem okay. Can you help me please?

Hi Anzelmo,
What error are you encountering, and which troubleshooting methods have you tried?
To send data to the LCD, convert the time data to a string and print it on the LCD as text. Also, make sure to clear the LCD before printing the time to avoid overlapping data.

Thanks a lot for your interest, the following is my code, at the moment it only gives me an error on the last brace on the last line and I would be grateful if you tell me why.
below I put the platformio.ini that I have seen mentioned in many tutorials and I have not been able to understand what it is, can you help me?

Yes, it looks like you did that correctly, since it is attempting to install the HCMotor library. However, as the next line of the compile output says, you need to now install the Git client, so that PlatformIO can work with git repositories. You have two options, you can do what the error message says, and install git:

In other words, goto Git - Downloads and download the version of git for your operating system - i.e. Windows. Install it, and restart VSCode if you had it running still. PlatformIO should then find Git, and carry one.

Reply all
Reply to author
Forward
0 new messages