This project demonstrates how to use the DS3231 Real-Time Clock (RTC) module on a Raspberry Pi 4 using the pigpio library.
This is an assignment implementation by Arina Sofiyeva, based on the original work and guidance of Derek Molloy.
Main author: Derek Molloy
Contributors: Arina Sofiyeva
- Sets the current time and date on the RTC module (in both 12h and 24h modes)
- Reads and displays the current RTC module time, date and temperature.
- Sets and reads two alarms. One is triggered when hours, minutes, seconds and specific days match. The second one is triggered when minutes, hours and specific dates match. (All trigger in 1 minute ahead of the current time)
- Demonstrates I2C communication with the RTC on Raspberry Pi.
- Uses RTC interrupts to control LED blinking, based on alarm triggers.
- Drives PWM-controlled LED brightness depending on SQW frequency (1Hz - LED at 100% PWM, 1.024kHz - LED at 75% PWM, 4.096kHz - LED at 50% PWM, 8.192kHz - 25% PWM).
- Uses
pigpiofor GPIO control.
The full explanation is here.
The grade received: 94/100.
- Raspberry Pi 4
- DS3231 RTC module
pigpiolibrary installed and running- One LED
- One resistor
Clone the repository:
git clone https://github.com/heroisaprinciple/ds3231RTCProject.git
cd ds3231RTCProjectBuild the project:
./buildThe
buildscript compiles application.cpp, I2CDevice.cpp and DS3231.cpp into a single executable rtc using g++ with flags.
Start the pigpiod daemon if it is not already running:
sudo pigpiodThen run the program with superuser privileges:
sudo ./rtcSuperuser access is required because
pigpioperforms low-level GPIO operations.
Choose a time format in the console menu and enjoy!
- Part 1. 24h mode: https://drive.google.com/file/d/1Z2AjoxirsHOiT-u8FgImH-B_GP-E4pXV/view?usp=sharing
- Part 2. 12h mode: https://drive.google.com/file/d/1ykMywWrtRKMtZHHz3JlNjtWfhz4C3LkY/view?usp=sharing
- Result: https://drive.google.com/file/d/1ipUiKreYtVdCXzoaIvkV0XJMF4RwG29j/view?usp=sharing
- Derek Molloy, Exploring Raspberry Pi
Copyright 2025- Dublin City University