Go Down

Topic: How to add RTC in an Arduino sketch (Read 373 times) previous topic - next topic

Dancopy

Jun 15, 2019, 12:04 am Last Edit: Jun 15, 2019, 12:11 am by Dancopy
Greetings to all.
A friend sent me an example of a modified 'myMATRIX_Clock' sketch here: https://www.youtube.com/watch?v=4uvpxXMFPOk&feature=youtu.be but, for private reasons, he did not add the RTC function in the code.
Time is only being taken with the Arduino internal Timer, and I would like to add a real RTC as in the original sketch, but I do not know enough about it.
To facilitate, the original skech is this: Digital_Clock_and_Message, which is attached.
And the code to add the RTC is this: myMATRIX_Clock, which is also attached.
Therefore, I would ask your help to, for kindness, add the RTC function in the myMATRIX_Clock sketch, just like the original sketch.

My sincere thanks,

Daniel Fernandes

larryd

You should probably spend some time looking a the examples that come with the RTC library.

BTW
A DS3231 RTC is a good choice.



No technical PMs.
The last thing you did is where you should start looking.

Dancopy

@larryd
Yes, I've already taken a look at the libraries RTClib and DS1307 (which is in the original sketch) and tried to adapt it in my sketch, but certainly for lack of knowledge and experience, I could not.
Of course I will use the DS3231, which is more accurate.

larryd

You can read the RTC every example: 100ms.

When the RTC seconds change, you then use the read value for hours/minute/seconds in your existing sketch.


No technical PMs.
The last thing you did is where you should start looking.

Nick_Pyner

You don't even need a library. If you just want the time, this will do. No changes needed for DS3231.

Dancopy

@larryd
@Nick_Pyner
If you look, the first sketch (Digital_Clock_and_Message) uses the RTClib library, and the second sketch (myMATRIX_Clock) is using the internal arduino clock (without RTC), and I want to use 'myMATRIX_Clock' with a RTC module (DS1307 or DS3231) to, when to turn off the arduino, do not waste the time but, I do not know to add it in the sketch, that's it.
If anyone can do that for me, I appreciate it.

Daniel

larryd

There is a 'Gigs and Collaborations' forum on this web site where people can do the work for you.






No technical PMs.
The last thing you did is where you should start looking.

Dancopy

@larryd
Thank you, I'll take a look.

@lastchancename
Oh, if I knew how to do all this, I would gladly help people!
It's just that I have enough difficulties! already tried

Dancopy

#8
Jun 16, 2019, 07:20 pm Last Edit: Jun 16, 2019, 07:24 pm by Dancopy
There is a 'Gigs and Collaborations' forum on this web site where people can do the work for you.







Okay, but do I need to bring it there or do I have to create a new topic there and a new account as well?

larryd

I believe the moderator will move this thread if you send a request to them.



No technical PMs.
The last thing you did is where you should start looking.

dave-in-nj

I would suggest you follow the advise of  post #1

there are example programs in your IDE, just search down the list.

most often, there are some statements you need to define before setup()

call libraries, set variables, etc.

in setup, there is a section that sets the time on the RTC.  this is a one time program
you put in the date and time about a minute in advance, then upload the sketch.
at the time you set, you would reset the Arduino and it would set that time.

then you go back to the IDE, comment out that time
then upload the new sketch. this way, it will not re-set the time in the RTC back to that time, with ever power loss.

then watch the terminal window.

play with the examples.  (you only need to set the time once, then comment out in all the exampes.)

but you get to see how to read the time.

once you have the time as you like,

copy and post the bits before setup into your desired sketch


as you work with the sketch, the parts should be come more and more clear.

Dancopy

@dave-in-nj

Thanks for your help and encouragement. (yours and others here in the forum) - I've tried and I could not.
I'll try again.

larryd

Well/if you run into trouble, ask us to review your attempt on writing the changes to your sketch.



No technical PMs.
The last thing you did is where you should start looking.

Dancopy

I made the code with the help of a friend;
thank you to all who have had the spirit of help;

lastchancename

I made the code with the help of a friend;
thank you to all who have had the spirit of help;
Always great if you have an experienced 'buddy' to get over the speed bumps.
You should re-post your final code below here (in <code> tags)... to help others
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up