Here is the RTC I'm using, though this is bound to work for other models.
https://www.amazon.com/WayinTop-DS3231- ... 628&sr=8-5
1. Connect the Vcc, GND, SDA, and SCL pins from the module to the respective GPIO pins on the Red Pitaya. Power on and connect to the Red Pitaya via SSH.
3. Determine if the RTC is connected, and the Red Pitaya can see it.
Code: Select all
$ i2cdetect -y -r 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: UU -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
4. Set the time of the RTC module to Tues March 16, 2021 08:05:00 UTC or something. According to the data sheet for the DS3231, registers 0x00-0x06 hold the seconds, minutes, hours, etc.
https://datasheets.maximintegrated.com/en/ds/DS3231.pdf Use i2cset to tell each register where it should be.
Code: Select all
$ i2cset -y 0 0x68 0x01 0 //start at 0 seconds
$ i2cset -y 0 0x68 0x02 5 // start at 5 minutes
....
We next need to set the Red Pitaya's system time from the RTC's time. For my application, I need the time to be accurate no matter the state of the Red Pitaya (losing power, resets, etc). So I use a bash script to set the Red Pitaya's time at boot. Create a timedate.sh file on the Red Pitaya, defining seconds, minutes, hours, day, month, and year. You can just copy and save this someone on your board. The name "timedate".sh doesn't matter.
Code: Select all
#!/bin/bash
# read in sec, min, etc from ds3231 and store in variable
sec=$(i2cget -y 0 0x68 0x00)
min=$(i2cget -y 0 0x68 0x01)
hour=$(i2cget -y 0 0x68 0x02)
day=$(i2cget -y 0 0x68 0x04)
month=$(i2cget -y 0 0x68 0x05)
year=$(i2cget -y 0 0x68 0x06)
# output of i2cget is of form 0x00, save on last two characters
sec=${sec: -2}
min=${min: -2}
hour=${hour: -2}
day=${day: -2}
month=${month: -2}
year=${year: -2}
# store all variables into strings to set time with
datee="20${year}${month}${day}"
timee="${hour}:${min}:${sec}"
# set system time
date +%Y%m%d -s "$datee"
date +%T -s "$timee"
Run this script from the command line using
Code: Select all
$ bash /path/to/script/timedate.sh
Code: Select all
[Unit]
Description=Time and date script
[Service]
ExecStart=/bin/bash /path/to/script/timedate.sh
Restart=always
[Install]
WantedBy=multi-user.target
Code: Select all
/etc/systemd/system/myservice.service
Code: Select all
$ systemctl enable myservice.service //service will start at next boot
$ systemctl disable myservice.service //will disable service on next boot
$ systemctl start myservice.service //starts service now, no reboot needed
$ systemctl stop myservice.service
There you have it. The Red Pitaya now does not rely on an internet connection to keep time. Hopefully this is helpful to the community until official RTC support comes out.
radman