### Configure Device Tree Overlay in config.txt Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Modern approach using Device Tree overlays to enable I2C RTC support. Add the dtoverlay parameter to /boot/config.txt to load the i2c-rtc overlay with DS1307 device configuration. Optionally specify custom I2C address if different from default 0x68. ```bash dtoverlay=i2c-rtc,ds1307 ``` ```bash dtoverlay=i2c-rtc,ds1307,addr=0x68 ``` -------------------------------- ### Load I2C and RTC Drivers Pre-Device Tree Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Traditional method to load I2C BCM2835 and DS1307 RTC drivers by writing device identifiers to sysfs. Requires root privileges via 'sudo su' to avoid permission denied errors. This approach is replaced by Device Tree overlays in modern Raspbian. ```bash sudo modprobe i2c-bcm2835 sudo modprobe rtc-ds1307 sudo su echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device ``` -------------------------------- ### Test Real Time Clock Functionality Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Verify RTC operation by writing current system time to hardware clock and reading it back. The first command synchronizes system time to RTC, the second displays the current RTC time. ```bash sudo hwclock -w ``` ```bash sudo hwclock ``` -------------------------------- ### Execute Python Sampling Period Script Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Command to run the Python script that adjusts the I2C device sampling period. Execute the script after saving it with appropriate filename. ```bash python3 ups_change_sample_period.py ``` -------------------------------- ### Configure RTC for Raspberry Pi 3B Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Complete configuration for Raspberry Pi 3B including device tree specification, Device Tree overlay for I2C RTC, and I2C ARM parameter. Add these three parameters to /boot/config.txt to properly support DS1307 on Pi 3B. ```bash device_tree=bcm2710-rpi-3-b.dtb dtoverlay=i2c-rtc,ds1307 dtparam=i2c_arm=on ``` -------------------------------- ### Adjust I2C Device Sampling Period via Python Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Python script using smbus library to configure the sampling period for I2C device at address 0x17. Modifies registers 21 and 22 to set custom sampling interval (range 2-60 minutes). Adjust SAMPLE_TIME value based on power quality: 1-2 for poor battery, 3-5 for poor charger. ```python import smbus DEVICE_BUS = 1 DEVICE_ADDR = 0x17 SAMPLE_TIME = 2 bus = smbus.SMBus(DEVICE_BUS) aReceiveBuf = [] aReceiveBuf.append(0x00) bus.write_byte_data(DEVICE_ADDR, 21, SAMPLE_TIME & 0xFF) bus.write_byte_data(DEVICE_ADDR, 22, (SAMPLE_TIME >> 8) & 0xFF) print("Setting Sampling Period to: %d Min" % SAMPLE_TIME) ``` -------------------------------- ### Comment Out systemd Check in hwclock-set Script Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Modify /lib/udev/hwclock-set script to comment out the systemd detection lines that prevent hardware clock initialization. This allows the real hwclock script to execute properly on systemd-based systems. ```bash #if [ -e /run/systemd/system ] ; then # exit 0 #fi ``` -------------------------------- ### Configure RTC for Raspberry Pi 4B Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Complete configuration for Raspberry Pi 4B including Device Tree overlay settings and I2C ARM parameter. Add these parameters to /boot/config.txt to enable DS1307 I2C Real Time Clock support on Pi 4B. ```bash dtoverlay=i2c-rtc,ds1307 dtparam=i2c_arm=on ``` -------------------------------- ### Remove Fake Hardware Clock Service Source: https://wiki.52pi.com/index.php?title=EP-0136/index_title=EP-0136 Disable the fake-hwclock service which interferes with the real hardware clock. Execute these commands to remove the fake-hwclock package and unregister it from system startup. ```bash sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.