0% found this document useful (0 votes)
23 views34 pages

Date: Raspberry Pi

Raspberry Pi is a small, inexpensive computer used to learn programming. It has ports for connecting a keyboard, mouse, monitor, and other devices. The document guides setting up the Raspberry Pi by installing an operating system onto an SD card, connecting peripherals, and powering on the device. Basic tasks like saving files, using commands in the Terminal, and connecting to the internet are demonstrated to introduce the user to the Raspberry Pi system.

Uploaded by

Prabhu Dorai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views34 pages

Date: Raspberry Pi

Raspberry Pi is a small, inexpensive computer used to learn programming. It has ports for connecting a keyboard, mouse, monitor, and other devices. The document guides setting up the Raspberry Pi by installing an operating system onto an SD card, connecting peripherals, and powering on the device. Basic tasks like saving files, using commands in the Terminal, and connecting to the internet are demonstrated to introduce the user to the Raspberry Pi system.

Uploaded by

Prabhu Dorai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Ex no: INTRODUCTION TO RASPBERRY PI PLATFORM AND PYTHON PROGRAMMING

Date :

Raspberry Pi
You are going to take a first look at Raspberry Pi! You should have a Raspberry Pi computerin
front of you for this. The computer shouldn’t be connected to anything yet.

o Look at your Raspberry Pi. Can you find all the things labelled on the diagram?

USB ports — these are used to connect a mouse and keyboard. You can also connect
other components, such as a USB drive.
SD card slot — you can slot the SD card in here. This is where the operating system
software and your files are stored.
Ethernet port — this is used to connect Raspberry Pi to a network with a cable.
Raspberry Pi can also connect to a network via wireless LAN.
Audio jack — you can connect headphones or speakers here.

HDMI port — this is where you connect the monitor (or projector) that you are usingto
display the output from the Raspberry Pi. If your monitor has speakers, you can alsouse
them to hear sound.
Micro USB power connector — this is where you connect a power supply. You should
always do this last, after you have connected all your other components.
GPIO ports — these allow you to connect electronic components such as LEDs and buttons

27
to Raspberry Pi.

Set up your SD card


If you have an SD card that doesn’t have the Raspberry Pi OS operating system on it yet, or if you
want to reset your Raspberry Pi, you can easily install Raspberry Pi OS yourself. To do so, you
need a computer that has an SD card port — most laptop and desktop computers haveone.
The Raspberry Pi OS operating system via the Raspberry Pi Imager
Using the Raspberry Pi Imager is the easiest way to install Raspberry Pi OS on your SD card.Note:
More advanced users looking to install a particular operating system should use this guide to
installing operating system images.
Download and launch the Raspberry Pi Imager

o Visit the Raspberry Pi downloads page

o Click on the link for the Raspberry Pi Imager that matches your operating system

28
o When the download finishes, click it to launch the installer

Using the Raspberry Pi Imager


Anything that’s stored on the SD card will be overwritten during formatting. If your SD card
currently has any files on it, e.g. from an older version of Raspberry Pi OS, you may wish to
back up these files first to prevent you from permanently losing them.
When you launch the installer, your operating system may try to block you from running it.
For example, on Windows I receive the following message:

29
If this pops up, click on More info and then Run anyway
Follow the instructions to install and run the Raspberry Pi Imager
Insert your SD card into the computer or laptop SD card slot
In the Raspberry Pi Imager, select the OS that you want to install and the SD card you
would like to install it on
Note: You will need to be connected to the internet the first time for the the Raspberry Pi
Imager to download the OS that you choose. That OS will then be stored for future offline use.
Being online for later uses means that the Raspberry Pi imager will always give you the latest
version.

30
31
Then simply click the WRITE button
Wait for the Raspberry Pi Imager to finish writing
Once you get the following message, you can eject your SD card

Connect your Raspberry Pi


Let’s connect up your Raspberry Pi and get it running.
o Check the slot on the underside of your Raspberry Pi to see whether an SD card is inside.If
no SD card is there, then insert an SD card with Raspbian installed (via NOOBS).

32
Note: Many microSD cards come inside a larger adapter — you can slide the smaller card out
using the lip at the bottom.

o Find the USB connector end of your mouse’s cable, and connect the mouse to a USB port
on your Raspberry Pi (it doesn’t matter which port you use).

