Raspberry Pi 2 Starter Kit Hookup Guide

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

View the updated tutorial: Raspberry Pi 3 Starter Kit Hookup Guide

Pages
Contributors: MTaylor
Favorited Favorite 1

Reading Inputs and Toggling the LEDs

This section contains instructions for getting the software necessary to compile programs that use the GPIO, then redirects to our Raspberry gPIo tutorial.

Getting WiringPi for Using C++

The wiringPi library is required to operate the GPIO with C++. There are two methods to get it. Either way, it will have to be built before use.

Get From the WiringPi

Note: Wiring Pi is now pre-installed with standard Raspbian systems. The instructions from the official WiringPi homepage are now depreciated. The original wiringPi source "git://git.drogon.net/wiringPi" is not available.

Wiring Pi is previously not included with early versions of Raspbian. This required users to download and install it. Luckily, Wiring Pi is included in standard Raspbian systems. If you are looking to update using a mirrored Wiring Pi with small updates to support newer hardware, we recommend checking out this GitHub repository.

You'll need git (may be installed by default). If git is not installed, enter the following into the command line.

pi@raspberrypi ~/code $ sudo apt-get install git-core

We highly recommend using Git to download the latest version. To check what version you have, enter the following command.

pi@raspberrypi ~/code $ gpio -v

If you receive an output similar to to the following with the Unknown17, you'll want to update WiringPi on a Raspberry Pi 4 or above.

language:bash
gpio version: 2.50
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Unknown17, Revision: 02, Memory: 0MB, Maker: Sony
    * Device tree is enabled.
    * --> Raspberry Pi 4 Model B Rev 1.2
    * This Raspberry Pi supports user-level GPIO access.

Enter the following to remove the wiringPi and configuration files. Then use the hash command for the Pi to remove all locations that remember wiringPi.

pi@raspberrypi ~/code $ sudo apt-get purge wiringpi
pi@raspberrypi ~/code $ hash -r

As long as you have Git installed, these commands should be all you need to download and install Wiring Pi:

pi@raspberrypi ~/code $ git clone https://github.com/WiringPi/WiringPi.git
pi@raspberrypi ~/code $ cd WiringPi
pi@raspberrypi ~/code/WiringPi $ git pull origin
pi@raspberrypi ~/code/WiringPi $ ./build

This will make a folder in your current directory called WiringPi, change the directory to Wiring Pi, and pull the latest changes from the origin. The final command is a script to build Wiring Pi from the source files. This builds the helper files, modifies some paths in Linux and gets WiringPi ready to rock.

At this point, the library should work. Try it out by entering the following command. An Ascii table of pins and states should appear.

pi@raspberrypi ~/code/WiringPi $ gpio readall

Getting Python

Raspian comes with Python pre-installed. Continue to the gPIo tutorial to find out how to use it.

Using the GPIO.

This excellent tutorial on the INs, OUTs, and PWMs of GPIO with the Pi platform. It includes operation of the Pi 2 Model B!

Raspberry gPIo

October 29, 2015

How to use either Python or C++ to drive the I/O lines on a Raspberry Pi.