100% found this document useful (1 vote)
206 views

Raspberry Pi: Step by Step Guide

This document provides an overview of the Raspberry Pi, including: - What is a Raspberry Pi and its key components like the board, operating system SD card, power supply, and display connection options. - The essential and recommended extra kit components needed to set up and run a Raspberry Pi. - Popular programming languages that are installed by default on the Raspberry Pi like Python, C/C++, Java, and Scratch. - Examples of how Raspberry Pis are used like for education projects, office tasks, playing videos, and electronic projects. - The steps to set up a Raspberry Pi for the first time including downloading an operating system, installing it on

Uploaded by

Qumail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
206 views

Raspberry Pi: Step by Step Guide

This document provides an overview of the Raspberry Pi, including: - What is a Raspberry Pi and its key components like the board, operating system SD card, power supply, and display connection options. - The essential and recommended extra kit components needed to set up and run a Raspberry Pi. - Popular programming languages that are installed by default on the Raspberry Pi like Python, C/C++, Java, and Scratch. - Examples of how Raspberry Pis are used like for education projects, office tasks, playing videos, and electronic projects. - The steps to set up a Raspberry Pi for the first time including downloading an operating system, installing it on

Uploaded by

Qumail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 149

Raspberry Pi

Step By Step Guide

By Ashraf AlMadhoun
Mechatronics Engineer
What is a Raspberry Pi?
• University of Cambridge’s Computer Laboratory
– Decline in skill level
– Designed for education
• A credit card sized PC
• Plugs into a TV or monitor
• Inexpensive(ish) ~$35 each
• Capability:
– Programming
– Electronic Projects
– Office
– Play HD Videos
Kit Components
• Essential:
– Raspberry Pi board
– Prepared Operating System SD Card
– USB keyboard
– Display (with HDMI, DVI, or Composite input)
– Power Supply
• Highly suggested extras include:
– USB mouse
– Internet connectivity - LAN cable
– Powered USB Hub
– Case
Programming Languages
• The Raspberry Pi Foundation recommends Python
• Any language which will compile for ARMv6 can be
used
• Installed by default on the Raspberry Pi:
– C
– C++
– Java
– Scratch
– Ruby
Raspberry Pis in Primary Ed.

http://www.youtube.com/watch?v=KdTwQXre1DU
SETUP
Power
5v micro
USB
connector

(Similar to the one on a lot of mobile


phones!)
3.5mm Audio
Standard
A/V (Audio/Video) headphone
socket
RCA Video
(works with most
older TVs)

HDMI Audio & Video


(works with modern TVs and DVI monitors)
Connectivity
2 x USB 2.0
ports
GPIO
(General
Purpose
Input &
Output)

10/100Mb
Ethernet
Internals LAN Controller

DSI
(display
interface) CSI
(camera
interface)
SOC (System On a Chip)
Broadcom BCM2835 700Mhz
Storage

SD Card Slot
(supports SD cards up to 32GB)
10 USES FOR
A RASPBERRY PI
10 Office

9 8 7 6 5 4 3 2 1
Office

10 9 8 7 6 5 4 3 2 1
9 Programming

10 8 7 6 5 4 3 2 1
Programming

10 9 8 7 6 5 4 3 2 1
Game
8
Console

10 9 7 6 5 4 3 2 1
Game
Console

10 9 8 7 6 5 4 3 2 1
7 Web Server

10 9 8 6 5 4 3 2 1
Web Server

10 9 8 7 6 5 4 3 2 1
6 Tor Router

10 9 8 7 5 4 3 2 1
Tor Router

10 9 8 7 6 5 4 3 2 1
5 HTPC

10 9 8 7 6 4 3 2 1
HTPC

10 9 8 7 6 5 4 3 2 1
4 Bird House

10 9 8 7 6 5 3 2 1
Bird House

10 9 8 7 6 5 4 3 2 1
Super
3
Computer

10 9 8 7 6 5 4 2 1
Supercomputer

10 9 8 7 6 5 4 3 2 1
2 Clock