o Connect the keyboard in the same way.

o Make sure your screen is plugged into a wall socket and switched on.
o Look at the HDMI port(s) on your Raspberry Pi — notice that they have a flat side on top.

33
o Use a cable to connect the screen to the Raspberry Pi’s HDMI port — use an adapter if
necessary.
Raspberry Pi 4
Connect your screen to the first of Raspberry Pi 4’s HDMI ports, labelled HDMI0.

You could connect an optional second screen in the same way.

Raspberry Pi 1, 2, 3
Connect your screen to the single HDMI port.

34
Note: nothing will display on the screen, because the Raspberry Pi is not running yet.

o If you want to connect the Pi to the internet via Ethernet, use an Ethernet cable to connect
the Ethernet port on the Raspberry Pi to an Ethernet socket on the wall or on your internet
router. You don’t need to do this if you want to use wireless connectivity, or if you don’t
want to connect to the internet.

o If your screen has speakers, your Raspberry Pi can play sound through these. Or you could
connect headphones or speakers to the audio port.

Start up your Raspberry Pi

Your Raspberry Pi doesn’t have a power switch. As soon as you connect it to a power outlet,
it will turn on.

o Plug the power supply into a socket and connect it to your Raspberry Pi’s power port.

35
You should see a red LED light up on the Raspberry Pi, which indicates that Raspberry Pi is
connected to power. As it starts up (this is also called booting), you will see raspberries appear
in the top left-hand corner of your screen.

After a few seconds the Raspberry Pi OS desktop will appear.

Finish the setup


When you start your Raspberry Pi for the first time, the Welcome to Raspberry Pi application
will pop up and guide you through the initial setup.

36
Click Next to start the setup.
Set your Country, Language, and Timezone, then click Next again.

o Enter a new password for your Raspberry Pi and click Next.

37
o Connect to your WiFi network by selecting its name, entering the password, and
clicking Next.

Note: if your Raspberry Pi model doesn’t have wireless connectivity, you won’t see this
screen.

38
o Click Next let the wizard check for updates to Raspbian and install them (this might take a
little while).

o Click Done or Reboot to finish the setup.


Note: you will only need to reboot if that’s necessary to complete an update.

A tour of Raspberry Pi

Now it’s time to take a tour of your Raspberry Pi.


o Do you see the raspberry symbol in the top left-hand corner? That’s where you access the
39
menu: click on it to find lots of applications.
o Click on Accessories, and then click on Text Editor.

o Type I just built a Raspberry Pi computer in the window that appears.

40
o Click on File, then choose Save, and then click on Desktop and save the file as .

o You should see an icon named rp.txt appear on the desktop.

Your file has been saved to your Raspberry Pi’s SD card.


Close the text editor by clicking the X in the top right-hand corner of the window.
Return to the menu, click on Shutdown, and then click on Reboot.
When Raspberry Pi has rebooted, your text file should still be there on the desktop.
Raspberry Pi runs a version of an operating system called Linux (Windows andmacOS
are other operating systems). This operating system allows you to make things happen
by typing in commands instead of clicking on menu options. To try this out, click on the
Terminal symbol at the top of the screen:

41
o In the window that appears, type:

ls
and then press Enter on the keyboard.
You can now see a list of the files and folders in your directory.

o Now type this command to change directory to the Desktop:


cd Desktop

You have to press the Enter key after every command.


Then type:
ls

Can you see the text file you created?


o Close the terminal window by clicking on the X.
o Now drag to the Wastebasket on the desktop so the Raspberry Pi will be tidy for the
next person using it.

42
Browsing the web

You might want to connect your Raspberry Pi to the internet. If you didn’t plug in an ethernet
cable or connect to a WiFi network during the setup, then you can connect now.

o Click the icon with red crosses in the top right-hand corner of the screen, and select your
network from the drop-down menu. You may need to ask an adult which network you
should choose.

o Type in the password for your wireless network, or ask an adult to type it for you, then
click OK.

o When your Pi is connected to the internet, you will see a wireless LAN symbol instead of
the red crosses.

43
o Click the web browser icon and search for .

Configuring your Raspberry Pi


You can control most of your Raspberry Pi’s settings, such as the password, through
the Raspberry Pi Configuration application found in Preferences on the menu.

