# Large Pi-based Thermometer and Clock

## Overview

This project combines a whole heap of modules to enable a Raspberry Pi to power a large 1.2 inch 4 digit 7 segment display. A small switch switches the display between showing the temperature and the current time. The project uses a real-time clock (RTC) to ensure that the Pi always has the correct time, even if it is not connected to the Internet.

![](https://cdn-learn.adafruit.com/assets/assets/000/006/396/medium800/raspberry_pi_overview.jpg?1396835749)

# Large Pi-based Thermometer and Clock

## Hardware

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/078/623/medium800/temperature___humidity_ds1307.jpg?1564094092)

The RTC will allow a Raspberry Pi to know the time, even when not connected to the Internet. As such it is not essential to this project if your Raspberry Pi is going to have an Internet connection.

The diagrams show GND connections in blue, +5V in red and +3.3V in purple.

The I2C bus connections use orange wire for SDA and yellow for SCA.&nbsp;

## 40-Pin (A, B, B+ and Zero) Cobbler Plus Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/078/625/medium800/temperature___humidity_Large_Pi_Based_Thermometer_Clock_bb.png?1564094808)

## 26-Pin (Raspberry Pi Rev 1 and Rev 2) Cobbler Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/006/463/medium800/raspberry_pi_fritzing4.png?1396836686)

You may also like to look at separate tutorials for the RTC [http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi](http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi "Link: http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi") and temperature sensor [http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing](http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing "Link: http://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing")

When everything is assembled, you can connect the ribbon cable to the GPIO connector. Remember to have the red or white band of the ribbon cable towards the SD card on the Raspberry Pi.

# Large Pi-based Thermometer and Clock

## Pi Prep

## Update Your Pi to the Latest Raspbian
Your Pi will need to be running the latest version of Raspbian. This tutorial was written using Raspbian Buster (July 2019). Checkout our guide for&nbsp;[Preparing an SD Card for your Raspberry Pi](https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi)&nbsp;if you have not done so already. After the installation is complete be sure and run the following commands to make confirm your installation packages are up to date.&nbsp;

```
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/675/medium800/temperature___humidity_apt-get.jpeg?1564185432)

## Install adafruit-blinka
Run the following command to install the&nbsp;adafruit\_blinka CircuitPython Libraries.

```
pip3 install adafruit-blinka
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/630/medium800/temperature___humidity_IMG_3015.jpg?1564101181)

## Enable 1-Wire Interface

You'll need to start by enabling support for the DS18B20 1-Wire subsystem.

[Visit this page for instructions on using raspi-config to enable 1-Wire support.](../../../../adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/ds18b20)

```
sudo raspi-config
&lt;Interfacing Options&gt;
&lt;1-Wire&gt; Enable/Disable
&lt;Back&gt;
&lt;Finish&gt;
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/626/medium800/temperature___humidity_1-wire-2.png?1564098471)

## Enable I2C Interface
Our clock and 7-segment display work using I2C bus which the Raspberry Pi supports, but it needs to be enabled. This [page has step by step instructions](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c). Enabling I2C is almost an identical process as enabling 1-Wire except that a reboot is required and we want to make sure to install the optional packages to scan the bus.&nbsp;

```
sudo raspi-config
&lt;Interfacing Options&gt;
&lt;I2C&gt; Enable/Disable
&lt;Enable&gt;
&lt;Back&gt;
&lt;Finish&gt;
sudo reboot
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/673/medium800/temperature___humidity_i2c.png?1564184752)

## Test the I2C Bus
```
lsmod | grep -i i2c
```

Now that our Pi has rebooted we can confirm that the correct I2C modules have loaded with the following command.

![](https://cdn-learn.adafruit.com/assets/assets/000/078/628/medium800/temperature___humidity_IMG_3017.jpg?1564101154)

```
sudo i2cdetect -y 1

```

This shows that two I2C addresses are in use – 0x68 and 0x70.

Note that if you are using one of the very first Raspberry Pis (a 256MB Raspberry Pi Model B) then you will need to change the last digit of the command port 1 to port 0.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/078/629/medium800/temperature___humidity_IMG_3016.jpg?1564101169)

# Install the HT16K33 Library
The software for this project uses the Adafruit code for driving the 7 segment display.&nbsp;

```
pip3 install adafruit-circuitpython-ht16k33
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/841/medium800/temperature___humidity_ht16k33.png?1564521968)

# Large Pi-based Thermometer and Clock

## Software

## CircuitPython Code
The main loop simply checks the position of the switch and then either displays the temperature or the time.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Large-Pi-Based-Thermometer-Clock/thermo_clock.py

We can easily copy this code onto our Pi's home directory using the 'wget' command and run it using the following python syntax.

## Download the Code
```
cd
wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Large-Pi-Based-Thermometer-Clock/thermo_clock.py
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/679/medium800/temperature___humidity_wget.png?1564186693)