10 9 8 7 6 5 4 3 1
Clock

10 9 8 7 6 5 4 3 2 1
1 PiBot!

10 9 8 7 6 5 4 3 2
PiBot!

10 9 8 7 6 5 4 3 2 1
Let’s Begin the Raspberry Pi Journey
Different versions of Raspberry Pi
• First Version
- It came with a very small and cheap size, but it came too small
that it’s really hard to use, it has the size of two coins with only
one USB port and one HDMI port to connect it to high screens.
Different versions of Raspberry Pi
• Second Version
- It came with a larger size than the previous one with an additional
GPIO port which allows connecting electronics components such as
switches and Leds.
Different versions of Raspberry Pi
• More advance Versions
- It came with more improvements, smaller size and a very low
cost, at only 25$.
- Image below shows the three versions of the Pi in the hand of
their manufacturers
Different versions of Raspberry Pi
• Model A and Model B
Different versions of Raspberry Pi
• Model A and Model B
Raspberry Pi Components
Raspberry Pi Components

Broadcom BCM2835

CPU core is an ARM11


GPU

CPU

RAM
Raspberry Pi Components
Raspberry Pi Components
OS Version Available for Raspberry Pi
Main OS Version for Raspberry Pi
• Raspbian:
• It is the Foundation’s official supported
operating system. You can install it with
NOOBS or download the image below
and follow our installation guide.

• Raspbian comes pre-installed with


plenty of software for education,
programming and general use. It has
Python, Scratch, Sonic Pi, Java,
Mathematica and more.
OS Version Available for Raspberry Pi
• Raspbian is what is known as the “Operating System” (OS)
– Similar to windows running on your home PC, the raspberry pi
requires an operating system to work
– Raspbian is a special-purpose distribution based on Debian (a variant
of linux)
• The OS is what lets the raspberry pi not only run programs,
but run multiple programs concurrently
• It accomplishes this with a “scheduler” in the OS
– Simply put, this makes programs “take turns”
– Only one program is actually executing at any one time
OS Versions for Raspberry Pi
• It is an operating system for media and
home theater entertainment use, it can
turn and old TV into a Media Center to
display HD Movies and watch Youtube,
it’s based on XBMC famous media
software.

• A distribution based on Raspbian,


edited by famous electronics company
Adafruit which develop the system to
control and electronic application which
make it easy to use different control
protocol
OS Versions for Raspberry Pi
• Kali Linux is a Linux distribution based
on BackTrack which is one of the best
OS for hackers and security experts
around the word, offering a Varity of
hacking tools to wired and wireless
networks.

• It stands for Robotics Operating System,


a specialized operating system for
robotics, and a system that is used in
robots project all around the word,
offering a great tool to make controlling
a robot an easy job.
OS Versions for Raspberry Pi
• Developers where able to modify a
version of Android to work properly
with Raspberry Pi, it’s still in the beta
stage.

• A professional version of Linux for


experts and anyone who wants a
version of Linux small enough to fit in
Raspberry Pi and fast enough to do all
the tasks without slowing the system
performance.
OS Versions for Raspberry Pi
• It’s a collection of four different
operating system: Raspbian, Pidora,
RaspBMC, OpenELEC, which allows a
beginner to choose and run without any
complications.

• RISC OS was developed in the early 90’s


in the UK to help computer and
engineering students learn more about
computer ARM based architecture.
Arduino vs Raspberry Pi vs BeagleBone
Arduino vs Raspberry Pi vs BeagleBone
Why Raspberry Pi is the BEST?

Not the Fastest BUT the cheapest!

Support and Documentation


Course Material Works with Any high
tech Board not Just Raspberry Pi
- There is a common thing about all the board
that works with ARM based CPU, which is the
fact that most if not all of these boards support
Linux specially Debian or Ubuntu Which makes
the content of this course usable with more of
the ARM based boards in the World.
- Knowledge that you get in this course won’t be
exclusive to Raspberry Pi, since almost 70% of
the course will depend on using Linux and it’s
applications, and that allows you to use the
same methods, codes and connection algorithms
with almost any available board such as:
BegalBoard, UDOO, pCduino, Parallela.
Section II: Running the Raspberry Pi
What do you need to Run Raspberry Pi
SD Card 4GB to 32GB

USB Charger: at least 1 Ampere to run the board


and any connected USB device properly
What do you need to Run Raspberry Pi
Keyboard & Mouse

TV Screen
What do you need to Run Raspberry Pi
HDMI Cable

RCA Video Cable


What do you need to Run Raspberry Pi
Memory Card Reader

RCA Video Cable


What do you need to Run Raspberry Pi
Raspberry Pi Protection Cover

You can make your own


Components needed for Electronic
Experiments
BreadBoard

Female-to-male wires
Components needed for Electronic
Experiments
Raspberry Pi Breakout Cable Optional
Components needed for Electronic
Experiments
You can get Adafruit board which
You can mount it above the Raspberry Pi Board to
easy access all ports
Other Components
Getting OS version on Raspberry Pi
Download Raspbian OS from the website below
http://www.raspberrypi.org/downloads
After downloading Unzip the file using WinRAR or 7zip

After downloading Unzip the file using WinRAR or 7zip


Getting OS on Raspberry Pi Using
Windows Device
Attach the card to the card reader, then plug the USB
card reader to your PC, you will see a drive like in the
image below

After this right click on


the drive and format it
using FAT32 File system
Getting OS on Raspberry Pi Using
Windows Device
Download W32 Disk Image Writer from the link
below which we will use to move the OS to the
memory card attached to our PC.
http://sourceforge.net/projects/win32diskimager/files/latest/d
ownload
Running Raspberry Pi
- Plug in the USB charger to the board
- Plug in the SD Card to the SD Card socket in the board
Running Raspberry Pi
- Plug in the USB Keyboard, Mouse, Ethernet cable
and HDMI Cable
Running Raspberry Pi
- Now Just plug in the Power Adapter and you are
good to go.
Setting up Raspberry Pi for the First time
Setting up Raspberry Pi for the First time
- Configure the Pi to take the whole space available in the SD
Card.
Setting up Raspberry Pi for the First time
- Configure the board to boot straight to the desktop.
Simulating Raspberry Pi
- Don’t have a Raspberry Pi ?!?! No Problem, you can learn it
anyway, by downloading and installing the simulation
environment.
- http://sourceforge.net/projects/rpiqemuwindows/
Simulating Raspberry Pi

- To exit simulation mode press Ctrl+Alt at anytime.


Simulating Raspberry Pi
Advantages:
1- Don’t need to buy a board
2- Easy to try Linux environment
3- Make Programming and Internet related experiments
4- Running more than one operating system at one time

Disadvantages:
1- Can’t simulate electronic control projects or GPIO projects
2- Can consume a bit of your CPU power and RAM.
Section III: A tour inside Raspberry Pi
Operating system
Section III: A tour inside Raspberry Pi
Operating system
Raspberry Pi Command Line
- Raspian has a program Called LXterminal which gives us
access to the system shell, we will call it command line
interface .
- You can run it from the desktop or from the LXDE menu
Raspberry Pi Command Line
- A list of most commonly used command line commands and
the use of each of them can be seen below.
Updating Software Packages
- A tool called apt-get is used to update all the software
packages within the system.

- You can install any software that you want using this too, by
simply writing install + program name.
Updating Software Packages

- If you added a –Y after or before the program name, the


setup will continue without asking for any confirmations

- To remove any app, replace install with remove


Updating Software Packages
- To update all the software packages and the operating system
at once, use the order upgrade, but don’t forget to make
execute update order before doing that.

- You can also get software packages from the Pi Store, which
is similar to ITunes and Google play store
Installing debian Software Packages
- Installing a .deb software package that you can get online
from any software developer website.

