You are on page 1of 10

instructables

Raspberry Pi Pico Thermometer & Clock

by educ8s

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 nd out.

Supplies:

Display: http://educ8s.tv/part/7735
Raspberry Pi Pico: http://educ8s.tv/part/RaspberryPiPico
RTC DS3231: https://educ8s.tv/part/DS3231
A small Breadboard
Wires

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.

Raspberry Pi Pico Thermometer & Clock: Page 1


https://www.youtube.com/watch?v=gBofy7MMdIY

Raspberry Pi Pico Thermometer & Clock: Page 2


Step 1: 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.

Raspberry Pi Pico Thermometer & Clock: Page 3


Step 2: 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 ne 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!

Raspberry Pi Pico Thermometer & Clock: Page 4


https://www.youtube.com/watch?v=KaGHxvVnKQ4

Raspberry Pi Pico Thermometer & Clock: Page 5


Step 3: 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.

Raspberry Pi Pico Thermometer & Clock: Page 6


You can nd 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 le. In the
CIRCUITPY drive we have to create a fonts folder and inside it copy the terminal font le I am going to share with you in
the Github Repository.
Then you need to update the code.py le with the script of this project.

Raspberry Pi Pico Thermometer & Clock: Page 7


Raspberry Pi Pico Thermometer & Clock: Page 8
Step 4: Set the Time to the RTC Module

The rst 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.

Raspberry Pi Pico Thermometer & Clock: Page 9


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 icker 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.

Raspberry Pi Pico Thermometer & Clock: Page 10

You might also like