Book Image

Raspberry Pi Essentials

By : Jack Creasey
Book Image

Raspberry Pi Essentials

By: Jack Creasey

Overview of this book

Table of Contents (15 chapters)
Raspberry Pi Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

TKinter switch demo


Since the action code for Python is so similar to that for TKinter, we will go directly to a TKinter interface for switch sensing. Since the plan is to eventually create push buttons for our Internet radio, let's show the breadboard schematic that we need to achieve this:

Note

Warning: While the schematic shown is quite OK for breadboard use, it is not suitable where the wires to the switches are long (greater than a few inches). Notice that the GPIO pin would be exposed directly to any fault conditions. It is advisable to put at least a 1k Ohm series resistor to the GPIO pin. Never run the 5 Volt or 3.3 Volt supply through a long line to the switch (or LED location) as this directly exposes the supply to any potential wiring faults.

In preparation for the demo, complete the following:

  1. Download the tkswitch21.py code from http://1drv.ms/1ysAxkl.

  2. Store the tkswitch21.py file in /home/pi/gpio.

  3. Run the code using IDLE3 by starting from a command line with sudo idle3 (remember...