- More Sources:
• http://ss64.com/bash
• http://www.pixelbeat.org/cmdline.html
• http://linuxcommand.org/learning_the_shell.php
Section IV: Controlling Raspberry Pi From
another device
Control using SSH (Secure Shell)
- Control using SSH (Secure Shell):
- It mainly consist of a server and a client.
1- We will need to activate SSH Server in the Raspberry Pi side
Control using SSH (Secure Shell)
Control using SSH (Secure Shell)
2- Knowing the IP Address of the Raspberry Pi using the ifconfig
command.

2- Getting a client software in our windows machine, in our case


I will use PuTTY, which is free and powerful software the provide
SSH server client communication.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download
.html
Control using SSH (Secure Shell)
Control using SSH (Secure Shell)
3- After entering the Pi IP and port click on open, a window will
appear asking you to provide the username: pi and the
password: raspberry

4- Know you can do whatever you like to your board without


having to connect it to a screen.
Control using VNC Protocol
VNC Stands for Virtual Network Computing, it mainly allows
viewing the Raspberry Pi desktop on any other device with a
VNC Client/Viewer, regardless of the type of the operating
system.
Control using VNC Protocol
1- Start by installing the VNC server software in Raspberry Pi.

2- After the installation had finished, you need to run VNC


server by writing the following command:

You will be asked to enter a password to enter the device, which


is different from the Pi password.
Control using VNC Protocol

3- One final step remains, which is knowing the IP Address for


the Raspberry Pi Board using ifconfig command

4- Know that the Board is ready to be controlled by any other


device, you need to go to the link below and download your
operating system client.
http://www.realvnc.com/download/viewer/
Control using VNC Protocol
Control using VNC Protocol
Automatically Running VNC Server when powering on the
Raspberry Pi.

Now we will create a start up file called tightvnc using the


following command.

Enter this data inside the file, then Press Ctrl+x to save the file.
[Desktop Entry]
Type=Application
Name=TightVNC
Exec=vncserver :1
StartupNotify=false
Control using VNC Protocol
Assign a Fixed IP Address for Raspberry Pi
Board
- In both cases VNC and SSH, we get the IP using ifconfig command,
which means that we need to connect Raspberry Pi at least once
every time we want to remote control it, to know it’s IP.
- To solve this problem we are going to assign a Fixed IP Address to
our Raspberry Pi board by going to our Internet Router and look for
the Mac address of the Board and assign it to a fix IP address which
can’t be changed no matter what.
Steps:
1- Go to your main internet router page: usually written in the
back of the router and could be any of these:
192.168.1.1 – 192.168.0.1 – 192.168.254.0
2- The explanation will be on TP-Link Router but it’s the same
process for all
Assign a Fixed IP Address for Raspberry Pi
Board
- After entering the main router page you will be asked to
provide the username and password

- Head over to DHCP settings under network section


Fixed IP Address for Raspberry Pi Board
- Then go to DHCP client list which has a list of all connected
devices and their Mac addresses

- MAC Address B8-27-EB-48-48-D7 is for raspberry pi head to


Address Reservation and add the MAC Address you got.
Fixed IP Address for Raspberry Pi Board

- By doing this we assigned 192.168.1.10 as a fixed IP for our


Raspberry Pi, but know that this have to be done again if you
changed the network you are connected to.
Connecting Raspberry Pi to another
computer using Network Cable
Setting the Raspberry Pi
- Remove the Raspberry Pi from the electricity and connect the
SD Card to your computer, you will get the name boot.

- Enter the Boot folder and open the cmdline.txt which has the start
up settings for the Raspberry Pi, head to the end of the file and add
the network IP as follow.
- ip=192.168.1.10
- After finishing the editing, save the file and re-attach the SD
Card to the Raspberry Pi.
Setting the Computer
- We will give the computer an IP Address, to do this attach the
Raspberry Pi to the computer using the network cable, then
enter the network settings.
Setting the Computer

- The network settings must be as follows:


- IP Address: 192.168.1.5
- Subnet Mask: 255.255.255.0
- Default Gateway: 192.168.1.5
Connecting to the Raspberry Pi

