We’ve come across more and more Pi fans who want to use their little friend to measure temperature. We’re not sure of the origins of this trend, but heck – who cares? Figuring out how to achieve this feat was always gonna be fun.
So here’s a way to program your Pi to measure heat using a digital “1-wire” sensor hooked up to one of its GPIO pins. Plus we’ll show you how you can control a digital output using the measured temperature…AND how you can use your Pi along with an LED driver chip to flash up the temperature on a multiple digit LED display.
Ready? Let’s do this thing…
As you can probably guess, we’re going to split this exercise into three “Steps” of increasing complexity to make life easy.
For starters, we’ll look at 1-wire digital sensor technology and show how these sensors can be easily interfaced with the GPIO port on your Raspberry Pi.
Next, you’ll find out a bit about the IDLE integrated development environment and the Python programming language. We’ll also check out how to create a file containing a series of Python commands and how to save this as a “computer program” before “running” the program. This is all pretty simple stuff, so we’ll also explore operating system kernels and how you can load modules into them to provide support for hardware interfaces. Finally for this step, we’ll show you some basic data manipulation and formatting in Python, including the “while” loop and “if…else” statement.
So far so good. To finish off, we’ll talk about serial and parallel data interfaces, and show you how to configure your Pi to use the SPI protocol. You’ll also find out about the “apt-get” command to download, install and update software packages from the Debian repository too, and we’ll download Python code from GitHub. To help you along the way, we’ll look at basic data transfer between your Pi and peripheral hardware by sending data to the LED driver chip. That means you’ll get to know something about using hexadecimal notation to represent of binary data.
Oh, and when we’re using Python, we’ll also check out the “try and “except” statements along with how to re-use and adapt code by loading/editing the code from the step before.
Remember – we’ve put these exercises together using a Raspberry Pi Model B with a 26 Way GPIO Pin header. Newer models have a 40 Way GPIO header, but the first 26 pins ae the same.
Ready to get started? Check out these files for all the exercises and your Raspberry Pi Setup guides: