You are on page 1of 41

The Raspberry Pi A Beginners Guide

December 3, 2015

This manual was produced in partial fulfillment of the requirements for a University professional writing course. The information contained in this
user manual is provided "as is". The author, though well-informed and experienced, is not professional or expert in the topic, so makes no
representations or warranties of any kind, expressed or implied, about the completeness of the information for a particular use, or
merchantability. Nor does the author make any representations of freedom from infringement of any intellectual property or proprietary rights of any
third party. You use the information at your risk. You are advised to consult an appropriate professional if you have any doubts related to the
advice or procedures in this manual.

Table of Contents
Title Page
Table of Contents.. 1
Introduction/Summary.. 2
Raspberry Pi Basics Section. 3-11
MicroSD Card Formatting. 3-6
Hardware.. 7-11
Linux Section.... 12-24
Linux Setup.. 12-19
PuTTY.. 20-23
Linux Commands.... 24
Electric Circuitry Section...25-30
Python/Twython Section.. 31-37
Helloworld... 31-32
Button Response.... 33-36
Twython... 37
Appendices.... 38-39
Works Cited/Resources. 40

Introduction/Summary
This manual covers the most basic aspects of using the Raspberry Pi, including obtaining the files to make the
Raspberry Pi run, putting these files onto a memory card, and plugging in all the necessary hardware to turn the
Raspberry Pi on for the first time. Next, the manual goes on to explain how to interact with the Raspberry Pi, connect to
the internet, as well as control it from a desktop computer or laptop. After this, a crash-course on electronic circuitry is
presented, which helps give a start in creating new circuits. Finally, an introduction to Python, the programming
language, is presented. In this section, several simple projects are designed and implemented, including a Twitter
monitor that blinks an LED every time a certain phrase is tweeted on Twitter.
The Raspberry Pi is an inexpensive, single-board computer created by the Raspberry Pi Foundation, a UK based
charity. The goal of the foundation is to expand access and interest in computers and computer science to a larger
audience, including children and adults. The Raspberry Pi can be used in a multitude of applications, and is capable of
video playback, word-processing, navigating the internet, playing games, programming, and more. Additionally, the
Raspberry Pi can be used with various electronic components, like light-emitting diodes (LEDs), motors, sensors, and
more, (What is a Raspberry Pi?).

Raspberry Pi Basics
MicroSD Card Formatting
Prior to doing anything with the Raspberry Pi, one needs to obtain a MicroSD card with an operating system on it. An
operating system is a package of software that tells a computer how to use its hardware. The best way of doing this is by
downloading the NOOBS files from the official Raspberry Pi website, and then copying them over to an empty MicroSD
card.
Go to https://www.raspberrypi.org/downloads/noobs/
Click Download ZIP under NOOBS

Navigate to the Downloads folder.


Extract files (Right click, Extract All, Extract)

Now insert the MicroSD card into the computers card reader. A microSD to SD card adapter will be required.

Copy the files from NOOBS to the MicroSD card.

Right click the MicroSD card on the left navigation column, click Eject

Remove the MicroSD card from the card reader.

Hardware
Now that the MicroSD card has the software it needs to tell the Raspberry Pi how to operate, we must connect various
peripherals to the Raspberry Pi in order to boot the device for the first time. Insert the MicroSD card into Raspberry Pi.

Here is an Ethernet cable, USB Wi-Fi dongle, and USB keyboard/mouse dongle. These are needed to connect the
Raspberry Pi to the internet, and to allow the user to interact with the Raspberry Pi.
NOTE: It is only necessary to connect either the Ethernet cable or the USB Wi-Fi dongle. It is not required to connect
both. The USB keyboard/mouse dongle, however, is needed in addition to either the Ethernet cable or the USB Wi-Fi
dongle.

Plug in either an Ethernet cable or a USB Wi-Fi dongle. (Both are pictured.)

Plug in keyboard/mouse. (In this case, the single USB dongle plugged into the bottom right USB port controls both the
wireless mouse and keyboard.)

Plug in the power cable (the microUSB cable), and an HDMI cable.

Here is a microUSB power cable for reference.

10

Here is an HDMI cable for reference.