- Now you can connect to the Board using PuTTY or VNC viewer, note that
you need to reset the network setting when you finish working with the
Board so that your computer can get an automatic IP address from the
internet provider.
Section V: Programming GPIO with Python
GPIO – General Purpose Input/Output
- Raspberry Pi Board has 28 connection point/Pin called GPIO, some of the is
used for electronic control Output, while others are used to sense signals
called Input providing Power and communication protocol.
GPIO – Power & Control Pins
- Pin 1,7: Provide 3.3 volt, 50 mA, incase you need more than
50 Ma, you need to use an external relay to control, or you
might damage the board.
- Pin 2,4: Provide 5 volt and is connected to Micro USB on the
board
- Pin 6,9,14,20,25: are for Ground.
- Pin (3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24,
26): for control operation as Input or Output, you can control
this using the written software.

- Note: Pin numbers is different than GPIO numbering, for


example Pin 3 is GPIO2, so you always need to return to the
image in the documentation for the right numbering.
GPIO – Communication Protocol,
Programming Languages
- Raspberry Pi supports 4 Communication protocols:
i2C, SPI, UART, 1Wire.

- These protocols work at the same pins, so you can


program pins to be input/output or communication
protocol.
Programming Languages
- Raspberry Pi supports almost all programming
languages including: C, C++, C# (Mono), Java,
Python, Perl, Ruby, Pascal ..etc

- The best language to be used it Python since it has


so many libraries, support and documentation as
well as examples.
- You can choose any language that you are good at
and program Raspberry Pi using it.
Python
- Basic operations:
- Let’s start by writing Hello World in the command Line

- Mathematical Calculations:
- In python you can do any mathematical operation easily, just
type the two numbers and the result will come:

- To define any variable just type the variable followed by


equal sign then the value.
Python
- Same thing when it comes to string variable

- You can also combine mathematical operation with


variables:

- To close the command line press Ctrl+D


Storing the code in a Script
- All of the previous examples we wrote code that will be gone
once the command line windows is closed, so to maintain the
code we need to save it in a file with .py extension.
- Consider the following code:

- You can write it by doing to Menu > Accessories > Leafpad and
write the code then click on File > Save and assign the name
sum.py store it inside the /home/pi folder
- To run the program write python sum.py in the command line
Installing the Control Library
- Before start using Python to control GPIO, We will install the
control library rpi.gpio which we can get by writing:
Nano: Code editor to Be Used
- Nano is one of the best text editor in Command Line
environment inside Linux systems.
- We will use it as our default coding program.
- It’s really simple to run it, just write nano Yourfilename and it
will open a new file with the name you assigned in the
previous command.
Nano: Code editor to Be Used
- To save the file click on Ctrl+X a message will appear, hit Y then
enter.
Example 1: Blinking Led
• Goal From Example:
- Running a Led and make it turn on
and off indefinitely.

• Required Components:
- Bread Board
- Raspberry Pi Board
- LED
- 300 Ohm Resistor
- Connection Wires
Example 1: Blinking Led
• Preparing Project Parts:
- Running a Led and make it turn on
and off indefinitely.
Example 1: Blinking Led
• Code:
Example 1: Blinking Led
• Applying the code and see the result:

To close the program click Ctrl + C


To run the code write
Notes on Example 1: Blinking Led
• If you tried to run it again using the same sentence you will get a warning
telling you that the output you are trying to use it already used.

• This message appear when running a software after another at the very
same port, you can ignore this message and if you would like to hide it use
this sentence GPIO.setwarnings(False)
Explaining the Code
• This is used to call libraries, this is always the
start of each program, calling time library for
time measurements and calling the GPIO
Library.

• Activation code: This is used to enable GPIO


ports so that it will be ready to send and
receive signals

• Setting the pin function as input or output


Explaining the Code
• While is used to repeat the commands
indefinitely, or for a defined number of times.

• Used to turn the output on or off depending on


the numbers inside the practices, first number is
the pin number while second is the state on or off.
• Note: You can use True or False instead of 0 and 1.

• To control the amount of time used for the


previous line to be executed or viewed by the
user.
• Means wait for 1 second
Developing Example 1 Code
• We will develop the code so that it will show a line after turning the Led
on or off.
Developing Example 1 Code
• The Result on Nano Editor screen
Example 2: Reading Input Values From
A Switch