44
System
In this tab you can change basic system settings of your Raspberry Pi.

Password — set the password of the pi user (it is a good idea to change the password
from the factory default ‘raspberry’)
Boot — select to show the Desktop or CLI (command line interface) when your
Raspberry Pi starts
Auto Login — enabling this option will make the Raspberry Pi automatically log in
whenever it starts

45
Network at Boot — selecting this option will cause your Raspberry Pi to wait until a
network connection is available before starting
Splash Screen — choose whether or not to show the splash (startup) screen when your
Raspberry Pi boots
Interfaces
You can link devices and components to your Raspberry Pi using a lot of different types of
connections. The Interfaces tab is where you turn these different connections on or off, so that
your Raspberry Pi recognises that you’ve linked something to it via a particular type of
connection.

Camera — enable the Raspberry Pi Camera Module


SSH — allow remote access to your Raspberry Pi from another computer using
SSH
VNC — allow remote access to the Raspberry Pi Desktop from another computer
using VNC
SPI — enable the SPI GPIO pins
I2C — enable the I2C GPIO pins
Serial — enable the Serial (Rx, Tx) GPIO pins
1-Wire — enable the 1-Wire GPIO pin.
Remote GPIO — allow access to your Raspberry Pi’s GPIO pins from another
computer
46
Performance
If you need to do so for a particular project you want to work on, you can change the
performance settings of your Raspberry Pi in this tab.
Warning: Changing your Raspberry Pi’s performance settings may result in it behaving
erratically or not working.

Overclock — change the CPU speed and voltage to increase performance

GPU Memory — change the allocation of memory given to the GPU


Localisation

This tab allows you to change your Raspberry Pi settings to be specific to a country or
location.
Locale — set the language, country, and character set used by your Raspberry Pi
47
Timezone — set the time zone
Keyboard — change your keyboard layout
WiFi Country — set the WiFi country code

48
Ex no : INTERFACING OF SENSORS

Date :

Aim :

Using the light sensors, monitor the surrounding light intensity & automatically turn
ON/OFF the high intensity LED's by taking some pre-defined threshold light intensity
value.

Measure the intensity of light in a room using a single photocell and a capacitor connected to
the raspberry pi with a bit of code in python.
What is Photocell?

The Photocell is a light sensor in which the resistance varies according to the intensity of light.
The resistance reduces when it is in brighter surroundings. We have to set up athreshold value
for the measurements of the intensity because it cannot give the precise measurements. If the
measurements are below the threshold then it is dark, else it is bright.
Role of a Capacitor
A Capacitor is an electrical component that can store electrical energy temporarily. It is
measured in Farads which is characterized by capacitance. The capacitor consists of 2
conductors that can hold the electric charge and when it is fully charged the capacitor starts
discharging. This kind of alternative behavior is used to generate AC.

49
When the switch is pressed the current starts flowing and the capacitor starts charging up.
The capacitor stops charging when the voltage at its end reaches the voltage of the battery.
Then as there is no potential difference in the upper half of the circuit, no current flows there.
Things needed
 A Raspberry pi
 1 x breadboard
 A Photocell
 A Resistor
 A Capacitor ( 1 microfarad)
Circuit:

We need to measure the resistance of the photoresistor. The Raspberry pi acts as the battery
whereas the GPIO pin 1 provides 3.3 V to the photoresistor. Make the GPIO pin 12 as the
bidirectional pin ( input and output pin). When the capacitor is charging it will take some
time to reach a voltage that registers as high. GPIO pin 6 is grounded which is connected

50
to the negative side of the capacitor (short end). Check how long it takes for the input pin to
become high and use the result to calculate the resistance of the photocell.

 Insert a photocell in a breadboard.


 Connect the GPIO pin 1 (3.3 V) to the resistor which is connected serial to the
Photocell.
 Connect the other end of the photocell to the GPIO pin 12 and the Capacitor as shown
in the diagram.
 GPIO pin 6 ( ground) is connected to the other end of the capacitor ( short end ).

Code
#measuring the light intensity using a photocell
import RPi.GPIO as GPIO,time,os #import the libraries
DEBUG=1
GPIO.setmode(GPIO.BOARD)

