Raspberry Pi Pico Thermometer & Clock

Dear friends welcome to another tutorial! Today we are going see how to build this low-cost real-time clock and thermometer with a color TFT display using CircuitPython on a Raspberry Pi Pico board.

6 years ago, I built a similar project using an Arduino Uno board and the Arduino IDE. Now that new, much faster boards are available, we can use CircuitPython, an implementation of Python for microcontrollers, to build the same project. Is CircuitPython a good choice for this project? Let’s find out.

Raspberry Pi Pico Thermometer & Clock

Supplies

Supplies

The cost of the project is around 14$.

5$ for the display, 6$ for the Raspberry Pi Pico, and around 3$ for the real time clock module.

Step 1: The DS3231 RTC Module

The DS3231 RTC Module

The real time clock module is all we need in order to measure the temperature and get the time and the date. It contains the DS3231 real time clock chip which also contains a temperature sensor. Let’s now see how to connect all these parts together.

Step 2: Connections

Connections

First, we are going to connect the real time clock module. Ground goes to the Raspberry Pi Ground. Vcc goes to The Vbus pin of the Raspberry Pi Pico which outputs 5Volts. SDA goes to pin GP0. SCL goes to analog pin GP01. Next, we connect the 1.8’ color TFT display. Please watch my detailed tutorial on how to connect it to a Raspberry Pi Pico or follow the schematic diagram I have attached in this step.

When all the wires are connected, we are ready to power up the project and see if it is working. OK, as you can see the project is working fine and it displays the current date and time, the temperature right now and the min and max temperatures it recorded since powerup. If we compare the temperature readings of our project with a commercial device you can see the temperature readings are very accurate. I love this real time clock module!

Step 3: Code & Libraries

Code & Libraries

 Now let’s take a look at the software side of the project.

I am using Thonny as the development environment with CircuitPython.

You can find the code in this Github repository: https://github.com/educ8s/CircuitPython-Clock-with-DS3231-and-ST7735-display

We are using a lot of libraries in this project. Some of them are built into CircuitPython so we don’t need to install them. Some of them are not so we need to install them. So, we need to install 5 libraries: the adafruit_st7735r library for the display, the adafruit_ds3231 library for the real time clock module, the adafruit_display_text_library, the adafruit_register library and the adafruit_bitmap_font library. In order to install the libraries, we have to download the CircuitPython libraries bundle from this link and unzip it on our computer. Since I developed the project using CircuitPython 8 we need to download the bundle for CircuitPython 8. Now all we have to do, is to locate the needed libraries and copy and paste them inside the lib folder in the CIRCUITPY drive. Additionally, we also need a font file. In the CIRCUITPY drive we have to create a fonts folder and inside it copy the terminal font file I am going to share with you in the Github Repository.

Then you need to update the code.py file with the script of this project.

Step 4: Set the Time to the RTC Module

Set the Time to the RTC Module

The first time we run the program we have to set the time to the real time clock if it is not already set. To do so, we have to uncomment lines 57, 58, and 59 and enter the current date and time here. We need to enter the year, the month, the date, the hour, the minutes, the seconds and the weekday. The last two arguments are not needed.

Now we run the program once. Now, time has been set to the real time clock and it is kept internally with the use of the small battery on the back of the RTC module. Now, we have to comment these three lines of the code again and hit run once more. That’s it. The code now runs on the Raspberry Pi Pico and it displays the date, time and temperature at the display and at the terminal. Cool.

Step 5: Comparison With Arduino

As you can see the code of the project is very simple and we needed only 134 lines of code to develop this project. Since I used Python to develop this project, development was very fast and easy.

CircuitPython is an interpreted language which means that the code does not need compilation before running, we just hit run on the IDE and the code runs at once on the board. This makes development way faster than Arduino. Testing things out and debugging is instant which saves a lot of time.

On the other hand, this makes the code run slower on the board, a lot slower. But since we are using a very fast board, the slower execution of the code is not a problem. As you can see, the display updates instantly, there is no flicker at all, so there is no speed issue with this project.

Also, since Python is a higher-level language, its syntax is much easier than Arduino, which makes coding this project easier, more fun and faster. Another advantage of CircuitPython.

Of course, using CircuitPython requires knowing how to code in Python, which is another headache if you are not familiar with Python.

In that case, don’t worry. The fundamentals are very easy to learn. I have prepared a detailed course on my second channel about Python programming. It will teach you the basics in just a couple of hours. If you are interested in learning Python or CircuitPython check it out now, by clicking here, I think it will help you a lot.

Thanks for reading this tutorial. If you don’t want to miss any future projects consider following me in Instructables, and I will see you next time.

Source: Raspberry Pi Pico Thermometer & Clock

Scroll to Top
Read previous post:
NANO-SPOT-WELDING-JUST-GOT-EASY-AND-AFFORDABLE
NANO: SPOT WELDING JUST GOT EASY AND AFFORDABLE

One of the major focuses of the maker movement since time immemorial has been the development of a makeshift version...

Close