Hi all, I’m looking to capture a couple of analog voltages from two sensors every 30 seconds, store up 10 of those readings, then send the collection of data using BLE. I could use a timed delay between readings, but I’m afraid that after taking days-weeks of this data even an error of a few milliseconds is eventually going to result on corrupting my time scale. Therefore, I wish to include a RTC value on each reading. I’m only familiar with the Arduino RTCZero.h library. Is there a way that I can do this with the mbed architecture via the Arduino IDE?
Honestly I have even seen some RTCs giving inaccurate results. I don’t think using RTC will be helpful in your case. Anyway, let’s see what the others opine.
I used the Arduino library manager to install “Jeelab’s fantastic RTClib” library, which includes implementations for several RTC modules, including the PCF8563 used on the XIAO BLE.
I attached a simple demo project and some output. The RTC values kept in step with the wall clock I used to set the clock for many hours.
Enhancements left to the users to implement:
From this, you can use a function from this library to determine whether or not the unit has been powered down and, therefore requires initial input to set the clock. (Refer to the library’s documentation.) My little demo asks for user clock settings every time it’s reset.
My user input clock setting routine doesn’t do any error checking to see whether values for year, month, day, hours, minutes, seconds are valid. In a “real” application you would always test for valid inputs.
It would be easy to test, every time through the loop, for user input to allow new clock settings in case the RTC drifts.
There are functions in this library to convert DateTime objects to-and-from UNIX epoch values. These can be used to extract day-of-week without having the user input the day manually. May be useful for some folks.
For an actual clock, current time value can be obtained from some libraries that handle Daylight Savings time automatically.
Etc.
Regards,
Dave
pcf8563_rtclib.zip (1.5 KB)
This is a great solution! But it is possible that only works in mbed bootloader?
I’m using adafruit library (1.0.0) and it seems the code is freezing at “Oops: Can’t access the RTC”
I haven’t found any documentation related to create a RTC using this seeduino. It’s a bummer since the initial SAMD Xiao does have a very good RTC module.