3 Hours Crash Course
Raspberry Pi
by Cytron Technologies Sdn Bhd
[Link]
TRAINING OUTLINE
CONTENT:
● Introduction to Raspberry Pi
● Getting Started with Raspberry Pi Zero
○ Installing Raspbian OS
● Raspberry Pi Zero SSH Remote using USB OTG
○ PuTTy
○ Remote Desktop Connection
● Getting Familiar with Command Line
● Getting Started with Python Programming
● Hands-on Projects With Raspberry Pi Zero
○ LED Blinking
○ Push Button and LED
○ Auto run program
[Link]
3 Hours Crash Course
Raspberry Pi Zero
INTRODUCTION TO
RASPBERRY PI
[Link]
INTRODUCTION TO RASPBERRY PI
What is Raspberry Pi?
● A series of credit card–sized single-board computers developed in
England, United Kingdom by the Raspberry Pi Foundation.
● Intent to promote the teaching of basic computer science in schools and
developing countries.
● The Foundation provides Debian and Arch Linux ARM distributions for
download, and promotes Python as the main programming language.
● The system on a chip (SoC) used in the 1st generation Raspberry Pi is
somewhat equivalent to the chip used in older smartphones (such as
iPhone, 3G, 3GS).
● As of 29 Feb 2016, more 8 million Raspberry Pis have been sold including
three million units of Raspberry Pi 2.
[Link]
INTRODUCTION TO RASPBERRY PI
What can you do with Raspberry Pi?
● A general purpose computer.
● Media center.
● Learn to program.
● Learn electronics.
● Take photos!
● Robotics.
● Network storage.
● Retro games console.
● Weather station.
● etc...
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi vs Arduino: What is the difference between the two?
● An Arduino is a microcontroller motherboard. A microcontroller is a simple
computer that can run one program at a time, over and over again. It is
very easy to use.
● A Raspberry Pi is a general-purpose computer, usually with a Linux
operating system, and the ability to run multiple programs. It is more
complicated to use than an Arduino.
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi vs Arduino: What would I use each for?
● Arduino is best used for simple repetitive tasks: opening and closing a
garage door, reading the outside temperature and reporting it to Twitter,
driving a simple robot.
● Raspberry Pi is best used when you need a full-fledged computer: driving
a more complicated robot, performing multiple tasks, doing intense
calculations.
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi vs Arduino: A simple rule of thumb to decide?
● Think about what you want your project to do. If you can describe it with
less than two ‘and’s, get an Arduino. If you need more than two ‘and’s, get
a Raspberry Pi.
● “I want to monitor my plants and have them Tweet me when they need
water.” That can best be done by an Arduino.
● “I want to monitor my plants and have them Tweet me when they need
water and check the National Weather Service and, if the forecast is for
fair weather, turn on the irrigation system and if the forecast is for rain, do
nothing.” That would best be handled by a Raspberry Pi.
[Link]
INTRODUCTION TO RASPBERRY PI
Lists of Raspberry Pi boards:
● Raspberry Pi 1 Model A (February 2012).
● Raspberry Pi 1 Model B (April 2012).
● Raspberry Pi Compute Module (April 2014)
● Raspberry Pi 1 Model B+ (July 2014)
● Raspberry Pi 1 Model A+ (November 2014)
● Raspberry Pi 2 Model B (February 2015).
● Raspberry Pi Zero (November 2015).
● Raspberry Pi 3 Model B (29 February 2016)
● Raspberry Pi Zero W (28 February 2017)
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi 1 Model A:
● February 2012
● US$ 25
● SoC Broadcom BCM2835
● 700 MHz single-core
● SDRAM 256 MB
● USB 2.0 x1
● HDMI
● SD / MMC / SDIO card slot
● 300 mA (1.5 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi 1 Model B:
● April 2012
● US$ 35
● SoC Broadcom BCM2835
● 700 MHz single-core
● SDRAM 512 MB
● USB 2.0 x2
● HDMI
● SD / MMC / SDIO card slot
● 10/100 Mbit/s Ethernet
● 700 mA (3.5 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi Compute Module:
● April 2014
● US$ 30
● SoC Broadcom BCM2835
● 700 MHz single-core
● SDRAM 512 MB
● USB 2.0 x4
● HDMI
● 4 GB eMMC flash memory chip
● 200 mA (1.0 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi 1 Model B+:
● July 2014
● US$ 25
● SoC Broadcom BCM2835
● 700 MHz single-core
● SDRAM 512 MB
● USB 2.0 x4
● HDMI
● MicroSD card slot
● 10/100 Mbit/s Ethernet
● 600 mA (3.0 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi 1 Model A+:
● November 2014
● US$ 20
● SoC Broadcom BCM2835
● 700 MHz single-core
● SDRAM 256 MB
● USB 2.0 x1
● HDMI
● MicroSDHC card slot
● 200 mA (1.0 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi 2 Model B:
● February 2015
● US$ 35
● SoC Broadcom BCM2836
● 900 MHz quad-core
● SDRAM 1 GB
● USB 2.0 x4
● HDMI
● MicroSDHC card slot
● 10/100 Mbit/s Ethernet
● 800 mA (4.0 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi Zero:
● November 2015
● US$ 5
● SoC Broadcom BCM2835
● 1 GHz single-core
● SDRAM 512 MB
● USB OTG x1
● Mini HDMI
● MicroSDHC card slot
● ~160 mA (0.8 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi 3 Model B:
● 29 February 2016
● US$ 35
● SoC Broadcom BCM2837
● 1.2 GHz 64-bit quad-core
● SDRAM 1 GB
● USB 2.0 x4
● HDMI
● MicroSDHC card slot
● 10/100 Mbit/s Ethernet
● WiFi and Bluetooth 4.1
● ~1000 mA (5 W)
● 5V via micro USB
[Link]
INTRODUCTION TO RASPBERRY PI
Raspberry Pi Zero W:
● 28 February 2015
● US$ 10
● SoC Broadcom BCM2835
● 1 GHz single-core
● SDRAM 512 MB
● USB OTG x1
● Mini HDMI
● MicroSDHC card slot
● WiFi and Bluetooth 4.1
● ~160 mA (0.8 W)
● 5V via micro USB
[Link]
3 Hours Crash Course
Raspberry Pi Zero
GETTING STARTED WITH
RASPBERRY PI ZERO
[Link]
GETTING STARTED WITH RASPBERRY PI ZERO
Raspberry Pi Zero Starter Kit:
● Raspberry Pi Zero.
● Acrylic Case for Rpi Zero.
● 8GB microSD card with SD card
adapter.
● 5V 2.5A USB Adapter.
● Raspberry Pi Wire Kit:
○ HDMI mini to standard HDMI
adapter/converter
○ USB OTG cable (USB MicroB
to USB Type A receptor)
○ 2x20 Header pin (For GPIO)
[Link]
GETTING STARTED WITH RASPBERRY PI ZERO
Hardware required for this course:
1. Raspberry Pi Zero with header
pins.
2. 4 GB SD card.
3. SD card adapter
4. Micro USB cable.
5. Small breadboard.
6. Red LED.
7. Push button.
8. Resistor.
9. Male to female jumpers.
[Link]
Installing Raspbian OS
1. Download Raspbian OS from Raspberry Pi official download page – link.
For this course, we are using custom Raspbian Jessie Lite with Desktop,
Note: Before download, please make sure you have a strong and fast internet
connection.
[Link]
Installing Raspbian OS
2. Once download is finished, extract the zip file to get the image file.
[Link]
Installing Raspbian OS
3. Insert the SD card into your SD card reader. You can use the SD card slot if
you have one, or an SD adapter in a USB port. Note the drive letter
assigned to the SD card. You can see the drive letter in the left hand
column of Windows Explorer, for example D:
[Link]
Installing Raspbian OS
4. It is recommended to format the SD card using SDFormatter. You can
download it at [Link]. (a) Open SDFormatter, make sure your SD card
Drive is correct! Then click Format.
[Link]
Installing Raspbian OS
4. (b) Click OK.
[Link]
Installing Raspbian OS
4. (c) Click OK.
[Link]
Installing Raspbian OS
4. (d) SD card formatting is in progress.
[Link]
Installing Raspbian OS
4. (e) SD card formatting done!.
[Link]
Installing Raspbian OS
5. Download the Win32DiskImager utility from the Sourceforge Project page
as an installer file, and run it to install the software.
[Link]
Installing Raspbian OS
6. Run the Win32DiskImager utility from your desktop or menu.
[Link]
Installing Raspbian OS
6. Click on the folder icon and select the image file you extracted earlier.
[Link]
Installing Raspbian OS
7. In the device box, select the drive letter of the SD card. Be careful to
select the correct drive: if you choose the wrong drive you could destroy
the data on your computer’s hard disk! If you are using an SD card slot in
your computer, and can’t see the drive in the Win32DiskImager window,
try using an external SD adapter.
[Link]
Installing Raspbian OS
8. (a) Click ‘Write’ and followed by ‘Yes’ to confirm overwrite.
[Link]
Installing Raspbian OS
8. (b) Write image is in progress.
[Link]
Installing Raspbian OS
8. (c) Write image is complete!
[Link]
3 Hours Crash Course
Raspberry Pi Zero
SSH REMOTE USING
USB OTG PORT
[Link]
SSH REMOTE USING USB OTG PORT
1. Once Raspbian is flashed, open up the boot partition (in Windows Explorer,
Finder etc) and add to the bottom of the [Link] file dtoverlay=dwc2
on a new line, then save the file.
[Link]
SSH REMOTE USING USB OTG PORT
2. If using a recent release of Jessie (Dec 2016 onwards), then create a new
file simply called ssh in the SD card as well. By default SSH is now
disabled so this is required to enable it. Remember – Make sure your file
doesn’t have an extension (like .txt etc)!
[Link]
SSH REMOTE USING USB OTG PORT
3. Finally, open up the [Link]. Be careful with this file, it is very picky
with its formatting! Each parameter is seperated by a single space (it does
not use newlines). Insert modules-load=dwc2,g_ether after rootwait.
[Link]
SSH REMOTE USING USB OTG PORT
4. That’s it, eject the SD card from your computer. Put it in your Raspberry Pi
Zero (or W), make sure you have installed Bonjour, iTunes or Quicktime)
and connect it via USB OTG to your computer. It will take up to 90s to boot
up (shorter on subsequent boots). It should then appear as a USB Ethernet
device.
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
5. You can using PuTTy software
and SSH with
[Link] as the
address. You can download the
software here – [Link].
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
6. If you receive this popup, click
Yes.
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (a) Now, you can login with pi
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (b) ...and password raspberry.
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (c) Write command sudo raspi-config and following by enter
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (d) Select Hostname.
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (e) Proceed with Ok.
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (f) Write your pi name, then hit Ok..
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (g) Go to finish and press enter.
[Link]
SSH REMOTE USING USB OTG PORT (PuTTy)
7. (h) Select Yes and reboot your pi.
[Link]
SSH REMOTE USING USB OTG PORT (Remote Desktop)
8. Besides using PuTTy, we can use Remote Desktop Connection to view
full desktop UI. Open Remote Desktop Connection, type
<yourhostname>.local on Computer box and click Connect. Warning
window will popup, click Yes to continue.
[Link]
SSH REMOTE USING USB OTG PORT (Remote Desktop)
9. To login, insert pi as username and
raspberry as password. Click Ok.
Connection Log will display the
connection status, if succeed, it will
display connection complete,
connected ok. Click Ok.
[Link]
SSH REMOTE USING USB OTG PORT (Remote Desktop)
10. Raspbian desktop.
[Link]
3 Hours Crash Course
Raspberry Pi Zero
GETTING FAMILIAR
WITH COMMAND LINE
[Link]
GETTING FAMILIAR WITH COMMAND LINE
The terminal on a computer allows user to control over their system.
[Link]
GETTING FAMILIAR WITH COMMAND LINE
Fundamental and Common Linux Commands:
● LS - Lists the content of the current directory
● CD - Changes the current directory to the one specified
● PWD - Displays the name of the current working directory
● MKDIR - Makes a new directory
● RMDIR - Remove empty directories
● RM - Removes the specified file
● CP - Makes a copy of a file and places it at the specified location
● MV - Moves a file and places it at the specified location
● CHMOD - Normally used to change the permissions for a file
● SUDO - Run a command as a superuser
● IFCONFIG - Displays the network configuration
● For more detail please refer to Linux commands
[Link]
GETTING FAMILIAR WITH COMMAND LINE
Linux Commands Example:
Note: Please write a command in lowercase only:
● LS -A become ls -a
● CD Documents become cd Documents
● PWD become pwd
● CD become cd
● MKDIR NewFolder become mkdir NewFolder
● ls -a
● RMDIR NewFolder become rmdir NewFolder
● ls -a
[Link]
GETTING FAMILIAR WITH COMMAND LINE
Linux Commands Example:
[Link]
GETTING FAMILIAR WITH COMMAND LINE
Expand Filesystem:
● Ensures that all of the SD card storage is available to the OS.
● Write sudo raspi-config
● Choose Advanced Options - Expand Filesystem and press enter.
● After root partition have been resized, press another enter to ok.
● Press escape to exit Raspberry Pi configuration.
● Restart Raspberry Pi sudo reboot
[Link]
GETTING FAMILIAR WITH COMMAND LINE
Introduction:
● Python is one of the famous programming language.
● Python supports multiple programming paradigms, including
object-oriented, imperative and functional programming or procedural
styles.
● It features a dynamic type system and automatic memory management
and has a large and comprehensive standard library.
● Cross platform operating system.
● Under Python Software Foundation License (PSFL) and it is free.
● Principal author by Guido Van Rossum.
[Link]
3 Hours Crash Course
Raspberry Pi Zero
GETTING STARTED
WITH PYTHON
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
Syntax Comparison between Python and C++ (Partial Listing):
Syntax Description Python C++
Including a module/library from math import * #include <math>
Assignment operator =, +=, -=, *=, /=, %= same
Type integer value int, long short, int, long
float, double, long
Type decimal value float
double
bool: True/False or bool: true/false or
Type boolean
(not 0)/0 (!0)/0
Type charachter none char
char mystring[50] or
Type string str
string
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
Syntax Comparison between Python and C++ (Partial Listing):
Syntax Description Python C++
for statement for i in range(10): for(i = 0; i < 10; i++)
if statement if x != 3: if (x != 3)
while statement while x != 3: while (x != 3)
break out of a loop break same
function definition def myfunction(): int myfunction()
function call myfunction() same
and operator and &&
or operator or ||
not operator not !
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
Syntax Comparison between Python and C++ (Partial Listing):
Syntax Description Python C++
comparison operators ==, !=, <, <=, >, >= same
arithmetic operators +, -, *, /, % same
comments - single line # //
comments - multiple lines none /* */
pre and post inc/dec operators none ++x, x++, --x, x--
code blocks indentation, ; { }
statement separator end of line ;
constants none const int i = .018
Input/Output raw_input, input, print cin, cout
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
1. Open Python 2 (IDLE)
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
2. Create new file
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
3. New blank window appear
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
4. Save your new file as...
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
5. Give your file name - Lesson1
[Link]
GETTING STARTED WITH PYTHON PROGRAMMING
6. You are ready to write a Python code
[Link]
3 Hours Crash Course
Raspberry Pi Zero
HANDS-ON PROJECTS
WITH RPI ZERO
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Raspberry Pi Layout:
● 5V MicroUSB Power
● HDMI Out Port
● CSI Camera
● 3.5 Audio
● Ethernet Out Port
● 2x2 USB-A Ports
● 40 GPIO Headers
● MicroSD Card Slot.
● 4 Mounting Hole (2.5
mm diameter)
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Raspberry Pi GPIO Pinout:
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Python Lesson 1 - LED Blinking:
● Need an LED and 330 resistor. Connect to GPIO-23.
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Python Lesson 1 - LED Blinking:
import [Link] as GPIO
import time
[Link](False)
[Link]([Link])
[Link](23, [Link])
try:
while True:
[Link](23, [Link])
[Link](1)
[Link](23, [Link])
[Link](1)
except KeyboardInterrupt:
[Link]()
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Run Lesson 1 - LED Blinking:
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Run Lesson 1 - LED Blinking:
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Result of Lesson 1 - LED Blinking:
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Python Lesson 2 - Push Button and LED:
● Need an LED, 330 resistor and push button. Connect to GPIO-23 and 24
respectively.
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Python Lesson 2 - Push Button and LED:
Create a new file and save as [Link].
import [Link] as GPIO
import time
[Link](False)
[Link]([Link])
[Link](23, [Link])
[Link](24, [Link], GPIO.PUD_UP)
try:
while True:
if [Link](24) == 0:
[Link](23, [Link])
continue next slide...
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Python Lesson 2 - Push Button and LED:
else:
[Link](23, [Link])
except KeyboardInterrupt:
[Link]()
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Run Lesson 2 - Push Button and LED:
[Link]
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
Result of Lesson 2 - Push Button and LED:
[Link]
Auto Run Program
In order to have a command or program run when the Pi boots, you can add
commands to the [Link] file. This is especially useful if you want to be able
to plug your Pi in to power headless, and have it run a program without
configuration or a manual start.
EDITING [Link]
On your Pi, edit the file /etc/[Link] using the LXTerminal. You must edit
with root, for example:
sudo nano /etc/[Link]
Add commands below the comment, BUT leave the line exit 0 at the end,
then save the file and exit.
[Link]
Auto Run Program
WARNING
If your command runs continuously (perhaps runs an infinite loop) or is likely
not to exit, you must be sure to fork the process by adding an ampersand to
the end of the command, like so:
sudo python /home/pi/[Link] &
Otherwise, the script will not end and the Pi will not boot. The ampersand
allows the command to run in a separate process and continue booting with
the process running.
Also, be sure to reference absolute filenames rather than relative to your home
folder; for example, /home/pi/[Link] rather than [Link].
[Link]
Auto Run Program
After editing, press CTRL+X, then press Y followed by Enter to overwrite.
[Link]
Auto Run Program
Reboot your Pi Zero, write sudo reboot followed by Enter.
[Link]
3 Hours Crash Course
Raspberry Pi Zero
Q&A
Thank You
[Link]