Plug in the AC adapter side of the microUSB cable to a wall outlet, and connect the other end of the HDMI cable to an
HDMI TV.

11

Linux
Linux Setup
Now that the Raspberry Pi has an operating system, a means to connect to the internet, an interface for the user to
interact with, and power; it will now begin the booting process. The operating system, however, must be installed
because this is the first time that the microSD card is being used. This process does not need to be repeated any other
time the Raspberry Pi is turned on.
After a short period of time, the television will now show this.

Check the box next to Raspian, and then click install.

Now this dialogue box will appear. Click yes to acknowledge that the microSD card will be overwritten with the installed
operating system.
12

This window will now appear to show that the operating system is being installed, wait for it to finish.

13

This will then appear when the installation is finished. Click OK.

This will now bring you to the desktop.

14

Click this icon in the top right of the screen. This will allow you to configure your internet settings. Do so as you would on
any other device.

After connecting to the internet, click this icon in the top left corner to open the terminal. The terminal provides a way
to give text commands in order to have the Raspberry Pi do something.

15

This window will now open. We are now going to give the first command to the Raspberry Pi. Type sudo raspi-config
and the press enter. This command tells the terminal to open the basic configuration options for the Raspberry Pi.

16

This will now replace the black window of the terminal. Here we have several options to configure the Raspberry Pi.
First, the user password must be changed. Navigate to option two, Change User Password, with the arrow keys on the
keyboard, then press Tab on the keyboard until <Select> is highlighted in red. Then press enter. You will then be
prompted for a new password.
After changing the password you will be returned to the same configuration menu. Now navigate to option three, Boot
Options, in the same way as done before.

Select the option B1 Console. This option starts the Raspberry Pi at the command line (Essentially the terminal), and
requires the user to log in with your previously created password. You will now be navigated back to the main options
screen seen at the top of this page.
Now choose option eight, Advanced Options.
17

Now navigate to option A4 SSH, and select it. SSH is a way to set the Raspberry Pi to listen to commands from other
computers. By enabling this option, we will be able to communicate with the Raspberry Pi from other computers.

This option will now appear. Select <Enable>

18

The SSH server has now been enabled. Press enter to return to the main options screen.
Now press Tab until <Back> has been highlighted in red. Press enter to leave the configuration tool.

Press enter to confirm rebooting the device.

19

PuTTY
Now that the Raspberry Pi has power, is connected to a display, is connected to the internet, and has SSH enabled; we
can now control the Raspberry Pi remotely from another computer.
Because the Raspberry Pi has been rebooted, the display should now look like this.

It is requesting your login. The username is pi and the password was what was set in the previous section.
Now that the we are logged in, we are going to input the command hostname I
This command displays whatever IP address the Raspberry Pi is using on its current local network. Take note of whatever
numbers are returned after inputting this command. An IP address is a number that identifies devices connected to the
internet.

20

We will now return to our desktop to install PuTTY. PuTTY is a piece of software that allows you to control the
Raspberry Pi remotely, by using the IP address that was noted earlier.
First, we must install PuTTY by going to http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html on our
computer. Once there, click putty.exe to download the software.

Then, navigate to your downloads folder and open putty.exe


This window will now appear. In the Host Name (or IP address) section, type in pi@(THE IP ADDRESS YOU NOTED
EARLIER) and then click open

21

Now these two windows will appear, click yes to confirm that it is the Raspberry Pi you wish to connect to.

22

You will now be asked for the password you set earlier, input it now to login to the Raspberry Pi.

You have now logged into the Raspberry Pi from your desktop.

23

Linux Commands
We will now learn how to use various commands in Linux. These are basic enough to give one a start on navigating
directories (Where a Directory is essentially another word for folder), displaying helpful information, basic
file/directory manipulation, and basic Raspberry Pi control.
These commands are to be entered on this screen:

ls List everything in your current directory.


