element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Documents Video 4: Your First Pi Project
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: kellyhensen
  • Date Created: 26 Jan 2014 11:48 PM Date Created
  • Last Updated Last Updated: 10 May 2021 7:14 PM
  • Views 2249 views
  • Likes 1 like
  • Comments 1 comment
Related
Recommended

Video 4: Your First Pi Project

This is the fourth video in our 2013 five-part series Get Started With Pi for Raspberry Pi 2..

 

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Episodes in this Series

 

Video 1: Unboxing and Setting up the Peripherals


Video 2: Exploring the Raspberry Pi


Video 3: Getting Your Pi Online


image  Your First Pi Project


Video 5: Exploring Accessories and Projects

 

Using External Controls and your Pi

Although this project does require some programming, you don’t need to know how to program to follow along with this video.  The code you need is available for download below on this page.

 

GPIO Pins

 

imageYou’ll need to take the Raspberry Pi out of its case to access the GPIO Pins.  GPIO stands for “General Purpose Input Output” and you’ll find this method of interacting with the Pi is used in a lot of projects that can be found on element14 in our Raspberry Pi Projects.

 

GPIO pins are “generic” – they can be used as input or output devices – and can be controlled with programs running on your Raspberry Pi.

 

Pi Cobber Kit (Adafruit)

We’ll be connecting to the GPIO pins with a Pi Cobbler kitPi Cobbler kit – available on the element14 site from our friends at Adafruit.  The Pi Cobbler Breakout Kit has three main pieces:

 

image. . . a 26-pin ribbon cable
image. . . a connector that attaches to the ribbon.

 

The one pictured on the bottom connects to the PCB.  You can tell the difference because the one on the bottom has that little tab – that helps it line up properly on the PCB.
image
image
image
image
image

. . . a PCB board

 

The PCB is printed with information about the pins that stick into the breadboard.

  • The labels show you which pins
  • Are Ground
  • Carry a 5.0 volt power supply (Use caution – 5.0 volt power can damage the Raspberry Pi)
  • Carry a 3.3 volt power supply
  • Can serve as input or output pins

 

Adafruit Pi Dish

 

image

The Adafruit Pi Dish includes this clear acrylic board, some mounting posts to hold the Pi securely in place and the breadboard itself.

 

There’s a great video on the Adafruit site that shows how to assemble all the pieces.

 

Some people call these solderless breadboards since you can connect a variety of things without having to solder them all together.  Each of these little holes in the breadboard is a socket where you can push in things like led lights, buttons or jumper wires.

 

Breadboards have two columns of sockets in the middle – ours has one side labeled A through E and the other side labeled F through J.  All of the sockets in each row are “connected.”

 

On the outside of both edges are power rails – usually the blue line is used for ground and the red line is used for power.

 

Connect one End of the Ribbon Cable to the Pi and the other End to the Breadboard

 

The ribbon cable has a white line down one side. (Black ones usually have a red line; grey ones usually have a red line.)  That line represents the side of the ribbon that should be connected to Pin one.  On the Pi – Pin one is in the corner of the board so plug in ribbon with the line on the corner.

pins_explodedlarge.png

Be careful – it can be plugged in backwards!

 

The other end of the ribbon cable has a little tab on it – that helps line it up and snap in to the PCB.

 

Plug the PCB into the Breadboard

 

PCBheader.gifThere are two rows of pins on the bottom of the PCB – each row has to be plugged in to a different column A-E or F-G on the breadboard.

 

Connect the Jumper Wires on the Breadboard

The ribbon has been disconnected in the photos below to better illustrate the wiring.

 

image

First Power the board.

Find a pin labeled 3.3v and run a jumper wire from the row of pins in columns A-E with the power – or red rail on the same side (green wire).


Then find a pin labeled GND and run a jumper wire from that row of pins to the blue rail on the opposite side (orange wire).

imageNext, run a jumper wire from Pin 22 to any open row above (yellow wire).
image

Next add the resistor from the same row as the yellow wire to the power rail.


Add the button in the center – spanning the gap between the two columns much like the PCB.  The bottom pins of the button should be on the same row as the yellow wire.


