0% found this document useful (0 votes)
94 views

Raspberry Pi

The document provides information about the Raspberry Pi single board computer. It describes that Raspberry Pi can function as a mini personal computer when connected to peripherals like a keyboard, mouse, and display. It comes preloaded with operating systems like Raspbian and supports additional third party OS. Raspberry Pi is popular for applications involving image/video processing, IoT, and robotics due to its low cost and accessibility of GPIO pins. It has an ARM processor, GPU, and onboard memory and connectivity options. The document outlines the specifications of various Raspberry Pi models and provides examples of using GPIO pins to control an external LED.

Uploaded by

Harshit uppal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Raspberry Pi

The document provides information about the Raspberry Pi single board computer. It describes that Raspberry Pi can function as a mini personal computer when connected to peripherals like a keyboard, mouse, and display. It comes preloaded with operating systems like Raspbian and supports additional third party OS. Raspberry Pi is popular for applications involving image/video processing, IoT, and robotics due to its low cost and accessibility of GPIO pins. It has an ARM processor, GPU, and onboard memory and connectivity options. The document outlines the specifications of various Raspberry Pi models and provides examples of using GPIO pins to control an external LED.

Uploaded by

Harshit uppal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

RaspberryPi

Raspberry Pi 3 Board

Raspberry Pi is a small single board computer. By connecting peripherals like Keyboard,


mouse, display to the Raspberry Pi, it will act as a mini personal computer.

Raspberry Pi is popularly used for real time Image/Video Processing, IoT based applications
and Robotics applications.

Raspberry Pi is slower than laptop or desktop but is still a computer which can provide all the
expected features or abilities, at a low power consumption.

Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they provide
NOOBS OS for Raspberry Pi. We can install several Third-Party versions of OS like Ubuntu,
Archlinux, RISC OS, Windows 10 IOT Core, etc.
Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi. Raspbian have GUI which includes tools for Browsing,
Python programming, office, games, etc.

We should use SD card (minimum 8 GB recommended) to store the OS (operating System).

Raspberry Pi is more than computer as it provides access to the on-chip hardware i.e. GPIOs
for developing an application. By accessing GPIO, we can connect devices like LED, motors,
sensors, etc and can control them too.

It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics Processing
Unit).

The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz. Also, it has on-board SDRAM
that ranges from 256 MB to 1 GB.

Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules.

There are different versions of raspberry pi available as listed below:

1. Raspberry Pi 1 Model A
2. Raspberry Pi 1 Model A+
3. Raspberry Pi 1 Model B
4. Raspberry Pi 1 Model B+
5. Raspberry Pi 2 Model B
6. Raspberry Pi 3 Model B
7. Raspberry Pi Zero

Out of the above versions of Raspberry Pi, more prominently use Raspberry Pi and their
features are as follows:

Features Raspberry Pi Raspberry Pi 2 Raspberry Pi 3 Raspberry Pi


Model B+ zero
Model B Model B

SoC BCM2835 BCM2836 BCM2837 BCM2835

CPU ARM11 Quad Cortex A7 Quad Cortex A53 ARM11

Operating 700 MHz 900 MHz 1.2 GHz 1 GHz


Freq.

RAM 512 MB SDRAM 1 GB SDRAM 1 GB SDRAM 512 MB SDRAM


GPU 250 MHz 250MHz 400 MHz 250MHz
Videocore IV Videocore IV Videocore IV Videocore IV

Storage micro-SD Micro-SD micro-SD micro-SD

Ethernet Yes Yes Yes No

Wireless WiFi and Bluetooth No No No

Raspberry Pi zero and Raspberry Pi are shown below

Raspberry Pi Zero
Raspberry Pi Board

Raspberry Pi 3 On-chip Hardware


The On-chip hardware of Raspberry Pi 3 (here) is as shown in below figure,
Raspberry Pi 3 Model B Hardware

Some Hardware Components shown above are mention below:

1. HDMI (High-Definition Multimedia Interface): It is used for transmitting uncompressed


video or digital audio data to the Computer Monitor, Digital TV, etc. Generally, this HDMI
port helps to connect Raspberry Pi to the Digital television.
2. CSI Camera Interface: CSI (Camera Serial Interface) interface provides a connection in
between Broadcom Processor and Pi camera. This interface provides electrical
connections between two devices.
3. DSI Display Interface: DSI (Display Serial Interface) Display Interface is used for
connecting LCD to the Raspberry Pi using 15-pin ribbon cable. DSI provides fast
High-resolution display interface specifically used for sending video data directly from
GPU to the LCD display.
4. Composite Video and Audio Output: The composite Video and Audio output port
carries video along with audio signal to the Audio/Video systems.
5. Power LED: It is a RED colored LED which is used for Power indication. This LED will
turn ON when Power is connected to the Raspberry Pi. It is connected to 5V directly and
will start blinking whenever the supply voltage drops below 4.63V.
6. ACT PWR: ACT PWR is Green LED which shows the SD card activity.

Getting Started with Raspberry Pi


● To get started with Raspberry Pi, we have to store required OS on SD card.
● Now to store OS on SD card we need to install OS on SD card. If you want to know how
to install/store OS on SD card you can refer Installing Operating System Image on SD
card.
● Here, we installed the Raspbian OS on SD card.
● Now, we have an SD card with installed OS and Raspberry Pi Board.
● Initially to use raspberry Pi we need computer monitor or Digital Display.
● We can directly connect Raspberry Pi to the Digital Display using HDMI cable.

HDMI Cable

● But, if we have a computer monitor (VGA Display), then we need an HDMI to VGA
converter along with a VGA cable for connecting Raspberry Pi with monitors. HDMI to
VGA converter and VGA cable is shown below.
HDMI to VGA Converter

VGA Cable

Now, connect the Raspberry Pi to the Display/monitor and Power-On Raspberry Pi. We will get
a Black command window asking for Login and Password as shown below
● Then, use the following login name and password
raspberrypi Login: pi

Password: raspberry

● This is the default user name and password. You can change the password after the first
login.

The above command window can be used to operate Raspberry Pi.

● To get GUI environment on Raspberry Pi, use below command,

startx

And we will get Home Screen of Raspberry Pi as shown below:

● On display, there is a symbol of raspberry to the top-left corner of display. After clicking
on it, we will get menu as shown below,
● As we can see, the Raspbian OS has installed Python 2 & 3. It also has different
programming IDE like Geany, BlueJ Java IDE, etc. As raspberry pi 3 has On-chip WiFi,
we can connect it to the network and will get access over Internet.
● We can also change password of “Pi” user.
● To change password, click on preferences and then select Raspberry Pi
Configuration which will provide a pop-up window.
● Then, click on change password option shown below.
Now, we are quite familiar with Raspberry Pi OS.

How to write C program on Raspbian OS

● So, let’s write our First C code on Raspbian and execute it.
● First Create Empty file and label it with .c extension.
● Now write a small program to print “Hello World”

Program

#include<stdio.h>
int main(){
printf(“Hello World”);
return 0;
}

After writing the code, open terminal (ctrl+alt+t) to execute it. Then, type following commands for
compiling and execution.

GPIO (General Purpose Input Output) pins can be used as input or output and allows raspberry
pi to connect with general purpose I/O devices.

● Raspberry pi 3 model B took out 26 GPIO pins on board.


● Raspberry pi can control many external I/O devices using these GPIO’s.
● These pins are a physical interface between the Pi and the outside world.
● We can program these pins according to our needs to interact with external devices. For
example, if we want to read the state of a physical switch, we can configure any of the
available GPIO pins as input and read the switch status to make decisions. We can also
configure any GPIO pin as an output to control LED ON/OFF.
● Raspberry Pi can connect to the Internet using on-board Wi-Fi or Wi-Fi USB adapter.
Once the Raspberry Pi is connected to the Internet then we can control devices, which
are connected to the Raspberry Pi, remotely.

GPIO Pins of Raspberry Pi 3 are shown in below figure:


Raspberry Pi 3 Model B GPIO Pins

Some of the GPIO pins are multiplexed with alternate functions like I2C, SPI, UART etc.

We can use any of the GPIO pins for our application.

Pin Numbering
We should define GPIO pin which we want to use as an output or input. But Raspberry Pi has
two ways of defining pin number which are as follows:

● GPIO Numbering
● Physical Numbering

In GPIO Numbering, pin number refers to number on Broadcom SoC (System on Chip). So, we
should always consider the pin mapping for using GPIO pin.

While in Physical Numbering, pin number refers to the pin of 40-pin P1 header on Raspberry
Pi Board. The above physical numbering is simple as we can count pin number on P1 header
and assign it as GPIO.
But, still we should consider the pin configuration diagram shown above to know which are
GPIO pins and which are VCC and GND.

Interfacing Diagram

Control LED using Raspberry Pi

Example

Now, let’s control LED using switch connected to the Raspberry Pi. Here, we are using Python
and C (WiringPi) for LED ON-OFF control.
Control LED using Python
Now, let’s turn ON and OFF an LED using Python on Raspberry Pi. Switch is used to control the
LED ON-OFF.

Python Program

import RPi.GPIO as GPIO #import RPi.GPIO module

LED = 32 #pin no. as per BOARD, GPIO18 as per BCM


Switch_input = 29 #pin no. as per BOARD, GPIO27 as per BCM
GPIO.setwarnings(False) #disable warnings
GPIO.setmode(GPIO.BOARD) #set pin numbering format
GPIO.setup(LED, GPIO.OUT) #set GPIO as output
GPIO.setup(Switch_input, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
if(GPIO.input(Switch_input)):
GPIO.output(LED,GPIO.LOW)
else:
GPIO.output(LED,GPIO.HIGH)

Functions Used:

RPi.GPIO

To use Raspberry Pi GPIO pins in Python, we need to import RPi.GPIO package which has
class to control GPIO. This RPi.GPIO Python package is already installed on Raspbian OS. So,
we don’t need to install it externally. Just, we should include library in our program to use
functions for GPIO access using Python. This is given as follows.

import RPi.GPIO as GPIO

GPIO.setmode (Pin Numbering System)

This function is used to define Pin numbering system i.e. GPIO numbering or Physical
numbering.

In RiPi.GPIO GPIO numbering is identified by BCM whereas Physical numbering is identified by


BOARD

Pin Numbering System = BOARD/BCM


E.g. If we use pin number 40 of P1 header as a GPIO pin which we have to configure as output
then,

In BCM,

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.OUT)

In BOARD,

GPIO.setmode(GPIO.BOARD)

GPIO.setup(40, GPIO.OUT)

GPIO.setup (channel, direction, initial value, pull up/pull down)

This function is used to set the direction of GPIO pin as an input/output.

channel – GPIO pin number as per numbering system.

direction – set direction of GPIO pin as either Input or Output.

initial value – can provide initial value

pull up/pull down – enable pull up or pull down if required

Few examples are given as follows,

● GPIO as Output

GPIO.setup(channel, GPIO.OUT)

● GPIO as Input

GPIO.setup(channel, GPIO.IN)

● GPIO as Output with initial value

GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)

● GPIO as Input with Pull up resistor

GPIO.setup(channel, GPIO.IN, pull_up_down = GPIO.PUD_UP)

GPIO.output(channel, state)

This function is used to set the output state of GPIO pin.


channel – GPIO pin number as per numbering system.

state – Output state i.e. HIGH or LOW of GPIO pin

e.g.

GPIO.output(7, GPIO.HIGH)

GPIO.input(channel)

This function is used to read the value of GPIO pin.

e.g.

GPIO.input(9)

Control LED using C (WiringPi)


We can access Raspberry Pi GPIO using C. Here, we are using WiringPi library for accessing
Raspberry Pi GPIO using C.

Program

#include <wiringPi.h>
#include <stdio.h>
int LED = 26; /* GPIO26 as per wiringPi, GPIO12 as per BCM, pin no.32 */
int switch_input = 21; /* GPIO21 as per WiringPi, GPIO5 as per BCM, pin no.29 */
int main(){
wiringPiSetup(); /* initialize wiringPi setup */
pinMode(LED,OUTPUT); /* set GPIO as output */
pullUpDnControl(switch_input, PUD_UP);
while (1){
if(digitalRead(switch_input))
digitalWrite(LED,LOW); /* write LOW on GPIO */
else
digitalWrite(LED, HIGH); /* write HIGH on GPIO */

}
}

You might also like