0

HiFiBerry DAC+ RTC LibreELEC v9.2.6 Installation Guide

Hi to all.
After many attempts on different systems (Raspbian, HiFiBerryOS, etc. and LibreELEC itself) and searching for documentation I think I finally managed to correctly configure "HiFiBerry DAC+ RTC" on LibreELEC, below I report how I did so that it can serve as an example to everyone, avoiding many try and error tests.

My system consists of:
- Raspberry Pi 4 with "HiFiBerry DAC+ RTC" board
- LibreELEC v9.2.6 (LibreELEC-RPi4.arm-9.2.6.img.gz)

Configuration
Modify the config.txt file exactly as described (for example) in the document: https://www.hifiberry.com/docs/software/libreelec-installation-and-configuration/, adding (at the bottom) the two lines:
dtoverlay=hifiberry-dac
dtoverlay=i2c-rtc,ds1307
The first one enables the DAC (you will then need to select "ALSA ..." in the Kodi Settings->General->Audio->Audio Decoder->Audio output device configuration menu item), the second the RTC (which has a ds1307 chip).
Reboot for safety.
At this point you're done! I found that all the other changes that are needed in other systems (modules loading, clock initialization with "echo ds1307 0x68> ...", etc. see: https://www.hifiberry.com/docs/software/dac-rtc-configuring-the-rtc-driver /) instead with LibreELEC they are not or worse they are harmful.
Apparently the changes to the LibreELEC /storage/.config/autostart.sh and /storage/.config/shutdown.sh files are also not strictly necessary (see the comment below).
The RTC will work immediately, the only precaution is that the battery must be inserted for its operation (apparently this is a feature of the ds1307 chip but other chips could work without it obviously without keeping the correct date/time during power off).
To test the RTC:
hwclock -r
(-r=read RTC clock, can be omitted) if the command gives no errors and returns a date/time the RTC is already running.
Warning #1: the very first time the RTC is accessed after inserting the battery it may contain a garbled (not correct) date/time and the command may give an error.
The command:
date
returns the system date/time (the one that is then used and displayed by LibreELEC and Kodi). Without RTC the system date/time is initialized at each boot with a default value (always the same, awaiting for a time synchronization with an NTP server - if you want and have Internet access), while in the presence of RTC it is overwritten with the value maintained by the RTC itself even in the absence of voltage (using the battery during power off).
First you need to set the actual system date/time correctly. This can be done in two ways: the first is manual with the command:
date -s "..."
(with a string containing the current correct date/time, use the help), the second is to connect (if possible) to the Internet and wait for an NTP server to automatically synchronize the system date/time.
At this point you can copy (write) the system date/time to the RTC:
hwclock -w -u
(-w=write RTC from system clock) test with hwclock -r that the copy was successful (see below for -u).
From now on the RTC will autonomously keep the update of its correct date/time which will then be copied at each boot to the system date/time (overwriting the default initialization). In practice, during boot LibreELEC recognizes the presence of an RTC (only the modification to the config.txt file is required) and automatically executes a command like:
hwclock -s
(-s=set system clock from RTC)
Warning #2: especially if Kodi has been configured not to be in the GMT Timezone (UTC+00), it is *NECESSARY* to execute the write command "-w" with "-u", specifying the write as "UTC" . This is because at boot the reading from the RTC will take place considering it as UTC and therefore the reset system date/time could vary by the difference with respect to GMT.
To understand this better, also try to test the difference between:
hwclock -r
hwclock -r -u
when the configuration is correct, the second command must coincide with the system date/time, while the first returns the date/time kept in the RTC and which must refer to UTC (=GMT).
It might be useful to modify the /storage/.config/shutdown.sh file (read the LibreELEC wiki) to copy the system date/time to the RTC at each shutdown (in practice a hwclock -w -u) in the hypothesis that a Internet access has synchronized the system date/time making it more precise than the one stored in the RTC (which in the long run can be desynchronized from the actual date/time, read the documentation on time drifting of ds1307 chip or other RTC chip).
So far so good. It is really simple but you need to know exactly how to proceed and not make any missteps.
Since we can consider "HiFiBerry DAC+ RTC" like "two board in one" (DAC and RTC), I think this tutorial could be useful with other RTC boards for Raspberry even with different chips: in "dtoverlay=i2c-rtc,ds1307" line just substitute last part with the correct chip (es. ds3231).

Hope this helps, at least to save a little time ;-).

Luca

0 comments

Please sign in to leave a comment.