Beruflich Dokumente
Kultur Dokumente
Raspberry Pi
by Cytron Technologies Sdn Bhd
www.cytron.com.my
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
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
INTRODUCTION TO
RASPBERRY PI
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
● 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.
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
● 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.
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
www.cytron.com.my
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
www.cytron.com.my
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
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
● 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
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
● 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
www.cytron.com.my
INTRODUCTION TO RASPBERRY PI
● 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
www.cytron.com.my
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
www.cytron.com.my
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
www.cytron.com.my
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
www.cytron.com.my
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
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
www.cytron.com.my
GETTING STARTED WITH RASPBERRY PI ZERO
● 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)
www.cytron.com.my
GETTING STARTED WITH RASPBERRY PI ZERO
www.cytron.com.my
Installing Raspbian OS
Note: Before download, please make sure you have a strong and fast internet
connection.
www.cytron.com.my
Installing Raspbian OS
2. Once download is finished, extract the zip file to get the image file.
www.cytron.com.my
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:
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
6. Click on the folder icon and select the image file you extracted earlier.
www.cytron.com.my
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.
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
Installing Raspbian OS
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
www.cytron.com.my
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 config.txt file dtoverlay=dwc2
on a new line, then save the file.
www.cytron.com.my
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)!
www.cytron.com.my
SSH REMOTE USING USB OTG PORT
3. Finally, open up the cmdline.txt. 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.
www.cytron.com.my
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.
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (PuTTy)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (Remote Desktop)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (Remote Desktop)
www.cytron.com.my
SSH REMOTE USING USB OTG PORT (Remote Desktop)
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
GETTING FAMILIAR
WITH COMMAND LINE
www.cytron.com.my
GETTING FAMILIAR WITH COMMAND LINE
www.cytron.com.my
GETTING FAMILIAR WITH COMMAND LINE
www.cytron.com.my
GETTING FAMILIAR WITH COMMAND LINE
● 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
www.cytron.com.my
GETTING FAMILIAR WITH COMMAND LINE
www.cytron.com.my
GETTING FAMILIAR WITH COMMAND LINE
Expand Filesystem:
www.cytron.com.my
GETTING FAMILIAR WITH COMMAND LINE
Introduction:
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
GETTING STARTED
WITH PYTHON
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
char mystring[50] or
Type string str
string
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
if statement if x != 3: if (x != 3)
or operator or ||
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
pre and post inc/dec operators none ++x, x++, --x, x--
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
GETTING STARTED WITH PYTHON PROGRAMMING
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
HANDS-ON PROJECTS
WITH RPI ZERO
www.cytron.com.my
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)
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
try:
while True:
GPIO.output(23, GPIO.HIGH)
time.sleep(1)
GPIO.output(23, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
● Need an LED, 330 resistor and push button. Connect to GPIO-23 and 24
respectively.
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.IN, GPIO.PUD_UP)
try:
while True:
if GPIO.input(24) == 0:
GPIO.output(23, GPIO.HIGH)
continue next slide...
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
else:
GPIO.output(23, GPIO.LOW)
except KeyboardInterrupt:
GPIO.cleanup()
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
HANDS-ON PROJECTS WITH RASPBERRY PI ZERO
www.cytron.com.my
Auto Run Program
In order to have a command or program run when the Pi boots, you can add
commands to the rc.local 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 RC.LOCAL
On your Pi, edit the file /etc/rc.local using the LXTerminal. You must edit
with root, for example:
Add commands below the comment, BUT leave the line exit 0 at the end,
then save the file and exit.
www.cytron.com.my
Auto Run Program
WARNING
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/Lesson1.py rather than Lesson1.py.
www.cytron.com.my
Auto Run Program
www.cytron.com.my
Auto Run Program
www.cytron.com.my
3 Hours Crash Course
Raspberry Pi Zero
Q&A
Thank You
www.cytron.com.my