51
GPIO.setwarnings(False)
def RCtime(RCpin): # function start
reading=0
GPIO.setup(RCpin,GPIO.OUT)
GPIO.output(RCpin,GPIO.LOW)
time.sleep(2) # time to discharge capacitor
GPIO.setup(RCpin,GPIO.IN)
while (GPIO.input(RCpin) == GPIO.LOW):
# the loop will run till the capacitor is charged
reading += 1
# measuring time which in turn is measuring resistance
return reading
# function

while True:
print RCtime(12) # calling the function

Output
1. With light:

2. Without light:

52
Result:

Thus the interfacing of sensors is successfully completed successfully.

53
Ex no: COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI USING ANY
WIRELESS MEDIUM
Date :

Aim :
To the Device Attempt to use the device while connecting to a wifi network using a USB
dongle and at the same time providing a wireless access point to the dongle.

Setting up a Raspberry Pi as a routed wireless access point

A Raspberry Pi within an Ethernet network can be used as a wireless access point, creating a
secondary network. The resulting new wireless network is entirely managed by the Raspberry
Pi.

If you wish to extend an existing Ethernet network to wireless clients, consider instead setting
up a bridged access point.

A routed wireless access point can be created using the inbuilt wireless features of the
Raspberry Pi 4, Raspberry Pi 3 or Raspberry Pi Zero W, or by using a suitable USB wireless
dongle that supports access point mode. It is possible that some USB dongles may need slight
changes to their settings. If you are having trouble with a USB wireless dongle, please check
the forums.
This documentation was tested on a Raspberry Pi 3B running a fresh installation of Raspberry

54
Pi OS Buster.
Before we start

 Ensure you have administrative access to your Raspberry Pi. The network setup will be
modified as part of the installation: local access, with screen and keyboard connected
to your Raspberry Pi, is recommended.
 Connect your Raspberry Pi to the Ethernet network and boot the Raspberry Pi OS.
 Ensure the Raspberry Pi OS on your Raspberry Pi is up-to-date and reboot if packages
were installed in the process.
 Take note of the IP configuration of the Ethernet network the Raspberry Pi is connected
to:

o In this document, we assume IP network 10.10.0.0/24 is configured on the

Ethernet LAN, and the Raspberry Pi is going to manage IP

network 192.168.4.0/24 for wireless clients.

o Please select another IP network for wireless, e.g. 192.168.10.0/24 , if IP

network 192.168.4.0/24 is already in use by your Ethernet LAN.

 Have a wireless client (laptop, smartphone, ...) ready to test your new access point.

Install the access point and network management software

In order to work as an access point, the Raspberry Pi needs to have the hostapd access point

software package installed:

sudo apt install hostapd

Enable the wireless access point service and set it to start when your Raspberry Pi boots:

sudo systemctl unmask hostapd


sudo systemctl enable hostapd

In order to provide network management services (DNS, DHCP) to wireless clients, the

Raspberry Pi needs to have the dnsmasq software package installed:

55
sudo apt install dnsmasq

Finally, install netfilter-persistent and its plugin iptables-persistent . This utilty helps by

saving firewall rules and restoring them when the Raspberry Pi boots:
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-
persistent

Software installation is complete.

Set up the network router

The Raspberry Pi will run and manage a standalone wireless network. It will also route between
the wireless and Ethernet networks, providing internet access to wireless clients. If you prefer,
you can choose to skip the routing by skipping the section "Enable routing and IP
masquerading" below, and run the wireless network in complete isolation.

Define the wireless interface IP configuration

The Raspberry Pi runs a DHCP server for the wireless network; this requires static IP

configuration for the wireless interface ( wlan0 ) in the Raspberry Pi. The Raspberry Pi also

acts as the router on the wireless network, and as is customary, we will give it the first IP

address in the network: 192.168.4.1 .

To configure the static IP address, edit the configuration file for dhcpcd with:

sudo nano /etc/dhcpcd.conf


Go to the end of the file and add the following:

interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant

Enable routing and IP masquerading


This section configures the Raspberry Pi to let wireless clients access computers on the main

56
(Ethernet) network, and from there the internet. NOTE: If you wish to block wireless clients
from accessing the Ethernet network and the internet, skip this section.
To enable routing, i.e. to allow traffic to flow from one network to the other in the Raspberry
Pi, create a file using the following command, with the contents below:

sudo nano /etc/sysctl.d/routed-ap.conf

