# 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;

```auto
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.

```auto
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)

```auto
sudo raspi-config
<Interfacing Options>
<1-Wire> Enable/Disable
<Back>
<Finish>
```

![](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;

```auto
sudo raspi-config
<Interfacing Options>
<I2C> Enable/Disable
<Enable>
<Back>
<Finish>
sudo reboot
```

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

## Test the I2C Bus
```auto
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)

```auto
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;

```auto
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
```auto
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;

```auto
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.

```auto
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.


## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [AtariFruit 2600 Joystick](https://learn.adafruit.com/atarifruit-2600-joystick.md)
- [NeoPixel Bracelet](https://learn.adafruit.com/neopixel-bracelet.md)
- [Solderless Robot Toy Xylophone](https://learn.adafruit.com/solderless-robot-toy-xylophone.md)
- [Adafruit DS2484 I2C to 1-Wire Bus Adapter Breakout](https://learn.adafruit.com/adafruit-ds2484-i2c-to-1-wire-bus-adapter-breakout.md)
- [Glowy Message Crown](https://learn.adafruit.com/glowy-message-crown.md)
- [Camera LED Ring Light](https://learn.adafruit.com/camera-ring-led-light.md)
- [PyPortal IoT Plant Monitor with Google Cloud IoT Core and CircuitPython](https://learn.adafruit.com/pyportal-iot-plant-monitor-with-google-cloud-iot-core-and-circuitpython.md)
- [Color Sensing Music Player](https://learn.adafruit.com/color-sensing-music-player.md)
- [A CircuitPython BLE Remote Control On/Off Switch](https://learn.adafruit.com/circuitpython-ble-remote-control-on-off.md)
- [CircuitPython Libraries on Linux and Raspberry Pi](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux.md)
- [Motorized Marble Machine](https://learn.adafruit.com/marble-run.md)
- [Halo Energy Sword RP2040](https://learn.adafruit.com/halo-energy-sword-rp2040.md)
- [Pyloton: CircuitPython Cycling Computer](https://learn.adafruit.com/pyloton.md)
- [USB Host to BLE Keyboard Adapter](https://learn.adafruit.com/esp32-s3-usb-to-ble-keyboard-adapter.md)
- [NeoPixel Rotary Fidget](https://learn.adafruit.com/neopixel-rotary-fidget.md)
