SPRING SALE up to 20% OFF! (excludes trade customers)   •   FREE Standard Delivery for orders over £35 (ex VAT)
Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

RTC Pi Library for C++

RTC Pi C++ Library Installation and Usage

Created 29/07/2024 | Last Updated: 19/06/2025

YOU WILL NEED THIS BOARD

111 available
Order a RTC Pi Photo of RTC Pi

RTC Pi

Real time clock for the Raspberry Pi and Single-Board Computers

£7.59 ex VAT

C++ Library to use with RTC Pi Raspberry Pi real-time clock board.

The example C++ files can be found in /ABElectronics_CPP_Libraries/RTCPi/demos

Downloading and Installing the library

To download to your Raspberry Pi type in the terminal:

git clone https://github.com/abelectronicsuk/ABElectronics_CPP_Libraries.git

Clases:

RTCPi(date) 

RTC class for accessing the DS1307 real-time clock.

Methods:

set_date(struct tm date) 

Set the date and time on the RTC
Parameter: date - struct tm formatted date and time
Returns: null


read_date() 

Returns the date from the RTC
Returns: (tm struct) date


enable_output() 

Enable the square-wave output on the SQW pin.
Returns: null


disable_output()

Disable the square-wave output on the SQW pin.
Returns: null


set_frequency(uint8_t frequency)

Set the frequency for the square-wave output on the SQW pin.
Parameter: frequency - options are: 1 = 1Hz, 2 = 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
Returns: null


write_memory(uint8_t address, uint8_t *valuearray, uint8_t length)

Write to the memory on the ds1307. The ds1307 contains 56-Byte, battery-backed RAM with Unlimited Writes
Parameter: address - 0x08 to 0x3F
Parameter: valuearray - uint8_t array containing data to be written to memory
Parameter: length - up to 56 bytes. array length can not exceed the available address space.
Returns: null


read_memory(uint8_t address, uint8_t length)

Read from the memory on the ds1307
Parameter: address - 0x08 to 0x3F
Parameter: length - up to 56 bytes. length can not exceed the available address space.
Returns: (uint8_t*) array of bytes from the SRAM

Also useful for your Raspberry Pi project

Temperature & Sensing

1 Wire Pi Plus

Connect dozens of 1-Wire sensors - temperature, iButtons, EEPROMs - via a single GPIO pin. Stacks directly on the 40-pin header.

£9.59 ex VAT

Analogue I/O

ADC Pi

Read up to 8 analogue inputs - perfect for pairing with your temperature sensors or other analogue-output devices.

£14.39 ex VAT

All-in-one

Expander Pi

Combines ADC, DAC, 32 GPIO ports and a real-time clock on one board. The most versatile board for complex Raspberry Pi projects.

£15.99 ex VAT

Order these Boards

All boards are designed & manufactured in the UK with RoHS-compliant components.