File contents:

# https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md
# Enable IPv4 routing
net.ipv4.ip_forward=1

Enabling routing will allow hosts from network 192.168.4.0/24 to reach the LAN and the

main router towards the internet. In order to allow traffic between clients on this foreign
wireless network and the internet without changing the configuration of the main router, the
Raspberry Pi can substitute the IP address of wireless clients with its own IP address on the
LAN using a "masquerade" firewall rule.
 The main router will see all outgoing traffic from wireless clients as coming from the
Raspberry Pi, allowing communication with the internet.
 The Raspberry Pi will receive all incoming traffic, substitute the IP addresses back, and
forward traffic to the original wireless client.
This process is configured by adding a single firewall rule in the Raspberry Pi:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Now save the current firewall rules for IPv4 (including the rule above) and IPv6 to be loaded

at boot by the netfilter-persistent service:

sudo netfilter-persistent save

Filtering rules are saved to the directory /etc/iptables/ . If in the future you change

configuration of your firewall, make sure to save the configuration before rebooting.

57
Configure the DHCP and DNS services for the wireless network

The DHCP and DNS services are provided by dnsmasq . The default configuration file

serves as a template for all possible configuration options, whereas we only need a few. It is
easier to start from an empty file.
Rename the default configuration file and edit a new one:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

sudo nano /etc/dnsmasq.conf

Add the following to the file and save it:

interface=wlan0 # Listening interface


dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
# Pool of IP addresses served via DHCP
domain=wlan # Local wireless DNS domain
address=/gw.wlan/192.168.4.1
# Alias for this router

The Raspberry Pi will deliver IP addresses between 192.168.4.2 and 192.168.4.20 , with a

lease time of 24 hours, to wireless DHCP clients. You should be able to reach the Raspberry

Pi under the name gw.wlan from wireless clients.

There are many more options for dnsmasq ; see the default configuration file

( /etc/dnsmasq.conf ) or the online documentation for details.

Ensure wireless operation


Countries around the world regulate the use of telecommunication radio frequency bands to
ensure interference-free operation. The Linux OS helps users comply with these rules by

allowing applications to be configured with a two-letter "WiFi country code", e.g. US for a

computer used in the United States.


58
In the Raspberry Pi OS, 5 GHz wireless networking is disabled until a WiFi country code has
been configured by the user, usually as part of the initial installation process (see wireless
configuration pages in this section for details.)
To ensure WiFi radio is not blocked on your Raspberry Pi, execute the following command:

sudo rfkill unblock wlan

This setting will be automatically restored at boot time. We will define an appropriate
country code in the access point software configuration, next.

Configure the access point software

country_code=GB
interface=wlan0
ssid=NameOfNetwork
hw_mode=g channel=7
macaddr_acl=0 auth_algs=1
ignore_broadcast_ssid=0wpa=2
wpa_passphrase=AardvarkBadgerHedgehog
wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP
rsn_pairwise=CCMP
Note the line country_code=GB : it configures the computer to use the correct wireless

frequencies in the United Kingdom. Adapt this line and specify the two-letter ISO code of
your country. See Wikipedia for a list of two-letter ISO 3166-1 country codes.

To use the 5 GHz band, you can change the operations mode

From hw_mode=g hw_mode=a hw_mode


To Possible values for
 a = IEEE 802.11a (5 GHz) (Raspberry Pi 3B+ onwards)
 b = IEEE 802.11b (2.4 GHz)
 g = IEEE 802.11g (2.4 GHz)

Note that when changing the hw_mode , you may need to also change the channel -

see Wikipedia for a list of allowed combinations


Run your new wireless access point
Now restart your Raspberry Pi and verify that the wireless access point becomes
automatically available.

sudo systemctl reboot


59
Once your Raspberry Pi has restarted, search for wireless networks with your wireless client.

The network SSID you specified in file /etc/hostapd/hostapd.conf should now be present,

and it should be accessible with the specified password.


If SSH is enabled on the Raspberry Pi, it should be possible to connect to it from your

wireless client as follows, assuming the pi account is present: ssh [email protected] or ssh

[email protected]

If your wireless client has access to your Raspberry Pi (and the internet, if you set up
routing), congratulations on setting up your new access point!

Result :

Thus the communication using wireless medium is completed successfully

60

You might also like