This guide covers the basic use of the Makerverse Supercap Real Time Clock (RTC) on the Raspberry Pi Pico. We'll connect the RTC, set the time and date and even create a basic datalogger project.

Transcript

Let's get started using the Makerverse Super Capacitor Real-Time Clock with a Raspberry Pi Pico. To follow along, you'll need a Makerverse Real-Time Clock with Super Capacitor backup, a Raspberry Pi Pico with pin headers soldered on, a breadboard, some jumper wires, and a potentiometer if you want to follow along with that data logging example.

Plug your Pico and your clock into a breadboard, connect the ground pin or the GND pin on the clock with the third pin in the top right of the Pico. Connect VCC to the 3.3V pin, that's the fifth pin in the top right on the Pico. Connect SDA, the data pin, to the top left pin on the Pico, that's GP0, and connect SCL or clock to the pin just below that, the second pin in the top left. And finally, connect to your computer with USB.

In the article for this tutorial, find the download section and find the driver that we need to download, that's the Makerverse RV3028.py link. Right click that link and save link as. I'm just going to save it into my downloads. We're going to be using Thonny to program our Pico. If you haven't used Thonny with Pico before, check out our guide for that. I'll open Thonny, connect to my Pico, and right click that file and upload it to the Pico. Back in the article for this tutorial, find the basic example and copy all of that code into Thonny. I'll paste it into this untitled file and save that to the Pico as main.py. Reboot your Pico with CTRL D, and we get in.

The REPL looks like a factory default kind of time. It is the year 2000, the 1st of January, and the time is pretty close to the whole hour. To start, we import the I2C and pin functions from the machine, and the Makeiverse RV3028 module for running the clock. We make an I2C object, which defines the pins that we connected to before. This is the I2C bus that handles communications between our Pico and the real-time clock. We use bus 0, and have SDA or data on pin 0, GP0, and SCL or clock on pin 1. This returns an I2C object that we call I2C, and we then pass that object into the initializer for our real-time clock and call that object RTC. We call RTC.timestamp, which gets us that timestamp string, and then we print it to the REPL.

To set the correct time, we can create lists or dictionaries. For lists, we fill it with integers for day, month, year, and similarly for time list with hours, minutes, seconds. There is an optional AM or PM indicator that we can include at the end. For dictionaries, we create an empty date dictionary, and then add to it keys for day, month, year, and then the time dictionary for hours, minutes, and seconds. will start and I can see the values being read from the potentiometer and saved to the file.

I prefer this one because it's quite prescriptive. You know exactly what you're getting because it says day in the dictionary. So, I'll scroll down to the next example, copy all of that code, and paste it into Thonny. I'll just paste it over the top of everything we already have. The start of the code looks very similar to our last example, so we'll skip over that. We'll move on to setting the time with the dictionary format. Now this has been pre-filled with some default values, but let's set it to the correct time. At the moment for me it is Tuesday the 15th of February 2022, and it's 10 53 in the morning. So I can enter the 15th of February, that's 2, 2022, and it is 10 53 in the a.m. Now when I run this code I'll just save my file and press ctrl d. Now I have the correct time stamp for the current time.

The time is backed up by the supercapacitor so that even when power is removed this clock will keep ticking for up to about seven days. When power is restored the supercapacitor will continue to charge back up so it's ready for another seven days of power outage. Now let's create a really simple data logging project. I'll connect a potentiometer to the Raspberry Pi Pico's ADC0. This will allow us to read some analog value from the potentiometer and save it to a file. We'll read the potentiometer and then save it to a file with a time stamp and then we can just do that repeatedly so we can see how that value changes over time. I'll connect my potentiometer with the leftmost lead connected to VCC or three volts, the rightmost lead connected to ground, and the middle lead connected to ADC0 on the Pico.

Returning to the article, I'll find that data logging example. We'll copy that and paste it into main. I'll highlight everything, paste over it, save the file. Now when I run the file with ctrl D the REPL will start and I can see the values being read from the potentiometer and saved to the file.

We will print out a time stamp and a value. On the left we have the time stamp and to the right of that we have some value from the ADC. By varying the position of the potentiometer, we can make that value change. We can wind it all the way to one end for a very small number and to the other end for a maximum scale of 65535.

We can stop the script with ctrl C and in the file explorer in Thonny under Raspberry Pi Pico, we can refresh the listing and find a new file datalog.csv. We can open it in Thonny and see an exact copy of what we saw in the REPL. We have our date time stamp and then our ADC values. We can see where we wound it to the minimum value and the maximum value. Looking closely at the time stamp, we can see that it's incrementing by one second each time. We can download this datalog file onto our computer using Thonny and open it up in a spreadsheet program for further analysis.

Taking a look at the code, we have a similar import sequence. This time we import time so we can create a delay. We have a log interval in seconds, taking one sample every second and setting up to read on ADC 0. In an infinite loop, we create a variable x and assign it the value that we read from the ADC. We print the time stamp with that value and open up our datalogging file datalog.csv in append mode. We write the time stamp to it followed by a comma and then convert our value from an integer to a string and append it to the file. Finally, we put in a new line for formatting and flush and close the file.

We've set up our Makerverse Supercap real-time clock to keep accurate time and we've done a simple datalogging project with it. This guarantees that our data is safe and we can remove power at any time without corrupting the file. To ensure accuracy, we have a loop at the bottom of the code that creates a one second interval. It gets the time from the clock and makes sure that at least a second has elapsed since the last sample.

This is now capable of keeping time between power cycles so you can unplug it, plug it back in, and rerun the code and you ought to still get the same accurate time showing in your datalog. If you have any questions about this content, let us know on our forums. We're full-time makers and happy to help. Until next time, see you later!

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.