Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (1 vote)
99 views76 pages

Lecture 16 - Rpi-Final PDF

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 76

Raspberry Pi Training

Dr. Vinay Chamola, Assistant Professor, EEE Department, BITS-Pilani


Agenda
• Introduction
• Pin Diagram
• Setup
• SSH
• RealVNC
• Wireless remote access
• Running program on Pi
• LEDblink
• LEDPWM
What is Rpi
• The Raspberry Pi is a series of small single-board omputers developed
in the United Kingdom by the Raspberry Pi Foundation to promotethe
teaching of basic computer science in schools and in developing
countries.
• The original model became far more popular than anticipated,selling
outside its target market for uses such asrobotics.
• It does not include peripherals (such as keyboards, mice and cases).
However, some accessories have been included in several official and
unofficial bundles.
History
• In 2006, early concepts of the Raspberry Pi were basedon
the Atmel ATmega644 microcontroller. Its schematics and PCBlayout
are publicly available. Foundation trustee Eben Upton assembled a
group of teachers, academics and computer enthusiasts to devise a
computer to inspire children.
• The Model A, Model Band Model B+ names are references to the
original models of the British educational BBCMicro computer,
developed by Acorn Computers.
Rpi Boards
Rpi 3 model B Rpi 2 model B Rpi 1 model B+

Rpi Zero W Rpi Zero Rpi Industrial Compute module 3


Why RPi
• Very Low Cost
• Great tool for Learning Programming, Computers & Concepts of
Embedded Linux, etc
• Support for all Age Groups (School Children,College Undergraduates,
Professional Developers, Programmers)
• Supports & runs Free and Open Source LinuxOS
• Consumes less than 5W of Power
• Supports Full HD Video Output (1080p), Multiple USBPorts ,etc
• Fun to learn &explore. You are limited by your imagination
Power

5v micro
USBconnector