cd Change directory.
pwd Print working directory. The terminal will tell you what directory you are currently in.
clear Clear all text from the terminal.
uptime Show how long the Raspberry Pi has been on.
date Display current date and time.
cp Copy a file to another location.
mv Move a file to another location.
rm Remove a file.
mkdir Make a directory.
redir Remove a directory.
history Show command history.
hostname I Display current IP address.
reboot Restarts the Raspberry Pi.
sudo halt Shuts down the Raspberry Pi.
passwd Change the password.
Ctrl + c - Will stop any command that is running.
sudo nano FILE.FILETYPE Allows one to modify text based files.

24

Electric Circuitry
Everything that has been accomplished so far with the Raspberry Pi could be done on any other computer. What makes
the Raspberry Pi truly unique is the ability to directly integrate with electronic components.
First we will learn to light a light emitting diode, which is essentially a light bulb.
Here is a black jumper cable, red jumper cable, 330 ohm resistor, LED (Light emitting diode), and solderless breadboard.

Our goal in this section is to build this circuit:

In this circuit, a voltage source (labeled V1) with a value of five volts (5V), where a volt is a unit of electric potential,
leads into an LED (labeled D1). This LED then leads into a 330 ohm resistor (labeled R1), where an ohm is a measure of
electric resistance and a resistor is an electronic component that converts electricity to heat. This resistor finally leads
back to the ground (GND), or the zero volt (0V), side of the voltage source.
25

This is the pin layout of the Raspberry Pi. (Above)


(Raspberry Pi 2 Model B GPIO 40 Pin Block Pinout)

Here is a solderless breadboard (On the left) with the connections it makes (On the right). (Above)
26

First, the red wire must be connected to the 5V pin on the Raspberry Pi. Using the chart above, it may be seen that
pins 02 and 04 are the 5V pins. With the Raspberry Pi off and disconnected from power (Using the command halt, and
then physically disconnecting the power cord), connect one end of the red jumper cable to pin 02. Then connect the
other end to a row on the solderless breadboard.

Now, connect the long end of the LED to the same row that the red jumper cable has been connected to, and the other
end to some other row on the breadboard.

27

Next, connect one of the ends of the resistor to the same row as the short end of the LED, and the other end of the
resistor to some new third row of the breadboard.

Finally, the black wire must be connected to the Ground pin on the Raspberry Pi. Using the chart above, it may be seen
that pins 09, 25, 39, 06, 14, 20, 30, and 34 are the ground pins. Connect one end of the black jumper cable to pin 06.
Then connect the other end to the same third row that the resistor was connected to.

28

Now when power is connected to the Raspberry Pi, the LED will now be on.

29

Here is a chart to determine the values of various resistors. For a 330 ohm resistor, the color code will start with
orange, orange, and then brown for a four band resistor.

(4 Band Resistor Color Code Calculator)

30

Python/Twython
Hello World!
Now we are going to explore Python, an easy to learn programming language that will allow us to do all sorts of
interesting things.
First, we will create a Python script to do some simple tasks for us. To do this we must first make a Python file in a
location we may reach.
When at the command line, enter the command cd to return you to the /home/pi directory. You can confirm for
yourself that you are at the correct location by inputting the command pwd. It should return a result of /home/pi.
Now we will navigate to the desktop. To first see what directories exist within the /home/pi directory, use the
command ls.
It should now tell you that several directories exist for you to explore. The one we wish to navigate to is Desktop. We
will do this by inputting the command cd Desktop. To ensure we are in the correct directory, we will again use the
command pwd. It should return a result of /home/pi/Desktop
If the previous commands were input correctly, our display should now show this.

To make our Python file, we are going to use the command sudo nano helloworld.py. helloworld.py is simply the
name of this Python file. This new display should now show:

31

This Python file is going to print out the words Hello world! for us. To do this we are going to type the following:

We shall now exit and save this file by inputting Ctrl + x. It will now ask if you wish to save, type y. Then it will ask
what file name you wish to have, simply hit Enter as we have already decided the name helloworld.py.
Now when you enter the command ls, it shall show you have a file titled helloworld.py.
Now, in order to run this file, we are going to give the command python helloworld.py, and see that the computer
prints out Hello world! for us.

32

Button Response
We will now have the Raspberry Pi receive input from a button, as well as adjust an LED based on this input.
First we will make another file, now titled buttonresponse.py and type in the following:

