Chapter 3

Reading Digital and Analog Input

IN THIS CHAPTER

check Reading the status of the GPIO ports

check Building an analog-to-digital converter

check Using a potentiometer as input

In the previous chapter, I explain how you can use your Raspberry Pi’s GPIO ports in output mode, sending digital HIGH and LOW signals to the output ports by using the GPI.output function.

In this chapter, I turn the tables and use the GPIO ports as inputs. Here, I explain how to read a digital input from a GPIO port, which is easy because a digital input is simply HIGH or LOW. I also explain how to do something a bit more complicated: read an analog input through a digital port. This can be useful, for example, if you want to use a potentiometer as input to a Raspberry Pi. Unlike Arduino or BASIC Stamp, Raspberry Pi does not have a built-in ability to read analog input. As a result, you’ll have to construct some external circuitry to convert analog input — such as the voltage level flowing through a potentiometer — to a digital value that the Pi can use. I explain how to create and use an analog-to-digital converter in this chapter.

Using a GPIO Port for Digital Input

In Chapter 2 of this minibook, I explain how ...

Get Electronics All-in-One For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.