(Similar to the one on a lot ofmobile


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

HDMI Audio & Video


Connectivity
4 x USB2.0
ports
GPIO
(General
Purpose
Input &
Output)
Internals LANController

DSI
(display
interface) CSI
(camera
interface)
SOC(System On a Chip)
Broadcom BCM2835 700Mhz
EEE G627: Networked Embedded Applications (Dr. Vinay Chamola, BITS-Pilani)
Storage

SDCard Slot
(supports SDcards up to 32GB)
Rpi 3 Module B
Add-ons
Handle with care
• The Raspberry Pi was built to be used, but not abused.
Every P.C.B. should be handled with care.
• Handle the Pi only by the edges of the board itself. Avoid
touching or holding any of the components on the board.
• Rough Handling can cause solder points to fail and may result inshort
circuits, but be careful with the GPIO pins as well. Best practice: Use
the Rpi Case
• While connecting Hardware, double check the connections and then
power it up. Raspberry Pi GPIO’s are not 5V tolerant.
Ground
• The Ground pins on the Raspberry Pi are all electrically connected, so
it doesn't matter which one you use if you're wiring up a voltage
supply.
• Generally the one that's most convenient or closest to the rest of your
connections is tidier and easier, or alternatively the one closest to the
supply pin that you use.
WiringPi
• WiringPi is an attempt to bring Arduino-wiring-like simplicity tothe
Raspberry Pi.
• The goal is to have a single common platform and set of functions for
accessing the Raspberry Pi GPIO across multiple languages. WiringPi
is a Clibrary at heart, but it's available to both Ruby and Pythonusers
who can "gem install wiringpi" or "pip install wiringpi2" respectively.
• WiringPi uses its own pin numbering scheme.
Setting up Raspberry pi (NOOBssetup)
• How to get and installNOOBS?
• BUY PREINSTALLED SD CARD
1. SDcards with NOOBSpreinstalled are available from many distributors and independent
retailers, such asPimoroni, Adafruit and The Pi Hut. For older models of Raspberry Pi, you’ll
need a full-size SDcard; for the Pi Zero, A+, B+, Pi 2 and Pi 3 you’ll need a micro SDcard.
• DOWNLOAD
1. recommended to use an SDcard with a minimum capacity of 8GB.
2. Using a computer with an SDcard reader, visit the Downloads page.
3. Click on NOOBS, then click on the Download ZIPbutton under ‘NOOBS (offline and network
install)’, and select a folder to save it to.
4. Extract the files from thezip.
Contd…
• FORMAT YOUR SD CARD
1. It is best toformat your SDcard before copying the NOOBSfiles onto it.
To dothis:
2. Visit the SDAssociation’s website and download SDFormatter 4.0 for
either Windows or Mac.
3. Follow the instructions to install the software.
4. Insert your SDcard into the computer or laptop’s SDcard reader and
make a note of the drive letter allocated to it, e.g. G:/
5. In SDFormatter, select the drive letter for your SDcard and format it.
Contd…
• DRAG AND DROP NOOBSFILES
1. Once your SDcard has been formatted, drag all the files in the
extracted NOOBSfolder and drop them onto the SDcarddrive.
2. The necessary files will then be transferred to yourSDcard.
3. When this process has finished, safely remove the SDcard and
insert it into yourRaspberry Pi.
Contd…
• FIRST BOOT
1. Plug in your keyboard, mouse, and monitor cables.
2. Now plug the USBpower cable into your Pi.
3. Your Raspberry Pi will boot, and a window will appear with a list of different operating
systems that you can install. We recommend that you use Raspbian – tick the box next
to Raspbian and click on Install.
4. Raspbian willthen run through its installation process. Note that this can take a while.
5. When the install process has completed, the Raspberry Pi configuration menu (raspi-
config) will load. Here you are able to set the time and date for your region, enable a
Raspberry Pi camera board, or even create users. Youcan exit this menu by
using Tab on your keyboard to move to Finish.
EEE G627: Networked Embedded Applications (Dr. Vinay Chamola, BITS-Pilani)
Powering up the Rpi
SSH(Secure Shell)
• SSH,or Secure Shell, is a protocol used to securely log onto remote
systems. It is the most common way to access remote Linux andUnix-
like servers.
• ssh remote_host
• The remote_host in this example is the IP address or domain name
that you are trying to connectto.
IMP…(EnableSSH)
• As of the November 2016 release, Raspbian has the SSHserver disabled by
default. It can be enabled manually from the Raspberry pi desktop (must have a
keyboard, mouse, and a display attached to the RPI)
• Launch Raspberry Pi Configuration from the Preferencesmenu
• Navigate to the Interfacestab
• Select Enabled next to SSH
• Click OK
Enable SSHon a headless Raspberry Pi (add file to
SDcard on another machine)
• For headless setup, SSHcan be enabled by placing a file named ssh,
without any extension, onto the boot partition of the SDcard from
another computer. When the Pi boots, it looks for the ssh file. If it is
found, SSHis enabled and the file is deleted. The content of the file
does not matter; it could contain text, or nothing at all.
• If you have loaded Raspbian onto a blank SDcard, you will have two
partitions. The first one, which is the smaller one, is the boot
partition. Place the file into thisone.
Connect the Rpi by Ethernet to your PC
Finding IPaddress
• For own System
• Cmd prompt:
 ipconfig

• FOR R-Pi
• Terminal
 ifconfig
SSHusing Windows (putty)
• In Windows you will need to download an SSHclient. The most commonly used
client is called PuTTY. Look for putty.exe under the heading For Windows onIntel
x86.
• Type the IP address of the Pi into the Host Name field and click the Openbutton.
If nothing happens when you click the Open button, and you eventually see a
message saying Network error: Connection timed out, it is likely that you have
entered the wrong IP address for the Pi.
CONNECT
• When the connection works you will see the security warning shown
below. You can safely ignore it, and click the 'Yes' button. You will only
see this warning the first time PuTTYconnects to a Raspberry Pi that
it has not seenbefore.
Contd…
• You will now see the usual login prompt. Log in with the same username
and password you would use on the Pi itself. The default login for Raspbian
is
• Login: pi
• Password: raspberry.
• You should now have the Raspberry Pi prompt which will be identical to the
one found on the Raspberry Piitself.
• pi@raspberrypi ~ $
• Detailed instruction to set upputty.
• https://www.raspberrypi.org/documentation/remote-
access/ssh/windows.md
Type arp –a on your laptop cmd prompt
SSHusing MAC
• You can use SSHto connect to your Raspberry Pi from a Linux
computer, a Mac, or another Raspberry Pi, without installing
additional software
• “ssh pi@<IP>”
• Where IP refers to the IP address of raspberry pi found earlier.
VNCremote access toRpi
• VNC (Virtual Network Computing) is a great technology included with
Raspbian. With this tech, you can remotely control your Raspberry Pi
from another computer, such as a PCor Mac, or even another
Raspberry Pi board.
• Sometimes it’s not convenient to work directly on a Raspberry Pi.This
can be because it’s not easy to access, or because your keyboard and
monitor are being used on your main computer.
• Using remote networking, you can open the Raspbian desktop
interface from your Raspberry Pi inside a window on your computer.
Contd…
• By default, VNC Server from RealVNC gives you direct control over your Raspberry
Pi, just as though you were sitting in front of it.
• However, you will need to enable it yourself. From then on, Server will be loaded
every time you switch on your Raspberry Pi.(Just like we enabled SSH)
• raspi-config can be used in the terminal:
• Enter ”sudo raspi-config” in a terminal window (This is once we havealready
SSHed into theRpi)
• Select Interfacing Options
• Navigate to and select VNC
• Choose Yes
• Select Ok
• Choose Finish
Contd…
• Download and install Viewer on your computer from RealVNC.Open
the app and enter the IPAddress of the Rpi into the VNC Server field.
Ensure Encryption is set to “Let VNCServer choose” and click
Connect. OK. The first time you connect it will display a “VNC Server
not recognized” alert. ClickContinue.
• Enter Pi into the Username field, and “raspberry” (or yourRaspbian
password) in the Password field. The Raspbian PIXELinterface will
appear inside a window on your computer. You can click on the
Menu, open programs and run Terminal commands on your
Raspberry Pi. If you have your Raspberry Connected to a monitor,
you’ll see it move as you remote control it.
LEDBlink
(“Hello World” of Physical computing)
• The simplest thing you can do with an Raspberry Pi to see an actual
physical output is to blink an LED! It’s more like an electronicsversion
of the classical hello world program that we write when learning a
new software language.
• Raspberry Pi has 8 General Purpose Input/Output pins(
4,17,18,21,22,23,24,25) which can be configured as input/output
and turned on/off via software.
• RPi.GPIO Python library is used to control the LEDfrom RaspberryPi.
Only SSH With VNC
>> sudo nano Led.py See in the Rpi desktop
Python (RPi.GPIO)API
• In order to use RPi.GPIO throughout the rest of yourPython script,
you need to put this statement at the top of your file:

import RPi.GPIO as GPIO

• This statement “includes” the RPi.GPIO module, and goes a step


further by providing a local name – GPIO – which we’ll call to
reference the module from hereon.
Pin Numbering Declaration
• After you’ve included the RPi.GPIO module, the next step isto
determine the pin-numbering schemes you want to use:

• GPIO.BOARD – Board numbering scheme. The pin numbers follow the


pin numbers on header P1
• To specify in your code which number-system is being used, use
the GPIO.setmode() function.

GPIO.setmode(GPIO.BOARD)
Setting a Pin Mode
• If you’ve used Arduino, you’re probably familiar with the fact that you
have to declare a “pin mode” before you can use it as either an input
or output.
• To set a pin mode, use the setup([pin], [GPIO.IN, GPIO.OUT] function.
So, if you want to set pin 18 as an output, for example,write:

GPIO.setup(18, GPIO.OUT)
Outputs
1. Digital Output

• To write a pin high or low, use the GPIO.output([pin], [GPIO.LOW,


GPIO.HIGH]) function. For example, if you want to set pin18 high,
write:
GPIO.output(18, GPIO.HIGH)

• Writing a pin to GPIO.HIGH will drive it to 3.3V, and GPIO.LOW willset


it to 0V. Alternative to GPIO.HIGH and GPIO.LOW, you canuse
either 1, True, 0 or False to set a pin value.
Contd…
2. PWM (“Analog”)Output

• PWM on the Raspberry Pi is about as limited as can be – one, single pinis


capable of it: 12
• To initialize PWM, use GPIO.PWM([pin], [frequency]) function. To make the
rest of your script-writing easier you can assign that instance to a variable.
Then use pwm.start([duty cycle]) function to set an initial value. For
example
pwm = GPIO.PWM(12, 0.6)
pwm.start(50)
• Just don’t forget to set the pin as an output before you use it for PWM.
• Toturn PWM on that pin off, use the pwm.stop() command
Inputs
• If a pin is configured as an input, you can use
the GPIO.input([pin]) function to read its value. The input() function
will return either a True or False indicating whether the pin isHIGH or
LOW.You can use an if statement to test this, for example…
if GPIO.input(17):
print("Pin 11 is HIGH")
else:
print("Pin 11 is LOW")

• Itwill read pin 17 and print whether it’s being read as HIGH or LOW.
Delays
• If you need to slow your Python script down, you can add delays.To
incorporate delays into your script, you’ll need to include another
module: time. This line, at the top of your script, will do it for you:

include time

• Then, throughout the rest of your script, youcan


use time.sleep([seconds]) to give your script a rest. You can use
decimals to precisely set your delay. For example, to delay 250
milliseconds, write:
time.sleep(0.25)
Garbage Collecting
• Once your script has run its course, be kind to the next processthat
might use your GPIOs by cleaning up after yourself. Use
the GPIO.cleanup() command at the end of your script to release any
resources your script may be using.
• Your Pi will survive if you forget to add this command, but it is good
practice to include wherever youcan.
Finally “LEDBlink”
• Write a python code in the text editor provided in the raspberry pi
desktop accessories to blink an LEDafter every 1sec.

• Save the file in “.py” format at the desktop or wherever you may wish.

• Then run the command ”python filename.py” on the terminalafter


changing directory to Desktop using ”cd Desktop” command.
LEDblink

PIN 14

PIN 11

PIN 1
Code
PWM

PIN 14
PIN 12

PIN 1
PWM

You might also like