Building a Raspberry Pi Pushbutton Switch
Published on 2/20/2017 4:23:24 AM
Description
<style>.e_editor{font:14px/24px Arial,'microsoft yahei','Times New Roman','b8bf53';}.e_editor div,e_editor p,e_editor td,e_editor th,e_editor li{font-weight:inherit;font-size:inherit;font-style:inherit;font-family:inherit;}.e_editor ul{margin:-10px 0 20px;}.e_editor li{padding:5px 0;}.e_table{width:96%;border-collapse:collapse;empty-cells:show;}.e_table th,.e_table td{padding:5px;border:2px solid #eee;}.e_img{padding:10px 0;text-align:center;}.e_p{line-height:20px;padding:0 0 20px;text-indent:0em;}</style><p> Want to build a Raspberry Pi Controller? You got it: </p><p> The Raspberry Pi (RPi) is a powerful single board Linux computer that allows a variety of programming projects and electronic devices to be created. This is a part one in a series of Raspberry Pi projects. With an accessible GPIO (General Purpose Input Output) dual inline female header connector, a variety of electrical, electronic, and electromechanical components and devices can be wired to the Raspberry Pi. In addition, the RPi has support features like audio, HDMI, composite video, camera, USB, and LCD devices using standard elecrical connectors, audio, and RCA phono jacks. Connecting to the web is easily accomplished by way of a standard Ethernet connector. To bring your maker devices to life, the RPi uses the Python programming language, which comes standard with the Debian Linux distro operating system installed on the SD card. In this introductory project to building RPi electronic controllers, you'll learn how to wire a programmable tactile based pushbutton switch to the RPi and read its status using a basic Python script </p><p> The programmable switch doesn't required a lot of electronic components and is quite easy to build. The Parts Lists for the programmable switch is shown below . </p><p><br/></p><p> Supplies Needed </p><p><br/></p><ul class=" list-paddingleft-2"><li><p> (1) tactile pushbutton switch </p></li><li><p> (1) Raspberry Pi </p></li><li><p> (1) solderless breadboard </p></li><li><p> several jumper wires </p></li></ul><p>Installing the RPi.GPIO Library </p><p><br/></p><p> In order to read the tactile pushbutton switch status, the RPi.GPIO library needs to be installed on the Raspberry Pi. The RPi.GPIO is a software module that conveniently allows the Raspberry Pi GPIO pins to be manipulated for electronic controls applications. To install the RPi.GPIO library onto the Raspberry Pi, open the LXTerminal and type the following linux installation command after the prompt: </p><p> pi@raspberrypi ~ $ sudo apt-get install python-dev python~rpi.gpio </p><p> After the linux installation command is entered, you will see a series of RPi.GPIO bulld-installation file sequences being displayed on the monitor as shown below. </p><p><img src="https://jpfile1.oss-cn-shenzhen.aliyuncs.com/allpcb/web/image/20190605/6369534316174654102838968.jpg" alt="153702655.jpg"/></p><p> Once the build is complete, the RPi is ready for reading the status of a tactile pushbutton switch. </p><p> Wiring the Tactile Pushbutton Switch to the RPi </p><p> Attaching a tactile pushbutton switch to the RPi is quite easy to do. An important item to remember is the RPi's GPIO pins are +3.3VDC compliant. Applying voltages greater than +3.3VDC will damage the RPi. The electrical wiring diagram for attaching the tactile pushbutton switch is shown next. </p><p><img src="https://jpfile1.oss-cn-shenzhen.aliyuncs.com/allpcb/web/image/20190605/6369534322265377554593887.png" alt="153714134.png"/></p><p> As an additional project build material, I included an equivalent circuit schematic diagram for reference below. </p><p><img src="https://jpfile1.oss-cn-shenzhen.aliyuncs.com/allpcb/web/image/20190605/6369534327776255307623644.png" alt="153723997.png"/></p><p> Although, the circuit wiring to the RPi is quite simple, recheck the wiring before programming the RPi. This important verification step will assure you project execution success when the python code is installed and running on the RPi. </p><p> The Programmable Switch Python Script </p><p> The next phase of the project build is to provide a python script for reading a tactile pushbutton switch wired to a RPi GPIO pin. The python script for reading a tactile pushbutton switch is shown next. </p><p> import RPi.GPIO as GPIO import timeGPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN,pull_up_down=GPIO.PUD_UP)while True: inputValue = GPIO.input(18) if (inputValue == False): print("Button press ") time.sleep(0.3) </p><p> You can entered this script using either the LXTerminal's nano editor or with the Python's IDLE (Integrated Development Enviroment). Save the script as pbbutton.py in the home/pi directory of the RPi. Next, type the following linux command to run the script on the RPi into the LXTerminal as shown next. </p><p>pi@raspberrypi ~ $ sudo python pbbutton.py </p><p> Next, press the tactile pushbutton switch. If the script was typed correctly, you will see the message "button press" displayed on the monitor's screen. Congratulations on building a programmable pushbutton switch! </p><p> The tactile pushbutton switch can easily be programmed to provide a variety of output messages and switching responses. Try changing the "Button Press" message to display your name or a whimiscal word when activating the switch. Record your results in a laboratory notebook. </p>
151
comment
All comments
4706
0
151
Rules about cashback: 1. Valid time: ALLPCB cashback activity will end on April 1st. 2. Capped amount: The capped amount of cashback for each account is $5,000. Each order can get a maximum of $2,000 cashback. That means every author can get $5,000 max. 3. Cashback range: The cashback activity only covers the corresponding PCB order. The order amount for other combined payment products will be invalid. 4. Clicking your own promotional link will be invalid. The same email address, shipping address, contact information, and phone number are all recognized as the same account. 5. ALLPCB has the final interpretation right of the cashback activity.
ALLPCB will donate 2% to the author for this promotion link.