## Run the Code
The thermo\_clock.py script will not output anything when run, but what you should see is the time or temperature on the large 7-segment display. Using the slide switch should switch modes between time and temperature.&nbsp;

```
python3 ./thermo_clock.py
```

![](https://cdn-learn.adafruit.com/assets/assets/000/078/682/medium800/temperature___humidity_thermo_clock.png?1564187042)

## Changing Temperature Units
The temperature display can easily be changed from displaying degrees F to degrees C by swapping comment line in the code.

```
temp = int(read_temp()[1]) # F
# temp = int(read_temp()[0]) # C
```

To swap, just move the # in front of the line that does not apply.


## Featured Products

### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
### Adafruit DS1307 Real Time Clock Assembled Breakout Board

[Adafruit DS1307 Real Time Clock Assembled Breakout Board](https://www.adafruit.com/product/3296)
This is a great battery-backed real time clock (RTC) that allows your microcontroller project to keep track of time even if it is reprogrammed, or if the power is lost. Perfect for datalogging, clock-building, time stamping, timers and alarms, etc. The **DS1307** is the most...

In Stock
[Buy Now](https://www.adafruit.com/product/3296)
[Related Guides to the Product](https://learn.adafruit.com/products/3296/guides)
### Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red

[Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red](https://www.adafruit.com/product/1270)
What's better than a single LED? Lots of LEDs! A fun way to make a numeric display is to use a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). LED matrices like these are 'multiplexed' - so to control all the seven-segment LEDs you need 14 pins....

Out of Stock
[Buy Now](https://www.adafruit.com/product/1270)
[Related Guides to the Product](https://learn.adafruit.com/products/1270/guides)
### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3 & Pi 4!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
### DS18B20 Digital temperature sensor + extras

[DS18B20 Digital temperature sensor + extras](https://www.adafruit.com/product/374)
These 1-wire digital temperature sensors are fairly precise (±0.5°C over much of the range) and can give up to 12 bits of precision from the onboard digital-to-analog converter. They work great with any microcontroller using a single digital pin, and you can even connect multiple...

In Stock
[Buy Now](https://www.adafruit.com/product/374)
[Related Guides to the Product](https://learn.adafruit.com/products/374/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

In Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Breadboard-friendly SPDT Slide Switch

[Breadboard-friendly SPDT Slide Switch](https://www.adafruit.com/product/805)
These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1" spacing and snap in nicely into a solderless breadboard. They're easy to switch no matter what size fingers you have, but not so easy that they'll get flipped by accident. Work great as...

In Stock
[Buy Now](https://www.adafruit.com/product/805)
[Related Guides to the Product](https://learn.adafruit.com/products/805/guides)
### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

Out of Stock
[Buy Now](https://www.adafruit.com/product/758)
[Related Guides to the Product](https://learn.adafruit.com/products/758/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [CircuitPython Hardware: LED Backpacks & FeatherWings](https://learn.adafruit.com/micropython-hardware-led-backpacks-and-featherwings.md)
- [Raspberry Pi Physical Dashboard](https://learn.adafruit.com/raspberry-pi-physical-dashboard.md)
- [CircuitPython Libraries on Linux and Google Coral](https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka.md)
- [DS1307 Real Time Clock Breakout Board Kit](https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit.md)
- [LoRa and LoRaWAN Radio for Raspberry Pi](https://learn.adafruit.com/lora-and-lorawan-radio-for-raspberry-pi.md)
- [NeoMatrix 8x8 Word Clock](https://learn.adafruit.com/neomatrix-8x8-word-clock.md)
- [Node.js Embedded Development on the Raspberry Pi](https://learn.adafruit.com/node-embedded-development.md)
- [Capacitive Touch Sensors on the Raspberry Pi](https://learn.adafruit.com/capacitive-touch-sensors-on-the-raspberry-pi.md)
- [Adafruit's Raspberry Pi Lesson 11. DS18B20 Temperature Sensing](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.md)
- [Adafruit's Raspberry Pi Lesson 13. Power Control](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-13-power-control.md)
- [Adding Basic Audio Ouput to Raspberry Pi Zero](https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero.md)
- [Adafruit's Raspberry Pi Lesson 10. Stepper Motors](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-10-stepper-motors.md)
- [CircuitPython Libraries on Linux and ODROID C2](https://learn.adafruit.com/circuitpython-libaries-linux-odroid-c2.md)
- [Arduino GPS Clock](https://learn.adafruit.com/arduino-clock.md)