In the same row as the top pins of the button, add another wire to the blue (ground) line.

 

Now Power up your Raspberry Pi

The following strings are to be entered in LX Terminal.  Be sure your Raspberry Pi is connected to the Internet.

 

Updating and Upgrading

Remember, it's always a good idea to keep your Raspberry Pi Operating System (in this case, Raspbian) up-to-date.

 

sudo apt-get update

This command downloads the latest version of the OS to your Pi – it may take a while, depending on your network speed.

sudo apt-get upgrade

This command installs the upgraded code (that you just downloaded above) on to your Pi. After you press enter, it will calculate how much space will be required for the new version.  It will say something like. . .

After this operation, xxxMB of additional disk space will be used.

Do you want to continue [Y/n]?

Press Y to continue.

 

Install Python Development Kit and the RPI.GPIO

 

sudo apt-get install python-dev

Type this in to install the Python Development Kit

sudo apt-get install python-rpi.gpio

Type this in to install the RPI.GPIO

. . . you’ll be prompted to enter “Y” to confirm the install

 

Create the Python File

 

nano pi-audio-button.py

One way to create a Python file is to use nano - this command will open an editor screen.


Save these two files to a thumb drive (in Windows, right click link and select “Save target as. . .”):
  pi-audio-button.py.txt
  cow.mp3
  and then connect the thumb drive to your Raspberry Pi.


Open file manager on your Pi, copy cow.mp3 to your Pi directory.  Then select pi-audio-button.py.txt and double-click to open it.


Select all the text and then toggle to the nano editor running in LXTerminal and right click to select Paste.


Once the text is in nano, press control-x (you'll be prompted to save your work).  Press Y and then press enter to save it as the same name.

chmod +x pi-audio-button.py

Run this string to make the file executable – if you don’t do this step the program won’t run.

sudo python pi-audio-button.py

This command string will run the program.

When you see the text “When you’re ready, please press the button. . . “ press the button you installed on the breadboard.  The audio file should play.  And you’ve created your first pi project!

 

Remember – everything in Linux is case sensitive so make sure you don’t inadvertently capitalize a word. Python is also quite particular about its indentation – that’s how it understands which commands work together – so be sure to set up the file exactly like it’s displayed.  Download this as a text file: pi-audio-button.py.txt

 

import time, os
try:

 

#Make sure we can import the GPIO library
import RPi.GPIO as GPIO

 

except RuntimeError:

print ("Unable to import GPIO library.  Make sure that this is being run as root and that RPi.GPIO is properly installed!")

 

#Pins will be referenced by the processor's numbering scheme
GPIO.setmode(GPIO.BCM)

 

#Tell the program you want to use pin number 22 as the input
GPIO.setup(22, GPIO.IN)

 

#Set up a function to check the state of the GPIO pin
def waitcheck():

 

loop=1
print ("When you're ready, please press the button. . . ")
while (loop):

 

#Run as long as loop is nonzero and check the state of the button ten times per second

time.sleep(0.1)

 

#If the button is pressed

if(GPIO.input(22)==0):

 

#Cleanup GPIO since it is no longer needed

GPIO.cleanup()

 

#Do not loop again

loop=0

 

#Say the cow is coming

print ("Here comes the cow!")

 

#Actually play the sound

os.system("omxplayer -o hdmi cow.mp3")

 

try:

#call function, this will run forever
waitcheck()
#Exit this program if control-c is pressed

except KeyboardInterrupt:

#Restore GPIO to default state
GPIO.cleanup()

 

  • raspberry
  • your
  • pi
  • project
  • video
  • first
  • with
  • 4:
  • started
  • get
  • raspberry_pi_getting_started
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
  • glennpd
    glennpd over 11 years ago

    Thanks for the entertaining video. A couple of comments: (1) The Python code appears to be using set mode GPIO.BOARD (Pin 22) as opposed to GPIO.BCM  (GPIO25). (2) To hear the cow, my audio is ported as "omxplayer -o local cow.mp3" instead of through the hdmi cable. Thanks again for your introduction to GPIO!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube