RASPBERRY PI
Introduction
Raspberry Pi is an ARM cortex based board designed for Electronic
Engineers and Hobbyists. It’s a single board computer working on low power.
With the processing speed and memory, Raspberry Pi can be used for performing
different functions at a time, like a normal PC, and hence it is called Mini
Computer in your palm.
Because it has
an ARMv7 processor, it can run the full range of ARM GNU/Linux distributions as
well as Microsoft Windows 10, we will discuss about that later. ARM architecture
is very influential in modern electronics. We are using the ARM architecture
based processors and controllers everywhere. For example we are using ARM
CORTEX processors in our mobiles, iPods and computers etc.
Pi is an
amazing tool for realizing ‘Internet of Things’. In this session we will
discuss the hardware and software requirements for Pi and setting up the
Operating System for the first run of PI.
There are different types of Raspberry Pi boards in the market now, with Raspberry Pi 2 Model B being the most popular. Raspberry Pi 3 Model B has also been launched; it is almost
similar to RPi 2, with some advance feature like on board Wi-Fi and Bluetooth
connectivity, more powerful CPU etc. We will discuss few characteristics
of “Raspberry Pi 2 B” now.
Raspbeery
Pi has four USB 2.0 ports.
These ports can be connected to any USB devices, like mouse and keyboard. With
the first start itself, we need mouse and keyboard, we will discuss it later.
The four USB ports are shown the figure.
Raspbeery
Pi 2 has one Ethernet
port. This port is for internet connectivity to the RASPBEERY PI 2.
This Ethernet port can also be used to transfer data between PI2 and your PC.
·
It has a 3.5mm
jack port for connecting
headphones, in case of playing music from PI.
·
PI has a single
HDMI port for connecting
a LCD/LED screen. The graphics provided by the chip is fairly good.
There
is a micro USB port on the board; we provide power for the
complete board through this port. If there are any fluctuations in voltage
provided at this port, the board will not work properly.
Instead
of connecting an LCD screen we can connect a 3inch to 7inch touch display. We
have inbuilt port for
connecting a touch display. We have a similar port for connecting a camera to the module; the camera module can
be connected to PI without any additional attachments.
There
are GPIO (General Purpose Input Output) pins and a couple power
ground terminals. We can program there GPIO pins for any use. Few of
these pins also perform special functions, we will discuss them later.
Hardware Requirements:
1. Power supply - As said earlier we will power the Raspberry Pi board by Micro USB port present on the board. Under normal operations the PI
board needs a 5V, 1000mA (or 1A) power source. The voltage and current
requirements are important here. Any power source higher than 5V will damage
the board permanently and for voltages lower than 4.8V, the board will not
function.
Here
I am using a 5V, 1000mA mobile phone
charger for powering up my PI.
Remember the minimum current rating for normal operation of PI board.
For
connecting the micro USB power, you need a good quality cable. If you do not
power the board from a good USB cable, no matter what the
power source, you will always have power shortage on the board. You need a good
quality USB cable as shown in figure.
For
higher operations of PI, you need a power source which could deliver at least
2000mA or 2A. So if you don’t have a power source of such kind, don’t drive the
PI by lower rated power source, its better get a new one.
But
if you have two adapters which can provide each, you can connect one adapter output
to the micro USB, and the second one to the USB 2.0 port, they both can share
the load. Here I have a 0.7A or 700mA adapter which I connect to one of 4 USB
ports on the chip.
2.
You need a LCD or LED screen, you can use your old
PC screen as a Raspberry Pi screen. After choosing your screen, you have to
look whether the screen supports HDMI inputs or not. If your screen has a HDMI
port then you just need to get a male to male HDMI cable as shown in figure.
If
your screen does not support HDMI like mine, then your screen must have VGA support as shown in figure. You need a HDMI to VGA converter; you can buy this at
any electronic store. This device converts HDMI from PI to VGA output. So we
can interface a VGA monitor to a PI. The device is shown in figure.
If
your screen does not support HDMI like mine, then your screen must have VGA support as shown in figure. You need a HDMI to VGA converter; you can buy this at
any electronic store. This device converts HDMI from PI to VGA output. So we
can interface a VGA monitor to a PI. The device is shown in figure.
3.You need a Mouse
and Keyboard, make sure they are USB driven type or
you won’t be able to connect it to PI, since PI only has USB ports.
4. You need a Micro
SD card (Memory
card) and a SD
Card Reader (or
Adapter) to connect SD card to PC (or laptop). The SD card must be of 8GB or
higher. If not, you won’t be able to install the OS (Operating System) on to
the PI easily. And also the Class of SD card should be equal or higher than 4,
for better speed. “Speed Class” represents the writing speed like class 10
means 10 MB/second.
Now
we have all the basic Hardwares, need to Getting Started with Raspberry Pi, and we will now
discuss the Software Requirement.
Software Requirements:
First we
need the OS (Operating System) for the PI, which can be downloaded from
Downloads section of Raspberry Pi website:
It will
show you all the supporting OS for the RASPBEERY PI 2. You can download and
install any OS on Pi which is listed there. We are going to download official
supported Operating System for Raspberry Pi, which is “Raspbian”.
Click on “RASPBIAN”, and download the Full desktop image of Raspbian Jessie. Extract the Rasbian image from
the Zip file, using any Zip file extractor like Winrar or Winzip.
We
also need a Image writer software for installing the OS on to the Micro SD card. We have used
“win32diskimager” to write the image on Micro SD card, which
can be downloaded from below link:
Once
the download completes, install the software, you will see an icon on the
Desktop Screen after installation.
Get started with Raspberry Pi: Steps
Now, we have all the software
and hard ware required to get started with the RASPBEERY PI 2.
To install OS on to a SD card follow below
steps:
1. UNZIP the ‘Raspbian
Jessie’ (OS ZIP file we downloaded from raspberry website) on to the
desktop; you will see an Image icon upon extraction on the screen as shown
below. Make sure you have at least 5 GB free disk space on ‘C’ drive of
your PC. The extraction file size would be greater than 3GB.
2. Insert the SD card into the USB card reader
or Card Adapter. Plug the card reader to the PC. You must see the card on the
screen as shown below.
3. Format the card drive by Right click
on it and select Format.
Select File system as ‘FAT32’ and tick on ‘Quick Format’. Finally click on
‘Start’ button to Format the drive.
4.
After formatting, run the “win32diskimager” application, which we have
downloaded as explained previously.
5.
Choose the SD card drive, browse for the Raspbian OS image file (which is
extracted on the screen) and Click on ’WRITE’ icon, to start writing the extracted OS file on to the SD
card. This is shown in below figure.
6.
After completion of writing, safely remove the SD card from the reader.
Now
we have SD card with Raspbian
OS installed on it and having all
the equipment required to Get Started with Raspberry PI 2. In the next session
we will have the first look at the “PI” OS and we will talk about configuring the BIOS of
Raspberry Pi.
Once
the OS (Raspbian Jessie) installed SD card is inserted into the
Raspberry Pi with the screen, keyboard and mouse connected, we are ready to boot
the Jessie first time. For this particular OS you don’t need Ethernet
connection.
Once
the power is started ON, you will see the power RED LED glowing. The BLUE
LED will start blinking at this stage, this means the OS (Operating System) is
loading and the PI is checking all the drivers.
By
this time you will see data on the screen as shown below,
As
told its just PI is loading all the drives. You have to wait until all the
drivers are checked, in case of error, turn off and on to restart PI. If there
is still trouble try installing the OS on to the SD card again by following the
steps described in first session.
If
everything goes successfully, you will be asked for authorization. This
authorization is predefined, with Username “pi” and password “raspberry”,
USER: pi
< Press enter>
PASSWORD: raspberry
< Press enter>
Once
you enter these details, you will be entered in CLI mode (Command Line) of
Raspberry Pi. For entering into the DESKTOP of PI you need to type,
startx
< Press enter>
BIOS SETTINGS:
Now you have entered into the screen of
Raspberry Pi and you are ready to go. Before going for the programming,
1. You need to configure the BIOS settings of
PI.
2. You need to configure the keyboard, you have
chosen.
If you don’t do these two things first you get
lot of errors, while programming and operating the PI.
For configuring the BIOS of PI first open the ‘LX TERMINAL” of PI and enter this
sudo raspi-config
< Press enter>
The BIOS options are as,
We will
discuss each of these options briefly below,
1.
Expand File System: After first start, some memory of
the SD will be misplaced and is not considered by PI. You need to select this
option to get the files & order and to display the remaining memory of SD
card. Once you choose this option, the PI will REBOOT to get everything in
order. If you don’t expand the file system, you will not be able to use
remaining memory of SD card.
2.
Change Password: This option changes the login
password, its “pi” by default. Just leave it, if you are not doing any
important work.
3.
Boot To Desktop: On the first start you are
entered in CLI mode, as discussed earlier. This option disables that, so that
you can enter DESKTOP of Pi with every start.
4.
Internationalisation Options: This option is for choosing
language. Its ENLGLISH by default, leave it you don’t want to change the
language and date. The DATE may be wrong, we will configure theses settings
later.
5.
Enable Camera: If you have a camera module at
hand, configure this option. It will turn on the CAM. If you don’t have a
camera, just leave it. Remember camera module draws power, so once you enable
it the module will be drawing power continuously.
6.
Add To Rastack: This option is for connecting
your PI online. Just leave it.
7.
Over Clock: This option over clocks PI, thus
increasing your PI speed and also its power consumption. Over clocking might
damage the board, if efficient cooling system is not provided. For basic
programming, you need not over clock the PI, just leave it 900MHz.
8.
Advanced Options: These options for BOARD devices (like AUDIO, I2C etc)
configuration:
We have
few options under this, but the important for now is, ‘AUDIO’. The PI can
output AUDIO either from HEADPHONE jack (on the PI board) or from HDMI port. To
find out the ports, check Getting Started with Raspberry Pi. Choose the appropriate one
based on you usage. If you won’t configure this, you won’t get AUDIO. The
remaining options are not important for now.
Keyboard Configuring:
We use
different type of keyboard all around the world, most of the keys match for all
keyboards. But few keys mismatch. This will cause really trouble while
programming, as special keys play a crucial part while doing programming in PYTHON and LINUX. So we need to configure the
Raspberry Pi to the keyboard we are using. I am from INDIA and almost everyone
one here uses US (United States) keyboard models.
So I am
configuring this on the ‘Keyboard Layout’ option,
LED Blinking with Raspberry Pi and Python Program
The concept of writing and executing
programs on PYTHON. We will start with Blink LED using Raspberry Pi. Blinky is done by connecting an
LED to one of GPIO pins of PI and turning it ON and OFF.
We will
discuss a bit about PI GPIO Pins before going any further,
Components Required:
Here we
are using Raspberry Pi 2 Model B with Raspbian Jessie OS. All the basic Hardware and
Software requirements are previously discussed, you can look it up in the Raspberry Pi Introduction, other than that we need:
·
Connecting
pins
·
220Ω
or 1KΩresistor
·
LED
·
Bread
Board
Circuit Explanation:
As shown
in the circuit diagram we are going to connect an LED between PIN40 (GPIO21)
and PIN39 (GROUND). As said earlier, we cannot draw more than 15mA from
any one of these pins, so to limit the current we are connecting a 220Ω or 1KΩ
resistor in series with the LED.
Working Explanation:
Since we
have everything ready, turn ON your PI and go to the desktop.
1. On
the desktop, go the Start Menu and choose for the PYTHON 3, as shown in figure below.
2. After
that, PYHON will run and you will see a window as shown in below figure.
3. After
that, click on New File in File Menu, You will see a new Window
open,
4. Save this file as blinky on the desktop,
5. After that write the program for blinky as
given below and execute the program by clicking on “RUN” on ‘DEBUG’ option.
If the
program has no errors in it, you will see a “>>>”, which means the program is executed successfully.
By this time you should see the LED blinking three times. If there were
any errors in the program, the execution tells to correct it. Once the error is
corrected execute the program again.
We will
see the PYTHON program Code for LED Blinking, in detail, below.
Code:
import RPi.GPIO as IO
# calling header file for GPIO’s of PI
import time # calling for time to provide delays in program
IO.setmode
(IO.BOARD) # programming the GPIO by BOARD pin
numbers, GPIO21 is called as PIN40
IO.setup(40,IO.OUT) # initialize digital pin40 as an output.
IO.output(40,1) # turn the LED on (making the voltage level HIGH)
time.sleep(1) # sleep for a second
IO.cleanup() # turn the LED off (making all the output pins LOW)
time.sleep(1) #sleep for a second
IO.setup(40,IO.OUT) # initialize digital pin40 as an output.
IO.output(40,1) # turn the LED on (making the voltage level HIGH)
time.sleep(1) # sleep for a second
IO.cleanup() # turn the LED off (making all the output pins LOW)
time.sleep(1) #sleep for a second
#loop is executed second
time
IO.setmode (IO.BOARD)
IO.setup(40,IO.OUT)
IO.output(40,1)
time.sleep(1)
IO.cleanup()
time.sleep(1)
IO.setmode (IO.BOARD)
IO.setup(40,IO.OUT)
IO.output(40,1)
time.sleep(1)
IO.cleanup()
time.sleep(1)
#loop is executed third time
IO.setmode (IO.BOARD)
IO.setup(40,IO.OUT)
IO.output(40,1)
time.sleep(1)
IO.cleanup()
time.sleep(1)
IO.setmode (IO.BOARD)
IO.setup(40,IO.OUT)
IO.output(40,1)
time.sleep(1)
IO.cleanup()
time.sleep(1)
Comments
Post a Comment