Thanks, I've created a new constructor that allows you to input the prescaler value if you wish, I'll test it today and upload it as well.
Clock calendar implementation on RTC
(152 posts) (17 voices)-
Posted 3 years ago #
-
Real life has intruded on me and I've been away for a bit.
I haven't had time to check out your code time of day code bublindo, sorry.
Just a check point on the state of my pull request in github.
I have now tested on three Maple Minis and the Olimexino board bubuindo has. I haven't yet got to the Maple board.
I had one Maple Mini board where the HSE clock wasn't working for the RTC, but that is no longer the case. Works fine on two of the three now and the other has stopped accepting code up loads (its now a candidate for a boot loader reflash). The Olimexino board works fine.
I think the code in the pull request is stable at this point.
Posted 3 years ago # -
Sweet. Thanks for your help. The brains were made by you... I just put some lipstick on it. :)
Posted 3 years ago # -
I have an Olimexino and am very keen to use the built-in RTC.
Can somebody explain where I can get this lib/example?Posted 3 years ago # -
You can download the library in:
https://github.com/bubulindo/MapleRTC
There is an example .pde file to use with it.
I'm affraid the time.h library makes the code quite big, but I haven't had the time to check how to minimize the footprint.
Posted 3 years ago # -
Thanks for the help.
The example compiles OK. Now I need to convert the value to a date-time string - probably as a class. Time should be easy. However, Date could be a problem due to the uneven month and year length. I will probably steal code from corresponding Arduino library.Suddenly millis() and delay() stopped working. Please help.
#include <time.h> is commented out. Do I need to uncomment it? What is it doing there?
Posted 3 years ago # -
How can I set the time value?
Posted 3 years ago # -
In github.com/bubulindo/MapleRTC/RTClock.cpp:
void RTClock::setTime (time_t time_stamp) {
rtc_set_count(time_stamp);
}Or in libmaple/rtc.c. (see github/rodglchrist/libmaple for a variant of libmaple 0.0.12 containing rtc.c (several other files are changed as well as the rtd.c/rtc.h addition) which bubuindo has repackaged as utilitiess/rtc_util.c in his github repo above:
/**
* @brief Sets the counter value (i.e. time/date) for the rtc.
* @param value New counter value
*/
void rtc_set_count(uint32 value) {Posted 3 years ago # -
Hello,
Sorry for missing that out. If you go to the hardware\leaflabs\cores folder, there will be a wirish_time.h file. (Just look for that file).
Then open the file, and change these lines:
#ifndef _TIME_H_
#define _TIME_H_to
#ifndef WIRISH_TIME_H_
#define WIRISH_TIME_H_Everything will work fine then. :)
Posted 3 years ago # -
Rod,
That did the job. ThanksBulblindo
Yes now they are working. Thanks.Now I want to convert the long value like below:
`tt = rt.getTime();
int MyHour = hour(tt);
int Mymin = minute(tt);
int MySec = second(tt);`
etc.How can I do this?
Once again thanks all you guys for the great work.
Posted 3 years ago # -
struct tm myTime;
struct tm * tm_ptr;
tm_ptr = rt.getTime(tm_ptr);
SerialUSB.print(tm_ptr->tm_hour);
SerialUSB.print("/");
SerialUSB.print(tm_ptr->tm_min);
SerialUSB.print("/");
SerialUSB.print(tm_ptr->tm_sec);Didn't the example show this?
This link might be handy:
Posted 3 years ago # -
I set the time with:
#include <RTClock.h>
RTClock rt (RTCSEL_LSE);
struct tm * tm_ptr;void setup()
{
tm_ptr->tm_sec = 0;
tm_ptr->tm_min = 45;
tm_ptr->tm_hour = 18;
tm_ptr->tm_mday = 4;
tm_ptr->tm_mon = 2;
tm_ptr->tm_year = 112; //2012-1900
tm_ptr->tm_wday = 6;
rt.setTime(tm_ptr);}
Then I tried to read time using another sketch with:
void blink ()
{
tm_ptr = rt.getTime(tm_ptr);
int MyHour = tm_ptr->tm_hour;
int MyMin = tm_ptr->tm_min;
int MySec = tm_ptr->tm_sec;
int MyDate = tm_ptr->tm_mday;
int MyMon = tm_ptr->tm_mon;
int MyYear = tm_ptr->tm_year + 1900;SerialUSB << MyDate << '/' << MyMon << '/' << MyYear << ' ' << MyHour << ':' << MyMin << ':' << MySec <<endl;
}
(I'm using Streaming library from Arduiana.org)I get: 4/0/1970 5:18:31
The only item correct in the result is day of month. However, seconds, minutes and hour counting are moving correctly. I understand that I set month incorrectly, but still result does not match.
Posted 3 years ago # -
You could always just use the built in Unix functions from the libc(?) library
#include <stdlib.h ... ... time_t time=rtc.getTime(); tm *timem=gmtime(&time); SerialUSB.print( "Time is currently : "); SerialUSB.println(asctime(timem));
Lookup asctime/gmtime on the net under unix commands. It does add about 10k.
It might be easier and safer to transfer as a single long word (time_t) and then read that in your second sketch, using gmtime/asctime to translate into human.
Posted 3 years ago # -
Thanks, it worked. #include <stdlib.h should not be added. If I add that, a bunch errors popup. However, I do not like the formatting which is not configurable.
Trouble is with RTClock::setTime. It is not setting the time. Can somebody share a sample sketch for setting time?
TIAPosted 3 years ago # -
Try,
strftime
- http://linux.die.net/man/3/strftime - that allows formatting of time however you choose, there is a whole bunch of time related functions in the time.h library, not sure if all of them are working/implemented but just have a poke around.As to setting the time, I'm sure
rtc.setTime()
takes a unix time_t value which is easier to deal with.Quick example I use for testing:-
long currTime; SerialUSB.begin(); // Wait for 5 seconds for something to be available on the usb serial line, // just leave time as it is if not // That something is purely the current date/time in seconds // Use date "+%s" >/dev/cu.usbmodem3d121 on the cmdline to send it the // correct date (assumes linux/mac) // Your serial port may by different // OR just paste a number into serial-monitor : 1327178558 is a good as // time as any, at least it's in the correct century for (int t=0; t<10; t++) { delay(500); if (SerialUSB.available()) { // char buff[100]; // int i; delay(10); // Allow time for whole msg to arrive, as this is a fast cpu nfscanf(SUSB, "%ld", &currTime); // Adds about 3k. SerialUSB.print("Time has been read:"); SerialUSB.println(currTime); rtc.setTime(currTime+2); // +2 secs to allow for human delays break; } }
Or even simpler
rtc.setTime ( 1327178558 );
Try http://www.onlineconversion.com/unix_time.htm
Again, look at all the time.h functions, there are loads to allow conversion between time_t and tm.Posted 3 years ago #
Reply »
You must log in to post.