An enhanced Arduino library for the Microchip MCP7941x Real-Time Clock/Calendar chips with improved ESP32 compatibility (supports all GLYPHdevelopment boards) and comprehensive examples.
PCBCUPID MCP79412 RTC is a feature-rich Arduino library that supports the Microchip MCP7941x Real-Time Clock/Calendar family. Built upon the foundation of the original MCP79412RTC library, we've made significant enhancements to improve compatibility and expand functionality.
This library is designed to work seamlessly with PJRC's Arduino Time library and provides extensive support for all MCP79412 features including dual alarms, battery-backed SRAM, EEPROM storage, power failure detection, and calibration capabilities.
- ESP32 Support: Modified Wire library implementation to use TwoWire interface for full ESP32 board compatibility
- Flexible I2C Configuration: Multiple begin() methods supporting custom SDA/SCL pins, clock frequencies, and TwoWire instances
- Cross-Platform: Maintains compatibility with traditional Arduino boards while extending support to modern ESP32 platforms
- Multi-I2C Support: Support for multiple I2C buses with custom TwoWire instances
We've significantly expanded the example collection to demonstrate every feature of the MCP79412 RTC:
- Basic Time Operations: Setting and reading time with various methods
- Dual Alarm System: Complete examples for both Alarm-0 and Alarm-1 configurations
- Power Management: Battery backup, power failure detection, and logging
- Memory Operations: SRAM and EEPROM read/write demonstrations
- Calibration: Fine-tuning RTC accuracy with calibration examples
- Advanced Features: Square wave generation, unique ID reading, and multi-function pin control
- Real-World Applications: Practical implementations including data loggers and scheduling systems
Supported RTC Chips:
- MCP79411 (EUI-48 MAC address)
- MCP79412 (EUI-64 MAC address)
Compatible Platforms:
- Glyph Development Board
- Arduino Uno, Nano, Pro Mini
- Arduino Mega, Leonardo
- ESP32 (all variants)
- Other Arduino-compatible boards with I2C support
get()- Get current time as time_tset(time_t t)- Set RTC time from time_tread(tmElements_t &tm)- Read time into tmElements_t structurewrite(tmElements_t &tm)- Write time from tmElements_t structureisRunning()- Check if RTC oscillator is running
setAlarm(alarmNumber, alarmTime)- Set alarm time (ALARM_0 or ALARM_1)enableAlarm(alarmNumber, alarmType)- Enable/configure alarm matching criteriaalarm(alarmNumber)- Check and clear alarm flagalarmPolarity(polarity)- Set alarm output polarity
Alarm Match Types:
ALM_MATCH_SECONDS- Match secondsALM_MATCH_MINUTES- Match minutesALM_MATCH_HOURS- Match hoursALM_MATCH_DAY- Match day of week (triggers at midnight)ALM_MATCH_DATE- Match date (triggers at midnight)ALM_MATCH_DATETIME- Match complete date and timeALM_DISABLE- Disable alarm
64-Byte Battery-Backed SRAM:
sramWrite(addr, value)- Write single bytesramWrite(addr, values[], nBytes)- Write multiple bytessramRead(addr)- Read single bytesramRead(addr, values[], nBytes)- Read multiple bytes
128-Byte EEPROM Storage:
eepromWrite(addr, value)- Write single byteeepromWrite(addr, values[], nBytes)- Write page (up to 8 bytes)eepromRead(addr)- Read single byteeepromRead(addr, values[], nBytes)- Read multiple bytes
vbaten(enable)- Enable/disable battery backuppowerFail(powerDown, powerUp)- Check for power failures and get timestamps- Power failure detection with automatic timestamping
- Battery backup support for continuous operation
calibRead()/calibWrite(value)- Clock calibration (±127 PPM adjustment)squareWave(freq)- Generate square wave output (1Hz, 4096Hz, 8192Hz, 32768Hz, or disable)out(level)- Set MFP output level when not used for alarms/square waveidRead(uniqueID[])- Read 64-bit unique IDgetEUI64(uniqueID[])- Get EUI-64 format MAC address
Square Wave Frequencies:
SQWAVE_1_HZ- 1 Hz outputSQWAVE_4096_HZ- 4.096 kHz outputSQWAVE_8192_HZ- 8.192 kHz outputSQWAVE_32768_HZ- 32.768 kHz outputSQWAVE_NONE- Disable square wave
- Microchip MCP79412 Datasheet: Product Page
- Arduino Time Library: PJRC Time Library Documentation
- Examples: Comprehensive example sketches included with the library
- Community Support: Active community support through GitHub issues & dedicated forum
This library is inspired by and builds upon the excellent work of Jack Christensen's MCP79412RTC library. We are deeply grateful for his foundational work that made this enhanced version possible.
Original Work:
- Author: Jack Christensen
- Original Repository: JChristensen/MCP79412RTC
- License: GNU GPL v3.0
We thank Jack Christensen for his contribution to the open-source Arduino community and for creating such a solid foundation for MCP79412 development. This enhanced version aims to extend his excellent work to modern platforms while preserving the quality and reliability of the original implementation.
We welcome contributions! Please see our Contributing Guidelines for details on how to submit bug reports, feature requests, and pull requests.
This library is released under the same license terms as the original MCP79412RTC library (GNU GPL v3.0). Please see the LICENSE file for details.
Made with ❤️ by the PCBCUPID