The way this code works is by activating the pins on the Raspberry Pi with the command import RPi.GPIO as GPIO and
also activating a stopwatch of sorts with the command import time.
The command GPIO.setmode(GPIO.BCM) tells the Raspberry Pi which pin is which, so when we say pin 6, it is the same
GPIO pin 6 featured on the electric circuit section chart.
Next, specific pins on the Raspberry Pi are given specific purposes. In this case, pin 6 is set as an output, meaning that
it will provide an electric current to whatever it is connected to. This is seen in the command GPIO.setup(6,
GPIO.OUT).
Additionally, pin 13 is set as an input, with a special bit of code that makes it easier to wire a button. This is done in the
line that states GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP).
The last bit of setup is done by setting the initial state of pin 6, the output, as LOW, meaning it provides no electric
current at first. This will cause the LED to be off when the code begins.
Now we have a loop, or a bit of code that runs over and over again until we stop it by pressing Ctrl + x. This loop
starts because of the command while True:.
Then the code follows a flowchart of sorts, as pictured below:

33

Now that we understand the code, we must create the two circuits needed for this section.
The first is very similar to the one created in the electric circuit section, except instead of the red wire being connected
to the 5V pin, it is instead connected to GPIO pin number 6. This is done because we cannot control the 5V pin, because
it will always give out an electric current. GPIO pin number 6, however, can be turned on and off.
The second circuit is very simple, as it simply connects ground (the 0V pin, or GND) to a button, and the opposite side of
the button is then connected to GPIO pin number 13. GPIO pin number 13 is used as an input, so whenever the button is
pressed, the pin is activated.
To create this second circuit, connect the yellow wire from GPIO pin number 13 to a new row on the breadboard, as
pictured:

Then add a button with one leg connected to the same row as the yellow wire, and another leg leading to some new row
on the breadboard.
34

Finally, connect a black wire to the same ground pin that was used for the first circuit, and the other end of this black
wire to the opposite side of the button that the yellow wire has been connected to.

We will now run the previously saved code, buttonresponse.py, and view the results in the terminal.

35

As it may be seen, the word off will keep repeating once every two tenths of a second, until the button is pressed and
held, at which point the word on will start repeating every two tenths of a second. Additionally, when the terminal is
reading off, the LED is off, but when the terminal is reading on, the LED is blinking on every tenth of a second.

36

Twython
What we have done so far could also be done on a much simpler device, such as an Arduino. What we must now learn, is
to integrate something more complex, such as Twitter. So, in this section, we will make an LED blink every time the
hashtag #pi is tweeted. This code is modified from Raspberry Pi Twitter Monitor, an article on Sparkfun, (Hymel).
To do this we must first install Twython, a bit of software that may be used with Python to incorporate Twitter into the
Raspberry Pi. To do this, first run the following commands, in this order.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install twython
After these files are installed, we will use the same electric circuit designed in buttonresponse.py to monitor Twitter.
We will then make a new file named twitter.py with the following contents:
import time
import RPi.GPIO as GPIO
from twython import TwythonStreamer
# Search terms
TERMS = '#pi'
# GPIO pin number of LED
LED = 6
# Twitter application authentication
APP_KEY = 'APPKEY'
APP_SECRET = 'APPSECRET'
OAUTH_TOKEN = 'TOKEN'
OAUTH_TOKEN_SECRET = 'TOKENSECRET'
# Setup callbacks from Twython Streamer
class BlinkyStreamer(TwythonStreamer):
def on_success(self, data):
if 'text' in data:
GPIO.output(LED, GPIO.HIGH)
time.sleep(0.1)
GPIO.output(LED, GPIO.LOW)
# Setup GPIO as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, GPIO.LOW)
# Create streamer
try:
stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(track=TERMS)
except KeyboardInterrupt:
GPIO.cleanup()
Note: You will need to replace APPKEY, APPSECRET, TOKEN, and TOKENSECRET from above with your own codes
provided by Twitter.

37

