Date: Raspberry Pi
Date: Raspberry Pi
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.
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
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
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 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.
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.
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.
36
Click Next to start the setup.
Set your Country, Language, and Timezone, then click Next again.
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).
A tour of Raspberry Pi
40
o Click on File, then choose Save, and then click on Desktop and save the file as .
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.
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 .
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.
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.
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:
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.
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:
Have a wireless client (laptop, smartphone, ...) ready to test your new access point.
In order to work as an access point, the Raspberry Pi needs to have the hostapd access point
Enable the wireless access point service and set it to start when your Raspberry Pi boots:
In order to provide network management services (DNS, DHCP) to wireless clients, the
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
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.
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
To configure the static IP address, edit the configuration file for dhcpcd with:
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
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:
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:
Now save the current firewall rules for IPv4 (including the rule above) and IPv6 to be loaded
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:
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
There are many more options for dnsmasq ; see the default configuration file
allowing applications to be configured with a two-letter "WiFi country code", e.g. US for a
This setting will be automatically restored at boot time. We will define an appropriate
country code in the access point software configuration, next.
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
Note that when changing the hw_mode , you may need to also change the channel -
The network SSID you specified in file /etc/hostapd/hostapd.conf should now be present,
wireless client as follows, assuming the pi account is present: ssh [email protected] or ssh
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 :
60