Reader small image

You're reading from  Practical Python Programming for IoT

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838982461
Edition1st Edition
Languages
Right arrow

The code solution

We can solve our floating pin situation in code by telling our Raspberry Pi to activate and connect an embedded pull-up resistor to GPIO 21, which, according to the Raspberry PI's documentation, will be within the range 50kΩ-65kΩ, hence why we stipulated that range in the circuit shown in the previous diagram.

The following diagram shows a circuit similar to the one shown in the preceding diagram, but without the physical resistor in the external circuit. I've added a resistor inside the Raspberry Pi diagram to illustrate the fact that there is a physical resistor hiding away somewhere in the Raspberry Pi's circuitry, even though we can't see it:

Figure 6.7 – Push button circuit using an embedded pull-up resistor

Let's enable a pull-up resistor in code and test this circuit. Here are the steps for you to follow:

  1. This example uses the push button circuit shown previously in Figure 6.5. Please...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Python Programming for IoT
Published in: Nov 2020Publisher: PacktISBN-13: 9781838982461