|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +--- |
| 4 | + |
| 5 | +import Tabs from '@theme/Tabs'; |
| 6 | +import TabItem from '@theme/TabItem'; |
| 7 | + |
| 8 | +# Real Time Clock |
| 9 | + |
| 10 | +There are several Real Time Clock (RTC) modules available for the Raspberry Pi, which can be used to keep track of the current time even when the Pi is powered off. These modules typically use I2C communication and can be easily integrated into your projects. |
| 11 | + |
| 12 | +Be sure when connecting a RTC module to use the pinout guide on your compute blade along with the pinout from the RTC modules data sheet to ensure correct wiring. |
| 13 | + |
| 14 | +## Available RTC Modules |
| 15 | + |
| 16 | +### Popular Options |
| 17 | + |
| 18 | +<Tabs groupId="rtc-modules"> |
| 19 | + <TabItem value="adafruit" label="Adafruit PiRTC" default> |
| 20 | + The [Adafruit PiRTC](https://www.adafruit.com/product/3386) is a reliable and well-documented RTC module. |
| 21 | + |
| 22 | + **Features:** |
| 23 | + - Built-in battery backup |
| 24 | + - Easy I2C interface |
| 25 | + - Compatible with all Raspberry Pi models |
| 26 | + - Excellent documentation and support |
| 27 | + </TabItem> |
| 28 | + <TabItem value="ds3231" label="DS3231 Module"> |
| 29 | + The [DS3231 Real Time Clock Module](https://www.pishop.us/product/ds3231-real-time-clock-module-for-raspberry-pi/) from PiShop.us offers high accuracy. |
| 30 | + |
| 31 | + **Features:** |
| 32 | + - Temperature-compensated crystal oscillator |
| 33 | + - ±2ppm accuracy from 0°C to +40°C |
| 34 | + - Built-in 32.768kHz oscillator |
| 35 | + - Battery-backed SRAM |
| 36 | + </TabItem> |
| 37 | + <TabItem value="ds1307" label="DS1307 Module"> |
| 38 | + The [DS1307 RTC for Raspberry Pi](https://wiki.seeedstudio.com/Pi_RTC-DS1307/) from Seeed Studio is a cost-effective option. |
| 39 | + |
| 40 | + **Features:** |
| 41 | + - Low-cost solution |
| 42 | + - 56-byte battery-backed RAM |
| 43 | + - Programmable square-wave output |
| 44 | + - Automatic leap year compensation |
| 45 | + </TabItem> |
| 46 | +</Tabs> |
| 47 | + |
| 48 | +## Installation |
| 49 | + |
| 50 | +### Hardware Setup |
| 51 | + |
| 52 | +1. **Power down** your Compute Blade before connecting any modules |
| 53 | +2. **Connect the RTC module** to your Compute Blade using I2C pins: |
| 54 | + - VCC → 3.3V or 5V (check your module's requirements) |
| 55 | + - GND → Ground |
| 56 | + - SDA → GPIO2 (Pin 3) |
| 57 | + - SCL → GPIO3 (Pin 5) |
| 58 | +3. **Insert the backup battery** (usually CR2032) into the RTC module |
| 59 | + |
| 60 | +### Software Configuration |
| 61 | + |
| 62 | +<Tabs groupId="installation-method"> |
| 63 | + <TabItem value="auto" label="Automatic Setup" default> |
| 64 | + ```bash |
| 65 | + # Enable I2C interface |
| 66 | + sudo raspi-config |
| 67 | + # Navigate to: Interfacing Options > I2C > Enable |
| 68 | + |
| 69 | + # Reboot to apply changes |
| 70 | + sudo reboot |
| 71 | + |
| 72 | + # Install I2C tools |
| 73 | + sudo apt update |
| 74 | + sudo apt install i2c-tools |
| 75 | + |
| 76 | + # Detect the RTC module |
| 77 | + sudo i2cdetect -y 1 |
| 78 | + ``` |
| 79 | + </TabItem> |
| 80 | + <TabItem value="manual" label="Manual Configuration"> |
| 81 | + ```bash |
| 82 | + # Edit the boot config |
| 83 | + sudo nano /boot/config.txt |
| 84 | + |
| 85 | + # Add the following line (adjust for your RTC chip): |
| 86 | + dtoverlay=i2c-rtc,ds3231 |
| 87 | + # or for DS1307: dtoverlay=i2c-rtc,ds1307 |
| 88 | + |
| 89 | + # Save and reboot |
| 90 | + sudo reboot |
| 91 | + |
| 92 | + # Remove fake hardware clock |
| 93 | + sudo apt-get -y remove fake-hwclock |
| 94 | + sudo update-rc.d -f fake-hwclock remove |
| 95 | + ``` |
| 96 | + </TabItem> |
| 97 | +</Tabs> |
| 98 | + |
| 99 | +### Testing Your RTC |
| 100 | + |
| 101 | +```bash |
| 102 | +# Check if RTC is detected |
| 103 | +sudo hwclock -D -r |
| 104 | + |
| 105 | +# Set system time to RTC |
| 106 | +sudo hwclock -w |
| 107 | + |
| 108 | +# Read time from RTC |
| 109 | +sudo hwclock -r |
| 110 | +``` |
| 111 | + |
| 112 | +## Benefits |
| 113 | + |
| 114 | +- **Persistent timekeeping**: Maintains accurate time when the system is powered off |
| 115 | +- **Low power consumption**: Uses minimal power from backup battery |
| 116 | +- **Easy integration**: Standard I2C interface works with existing projects |
| 117 | +- **Essential for logging**: Critical for applications requiring accurate timestamps |
| 118 | +- **Network independence**: No need for NTP when network is unavailable |
| 119 | + |
| 120 | +## Troubleshooting |
| 121 | + |
| 122 | +### Common Issues |
| 123 | + |
| 124 | +- **Module not detected**: Check wiring connections and I2C enable status |
| 125 | +- **Time drift**: Ensure backup battery is properly installed and charged |
| 126 | +- **Boot issues**: Verify correct device tree overlay for your RTC chip |
0 commit comments