Adafruit Real time ...
 
Notifications
Clear all

Adafruit Real time clock question

9 Posts
2 Users
0 Reactions
1,312 Views
(@mrclassicman)
Member
Joined: 3 years ago
Posts: 18
Topic starter  

I just started playing with Adafruit RTC pcf8523 to eventually add a clock feature to future projects. I got everything working, very easy to use, by the way. I commented everything out that I didn't want and re-arranged the date to be Month, Day, Year format. My question is, can this 24-hour clock format be changed? I tried adding and if then statement (IF > =13 THEN -12) basically. I get an error code that states it can't be changed. it's not a biggie but I do like the 12-hour format better. Thanks in advance for any assistance on this!

 

Terry


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7439
 

I would be surprised if the 12/24 format isn't already available. Is the time returned in a structure? If it is, then one field will be 12hr one will be 24hr with lot's of other things like UTC offset daylight savings etc. Check the .h file for clues.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7439
 

I just googled 'RTC pcf8523 ' and very quickly found the following, as I suspected it's a struct.

Screen Shot 2022 02 25 at 10.40.45

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@mrclassicman)
Member
Joined: 3 years ago
Posts: 18
Topic starter  

Yes, Ron that code as I understand it is just to set the clock when I is first connected and then commented out so that it will not have to be reset every time it turned on.  I let it use my computers time and date during this set up. Problem is I cannot seem to change the 24-hour format to a 12-hour format. I will admit I have not spent a lot of time at this point. The message seems to be more of a road block than a simple syntax issue. 


   
ReplyQuote
(@mrclassicman)
Member
Joined: 3 years ago
Posts: 18
Topic starter  

@zander Great suggestion! I completely forgot about going in that direction. Sometimes things are so simple we make them difficult! lol. I will look into this and report back.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7439
 

@mrclassicman Read the 2nd half more carefully. Here is the unix standard time function that you include. 

https://docs.python.org/3/library/time.html

Screen Shot 2022 02 25 at 11.13.51

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@mrclassicman)
Member
Joined: 3 years ago
Posts: 18
Topic starter  

@zander First let paraphrase a song title "Thick as a brick" and that is me. I really do not understand on how this statement formats the time format, or allows it to be set to 12-hours.  I did look at the rtclib.h and found that the time const is protected and set at 1-23 hours. I am not a seasoned coder so at this point it looks as if I am at an impasse. Although I may be able to configure 24 to 12 after it is retrieved from the module and before I send that info to the display screen. I will continue to decipher, or  at least try to decipher, the code in case I am missing something. Feel free to comment on this or even direct, as all assistance is truly appreciated. I am smart enough to know that I do not know everything and therefore guess an awful lot! lol

protected:
uint8_t yOff; ///< Year offset from 2000
uint8_t m; ///< Month 1-12
uint8_t d; ///< Day 1-31
uint8_t hh; ///< Hours 0-23
uint8_t mm; ///< Minutes 0-59
uint8_t ss; ///< Seconds 0-59

 

 

This post was modified 2 years ago by mrclassicman

   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7439
 

@mrclassicman Sending you a dm

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7439
 

Lookup the API doc at https://docs.python.org/3/library/time.html#functions

You will see a function called strftime(format [, t]) I am showing just a part of the directives list but you can see the differences for 24hr and 12hr, the full list will show you how to arrange the date in any way you like.

A large part of a professional programmers job is learning an API. Some of these like windows is a very thick book. Last time I needed to do that the 8" x 6" book was about 3" thick. First learn the C builtin stuff like printf because what the pic does not show as it says in the 3 para 2nd sentence is a part is missing and that part can be an art form with backwards references, -ve offsets and other 'tricks'. Have fun.

Screen Shot 2022 02 25 at 16.01.43

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote