The RTC Pi can be used with the Raspberry Pi Pico available at Raspberry Pi
We have a MicroPython library to use with the Raspberry Pi Pico at MicroPython Libraries GitHub Repository.
The example Python files can be found in /ABElectronics_MicroPython_Libraries/RTCPi/demos/
Connecting the RTC Pi to the Raspberry Pi Pico
The RTC Pi library uses the following Raspberry Pi Pico board pins.
Pico Pin | Pico GPIO | Function | Pi Pin | Pi GPIO |
---|---|---|---|---|
26 | 20 | I2C SDA | 3 | GPIO 2 |
27 | 21 | I2C SCL | 5 | GPIO 3 |
40 | VBUS | 5V | 2 | 5V Power |
38 | GND | GND | 6 | Ground |
36 | 3V3(OUT) | 3V3 | 1 | 3v3 Power |
Wiring Diagram:
Downloading and Installing the library
To download to your Raspberry Pi, type in the terminal:
git clone https://github.com/abelectronicsuk/ABElectronics_MicroPython_Libraries.git
To install the MicroPython Library, use the Thonny Python IDE.
Create a file for your chosen board and copy the contents of the Python file into that board's directory. For example, for the RTC Pi, create a new file in thonny called RTCPi.py, copy contents from RTCPi.py into the new file and save it onto the Raspberry Pi Pico board.
Create a second file where your main program will reside and import the board library at the program's top.
from RTCPi import RTCPi
Run with "Run Current Command" or F5 in Thonny.
Class:
RTC(sda, scl)
Parameters:
sda (optional): I2C SDA pin. If no value is set, the class will default to pin 20.
scl (optional): I2C SCL pin. If no value is set, the class will default to pin 21.
Functions:
set_date(date)
Set the date and time on the RTC in ISO 8601 format - YYYY-MM-DDTHH:MM:SS
Parameters: date
Returns: null
read_date()
Returns the date from the RTC in ISO 8601 format - YYYY-MM-DDTHH:MM:SS
Returns: 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(frequency)
Set the frequency for the square-wave output on the SQW pin.
Parameters: frequency - options are: 1 = 1Hz, 2 = 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
Returns: null
write_memory(address, valuearray)
Write to the memory on the ds1307. The ds1307 contains 56-byte, battery-backed RAM with Unlimited Writes
Parameters: address - 0x08 to 0x3F
valuearray - a byte array containing data to be written to memory
Returns: null
read_memory(address, length)
Read from memory on the ds1307
Parameters: address - 0x08 to 0x3F length - up to 32 bytes.
Length can not exceed the available address space.
Returns: array of bytes
Usage
To use the RTC Pi library in your code, you must first import the library:
from RTCPi import RTC
Next, you must initialise the RTC object:
rtc = RTC()
Set the current time in ISO 8601 format:
rtc.set_date("2013-04-23T12:32:11")
Enable the square-wave output at 8.192KHz on the SQW pin:
rtc.set_frequency(3) rtc.enable_output()
Read the current date and time from the RTC at 1-second intervals:
while (True): print rtc.read_date() time.sleep(1)