• Goal From Example:


- Reading a Digital Input Values
using a switch and display
results on screen

• Required Components:
- Bread Board
- Raspberry Pi Board
- Switch
- 10k Ohm Resistor
- Connection Wires
Example 2: Reading Input Values From
A Switch
Example 2: Reading Input Values From
A Switch
• The result

• Explaining If statement
Example 2: Reading Input Values From
A Switch
• Explaining If statement
Example 3: Running the Led using LDR
• Goal From Example:
- Running a Led and make it turn on
and off using Light emitting diode.

• Required Components:
- Bread Board
- Raspberry Pi Board
- LED
- 10k Ohm Resistor
- 300 Ohm Resistor
- LDR Light emitting diode
- Connection Wires
Example 3: Running the Led using LDR
Example 3: Running the Led using LDR
Example 3: Running the Led using LDR
• Save the file and run the code

• Now close the light room or place your hand at the LDR and see what will
happen to the LED.
• Improvements to Example 3
1- You can change True to False and see the result.
2- You can add Print sentence when executing the two output commands
Example 4: PIR Motion Detector
• PIR is one of the most important sensors in practical life, used
in many projects such as protection and smart doors.
• You can see it mostly in Centers and Companies doors which
opens once you get close to it.
• These type of sensors can use different methods to detect:
Ultrasonic waves, infrared signal and many more.
• In this lesson we will use the IR based PIR Motion Detector.
Example 4: PIR Motion Detector
• This sensor can sense the presence of an object at a distance
of 7 to 10 Meter and an angle between 90 to 110 degree.
• This is enough for a small room.
Example 4: PIR Motion Detector
• This sensor has 3 connection points which are: volt in 3 to 5
volt red wire, digital out yellow wire, Ground black wire.
Example 4: PIR Motion Detector
• We will connect the red wire to the pin 1 in the Pi which is the
5 volt output.
• Connect the yellow wire to the 23 pin
• Connect the black wire to pin number 6 which is Ground.
Example 4: PIR Motion Detector
• Start the editor
Example 4: PIR Motion Detector
• Run the code and see the result.

• The detector give 3 volt output signal whenever a motion is


detected.
Example 4: PIR Motion Detector
• Improving the code:
• We will add a 300 Ohm resistor and a
LED and edit the code as follows:
BCM Numbering instead of Numbering
by Order
• There is two famous numbering system for port numbering:
1- Board Numbering
2- BCM Numbering
- Most people prefer to use BCM numbering instead of board
numbering because Adafruit Breakout cable just like the
image below.
- Note that the BCM Numbering is the one inside the boxes at
both sides, while the Board numbering is the one inside the
circles.
BCM Numbering instead of Numbering
by Order
BCM Numbering

Board
Numbering
Where is the difference?
• The only difference is in the calling method of the GPIO library
in Python, if we want to run the terminals in GPIO order we
will call the library using:

• If we want to run the ports using BCM numbering we must


call the library using this line.

• Note:
• This is important thing to do because you will find
lots of projects online use BCM numbering so you
need to take good care of this and connect all
components to pins the right way.
Adafruit Protection Box and
Connection Cable
• Adafruit is considered one of the biggest open source
electronics companies that have many product for Arduino,
Raspberry Pi and much more.

• This company provides protection box and cable that are


really necessary before start using the Raspberry Pi.

• Note:
• The cable uses BCM numbering, so be sure to import the BCM
library in Python.
Assembling the Protection Box
Assembling Adafruit GPIO breakout
cable
Questions?
Skype: EngASM89
Email: Eng.asm.89@gmail.com
Mobile: +972595399311

Ashraf Said AlMadhoun | Mechatronics


148
Engineer
Eng Ashraf Said AlMadhoun
Mechatronics Engineer
+972595399311
Eng.asm.89@gmail.com
Skype: EngASM89

Ashraf Said AlMadhoun | Mechatronics


149
Engineer

You might also like