Appendices
Glossary:
Arduino An open source electronics prototyping platform. Basically, a small microcontroller, or computer, that
controls various electronic components that are plugged into it.
Ethernet cable A cable that allows devices to connect to the internet.
HDMI cable A cable that allows the Raspberry Pi to send video to a screen.
LED Light Emitting Diode. Essentially a light bulb.
Linux An operating system, such as Microsofts Windows or Apples OS X. Essentially, a package of software that
controls the hardware of a computer.
MicroSD card - A device that stores information. Not to be confused with the microUSB cable.
MicroUSB cable A cable that is used to power the Raspberry Pi. Not to be confused with the microSD card.
PuTTY A program that allows a computer to use SSH to communicate with another computer.
Python A computer programming language, essentially sets of instructions to be sent to a machine.
Raspberry Pi A small, single board computer that is approximately the size of an Altoids tin. It has an array of pins to
allow integration with other electronic components. The reason for the Raspberry Pis popularity is its low, 35 dollar
price, and the ability to get support within the community.
SSH An internet protocol that allows for communication with another computer over the internet. It requires PuTTY to
be installed on another computer.
USB keyboard/mouse dongle A wireless transmitter that allows one to type on the keyboard for the Raspberry Pi.
USB Wi-Fi dongle A wireless transmitter that allows devices to connect to the internet.

Software Sources:
NOOBS, the operating system files - https://www.raspberrypi.org/downloads/noobs/
PuTTY, the SSH program - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

38

(4 Band Resistor Color Code Calculator)

(Raspberry Pi 2 Model B GPIO 40 Pin Block Pinout)


39

Works Cited
4 Band Resistor Color Code Calculator. (n.d.). Retrieved November 30, 2015, from
http://www.digikey.com/en/resources/conversion-calculators/conversion-calculator-resistor-color-code4-band
Hymel, S. (n.d.). Raspberry Pi Twitter Monitor. Retrieved November 30, 2015, from
https://learn.sparkfun.com/tutorials/raspberry-pi-twitter-monitor
Raspberry Pi 2 Model B GPIO 40 Pin Block Pinout. (2015, January 28). Retrieved November 30, 2015, from
http://www.element14.com/community/docs/DOC-73950/l/raspberry-pi-2-model-b-gpio-40-pin-blockpinout
What is a Raspberry Pi? (n.d.). Retrieved December 3, 2015, from https://www.raspberrypi.org/help/what-is-araspberry-pi/
Resources for the Reader
Kuphaldt, T. (n.d.). Lessons in Electric Circuits. Retrieved September 26, 2015, from
http://www.allaboutcircuits.com/textbook/
This page advises readers on electronic circuitry. As such, it will be needed to give beginners a start on
creating basic circuits that send signals, receive signals, and power various components. This knowledge
is necessary to connect the digital environment of the Raspberry Pi to the physical world.
McGrath, R. (n.d.). Twython - Twython 3.3.0 documentation. Retrieved September 26, 2015, from
https://twython.readthedocs.org/en/latest/
These documents, created by the author of the software, advise users on usage of Twython. Twython is
essentially a program that transmits data from Twitter, the social media website, to Python, the
programming language. With these documents, readers are able to learn how to integrate Twitter with
their projects.
Python 3.5.0 documentation. (2015, September 25). Retrieved September 26, 2015, from
https://docs.python.org/3/
This website presents all the official documentation for Python, a programming language most
accessible to beginners. It is necessary to include this information as Python is required to perform a
myriad of actions with the Raspberry Pi, including carrying out calculations that dictate what is to be
done with the information sent to it. Beginners will need this information to begin generating their own
code to control their own projects.
Raspberry Pi Documentation. (n.d.). Retrieved September 26, 2015, from
https://www.raspberrypi.org/documentation/
This article presents all the official documentation for use of the Raspberry Pi. It covers nearly all
aspects of the Raspberry Pi, but is particularly effective in communicating how to "setup" the operating
system. It also presents the technical specifications of the hardware. This information is mandatory for
any beginner seeking to start learning with the Raspberry Pi.
Shotts, W. (n.d.). Now what? Retrieved September 26, 2015, from http://linuxcommand.org/index.php
Linux is the most common type of operating system for the Raspberry Pi and, as such, it is necessary to
present information on how to operate it. This website contains instructions on how to use the Linux
command line, and control the Raspberry Pi.

40

You might also like