Uploaded by Michelle Hines

Raspberry Pi Introduction: Setup, Components, & Programming

advertisement
Introduction to Raspberry Pi
What Will I learn?
1. What a Raspberry Pi is and does.
2. How to setup a Raspberry Pi and run it for the first time.
3. Get familiar with the Raspberry Pi and some sensors.
4. How to use breadboards, LED, motion detection sensors, switches, wiring,
etc.
5. Basic Linux commands.
What is a Raspberry Pi?
• It is a low-cost, credit-card size computer.
• It is a small single-board computer.
• It is developed in the United Kingdom by the Raspberry Pi Foundation to
promote the teaching of basic computer science in schools and in developing
countries.
• official website: www.raspberrypi.org
Variations of Raspberry Pi
◦ Raspberry Pi Zero
◦ Raspberry Pi
◦ Raspberry Pi 2
◦ Raspberry Pi 3 (with Wifi + Bluetooth)
◦ Raspberry Pi 4 (with Wifi + Bluetooth) ---> your kit includes this model
The Main Parts of a Computer System
• Processor: CPU (Central Processing Unit)
• Memory Unit: RAM (Random Access Memory)
• Input / Output
• Hard disk or secondary storage
• Communication devices (ethernet / WIFI / Bluetooth / etc. )
• Operating System
Raspberry Pi Main Parts Diagram
Image: https://projects.raspberrypi.org/en/projects/raspberry-pi-getting-started/2
Raspberry Pi All Parts Diagram
Image: https://realpython.com/python-raspberry-pi/
Operating System (OS)
• The Raspberry Pi Foundation provides Raspbian OS, as well as third party
Ubuntu, Windows 10 IOT Core, RISC OS, and other OS distributions.
• It promotes Python and Scratch as the main programming language, with
support for many other languages.
• We will use Raspbian OS + Python programming language.
Safe Online Behavior
>> Updating Software & Applications
• Always update your Raspberry Pi. Keeping your computer up to date
minimizes the chances for attacker to find weaknesses in your system.
• To update the Raspberry Pi, type the following commands:
• sudo apt update
• sudo apt upgrade
Raspberry Pi – Username & Password
The Raspberry Pi has the following default username and
password:
◦ Username: pi
◦ Password: raspberry
Safe Online Behavior
>> Changing the Default Password
• New electronic devices come with a default password. The common
password is provided for easy setup and installation.
• Always update the default password. Changing the default password to a
new secure password increases the security of your device.
• To update the Raspberry Pi password, click on the Raspberry icon on the top
left, select Preferences, select Raspberry Pi Configuration
GPIO Pins
• The Raspberry Pi features forty GPIO pins along the top edge of the
board. You can use these GPIO pins to connect the Raspberry Pi to
external components.
• The pin layout shows the different types of pins and their locations.
This layout is based on an overhead view of the pins with the
Raspberry Pi’s USB ports facing you.
• You can get the pin layout by typing the following terminal
command in Raspberry Pi: pinout
GPIO Pins (cont.)
The Raspberry Pi features five different types of pins:
1.
2.
3.
4.
5.
GPIO: These are general-purpose pins that can be used for input or
output.
3V3: These pins supply a 3.3 V power source for components. 3.3 V
is also the internal voltage that all GPIO pins supply.
5V: These pins supply a 5 V power source, the same as the USB
power input that powers the Raspberry Pi. Some components, such
as the passive infrared motion sensor, require 5 V.
Ground: These pins provide a ground connection for circuits.
ID SD: These special-purpose pins (physical pins 27 & 28) are
advanced and not covered in this tutorial.
Let’s Learn About Other Components
• Breadboards
• Jumper wires
• LEDs
• Motion detection sensors
• Buzzers
• Resistors
• Switches
• Contact switches
• Camera module
•
Breadboard
The breadboard is a way of connecting electronic
components to each other without having to solder them
together.
•
All holes in a single rail are connected. In the middle is a
gutter separating the two sides of the breadboard. Rails on
opposite sides of the gutter are not connected.
•
In the picture, three colors are used to mark the different
types of breadboard rails:
Red: Positive rail
Black: Negative rail
Blue: Component rails
LED (Light Emitting Diode)
• LED glows when electricity is passed through it.
• When you pick up the LED, you will notice that one leg is longer than the
other. The longer leg (known as the ‘anode’), is always connected to
the positive power supply of the circuit. The shorter leg (known as the
‘cathode’) is connected to the negative side of the power supply, known as
‘ground’.
• LED will not light if it is connected the wrong way.
• ALWAYS use a resistor when you connect an LED in your circuit.
Resistor
• You must ALWAYS use resistors to connect LEDs up to the GPIO pins of the
Raspberry Pi.
• The measure of resistance is called the Ohm (Ω), and the larger the resistance, the
more it limits the current.
• The value of a resistor is marked with colored bands along the length of the resistor
body.
• There could be 4 or 5 bands.
• The resistor in the picture above is (330 Ω). The colors are: orange / orange / brown
/ gold
• It does not matter which way round you connect the resistors. Current flows in both
ways through them.
Jumper Wires
• Jumper wires are used on breadboards to ‘jump’ from one connection to
another.
• The ones you will be using in this circuit have different connectors on each
end.
• The end with the ‘pin’ will go into the Breadboard.
• The end with the piece of plastic with a hole in it will go onto the Raspberry
Pi’s GPIO pins.
Push Button Switch
• Push buttons allow us to power the circuit or make any particular connection only
when we press the button.
• Simply, it makes the circuit connected when pressed and breaks when released. A
push button is also used for triggering an input GPIO.
•There is direct connection between A and B, whether button is pressed or not. And
same for C and D.
• When button is pressed, A and C are getting shorted (actually all pins are getting
shorted) and same way B and D are getting shorted.
• So to use this push button as a switch, use either A-C pair or B-D.
• The 4 pin push button switch is placed in the middle of the breadboard (the gap in
the middle makes A/C in one side and B/D in the other side)
Buzzers
• Piezo buzzers are simple devices that can generate basic beeps and tones.
•They work by using a piezo crystal, a special material that changes shape
when voltage is applied to it. If the crystal pushes against a diaphragm, like a
tiny speaker cone, it can generate a pressure wave which the human ear picks
up as sound.
• To connect a buzzer, you need a ground pin and a GPIO pin.
• The black wire is connected to the ground.
• The red wire is connected to the GPIO pin (any GPIO ## works fine).
• If you reverse the wires, there will be no sound output.
PIR Motion Detection Sensor
• PIR (passive infrared) motion sensor detects moving objects.
They are mostly used in automatically activated lighting and
alarm systems.
• PIR motion sensors detect change in the infrared radiation
impinging on it.
• When any object or human passes in the front of the PIR
sensor, the temperature in sensor’s field of view will rise from
ambient temperature to object temperature and then back
again to ambient temperature.
• PIR sensor converts this temperature change into the change
in output voltage and that change in voltage is considered as
motion detected.
PIR Motion Detection Sensor
• On the PIR Sensor there are three pins. A VCC, OUT, and
GND. Using jumper wires connect the VCC to 5V, the OUT to
the GPIO pin you will use in your code, and the GND to GND.
The OUT pin gives logic high if motion is detected.
• You should also note the 2 orange phillips screw heads.
These are the potentiometers that control the sensitivity
(Sx) and timing (Tx). This will be the baseline and can be
tuned later to your preference.
• Check your sensor, VCC and Ground pins maybe reversed.
Pi Camera Module
• The camera module has a ribbon that will be inserted into the camera slot in
the Raspberry Pi board.
• It is not controlled by GPIO pins.
• We will use “PiCamera” library to control the connected camera.
• When an event is triggered, the camera captures an image.
How to Program GPIO Pins
• In this lab, we will use Python programming language to program the
Raspberry Pi.
• There are several packages/libraries that we can use to interact and
program the GPIO pins.
• import gpiozero
• import PI.GPIO
• The “gpiozero” library has many built-in classes that we can use, it is easer
to use. We will use it in our labs.
Customized Input / Output
Image: https://projects.raspberrypi.org/en/projects/button-switch-scratch-pi/1
IoT LEGO-Style Building Blocks
• A basic Python program “building block” for each component is provided.
• The goal is use these blocks to build more complex systems, similar to
building a complex structure using simple LEGO blocks.
• The Python program shows the basic functions needed to use the
component and program it.
• Some examples and circuit diagrams are given to practice.
IoT LEGO-Style Building Blocks (cont.)
• The following blocks are provided:
• LED Block
• Button Block
• Buzzer Block
• PIR Motion Sensor Block
• Camera Block
• Keyboard Input-Output Block
• CSV Files Block
• Hashing Block
• Secure Random Numbers Block
• SMS Notification Block
References
www.raspberrypi.org
https://realpython.com/python-raspberry-pi/
https://gpiozero.readthedocs.io/en/stable/
Download