World's Fastest PCB Manufacturing
My Message
Suggestions
Account

Get started now

Log In

or

Sign Up

My ALLPCB

My Orders Shipping Address Balance Account Settings My SNS Profile
0
  • Home
  • Instant Online Quote Alternate Text
    • PCB Instant Quote
    • PCB Assembly Quote
    • SMD-Stencil Quote
  • PCB Assembly
  • PCB Capabilities
  • Feedback
  • Resources
    • Sponsorship
    • PCB Softwares
    • Units Conversion
    • FAQ
  • About Us
    • About Us
    • About Us
    • Why Us
    • Contact Us
    • News
Log In Sign Up
  • Home
  • Instant Online Quote
    • PCB Instant Quote
    • PCB Assembly Quote
    • SMD-Stencil Quote
  • PCB Assembly
  • PCB Capabilities
  • Feedback
  • Resources
    • Sponsorship
    • PCB Softwares
    • Units Conversion
    • FAQ
  • About Us
    • About Us
    • Why Us
    • Contact Us
    • News
service@ALLPCB.com
Thank you very much for your valuable suggestion!
We will solve it as soon as possible!

Building a Raspberry Pi Pushbutton Switch

2/20/2017 4:23:24 AM

Want to build a Raspberry Pi Controller? You got it:

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

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 .


Supplies Needed


  • (1) tactile pushbutton switch

  • (1) Raspberry Pi

  • (1) solderless breadboard

  • several jumper wires

Installing the RPi.GPIO Library


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:

pi@raspberrypi ~ $ sudo apt-get install python-dev python~rpi.gpio

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.

153702655.jpg

Once the build is complete, the RPi is ready for reading the status of a tactile pushbutton switch.

Wiring the Tactile Pushbutton Switch to the RPi

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.

153714134.png

As an additional project build material, I included an equivalent circuit schematic diagram for reference below.

153723997.png

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.

The Programmable Switch Python Script

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.

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)

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.

pi@raspberrypi ~ $ sudo python pbbutton.py

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!

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.

  • 4107
  • 1
  • 151
Post Comment

    Christopher

    2/22/2017 4:23:24 AM

    Great article! Keep up the great writing.

    You might like

    aaaa

    • Threads

      0

    • Following

      0

    • Followers

      0

    PCB Prototype

    PCB Instant Quote

    x mm

    Quantity

    Quote Now

    PCB Assembly

    SMT-Stencil

    • 12
    Products & Service
    PCB Capabilities
    Aluminum PCB Service
    PCB Assembly Service
    SMT-Stencil
    Quotation & Feedback
    Online Auto-Quotation
    PCB Assembly Quote
    Quote by Salesperson
    Customer Reviews
    Customer Support
    FAQ
    Community
    Sponsorship
    Referral Program
    About Us
    About Us
    Why Us
    Contact Us
    News
    Resource Details
    PCB Software
    Units Conversion
    service@allpcb.com central_support@allpcb.com
    Follow Us:
    Facebook Youtube Twitter Tumblr Youtube
    Certification: Certification
    Our Preferred Partners: Our Preferred Partners

    Please send Gerbers to service@ALLPCB.com for quotation © Label_AllpcbcomallRightsReserved Privacy PolicySitemap

    Secure Site by GoDaddy.com This site has earned the McAfee SECURE certification.