0% found this document useful (0 votes)
68 views61 pages

RaspberryPi Manual

The Embedded Linux Lab Manual outlines the general instructions, vision and mission of the institution and department, program outcomes, educational objectives, and specific outcomes related to the Embedded Linux course. It includes detailed course objectives and outcomes, as well as a list of experiments to be conducted in the lab, focusing on practical applications of embedded systems and IoT technologies. The manual emphasizes punctuality, preparation, and individual work ethics for students in the lab environment.

Uploaded by

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

RaspberryPi Manual

The Embedded Linux Lab Manual outlines the general instructions, vision and mission of the institution and department, program outcomes, educational objectives, and specific outcomes related to the Embedded Linux course. It includes detailed course objectives and outcomes, as well as a list of experiments to be conducted in the lab, focusing on practical applications of embedded systems and IoT technologies. The manual emphasizes punctuality, preparation, and individual work ethics for students in the lab environment.

Uploaded by

vikas malhotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Department

of
Electronic Communication Engineering

EMBEDDED L I N U X
LAB
(23EC364)

Prepared
by

Dr. Vikas Malhotra (Assist .Prof)

Embedded Linux Lab Manual Page 1


INDEX

S. No Content Page No

1 General Instructions

2 Institute Vision and Mission

3 Department Vision and Mission

4 Programme Outcomes

5 Programme Educational Objectives

6 Programme Specific Outcomes

7 Course Objectives and Outcomes

8 Course Syllabus

9 Course Experiments

10

11

Embedded Linux Lab Manual Page 2


GENERAL INSTRUCTIONS

 Students are instructed to come to Embedded Linux laboratory on time. Late comers
are not entertained in the lab.
 Students should be punctual to the lab. If not, the conducted experiments will not be
repeated.
 Students are expected to come prepared at home with the experiments which are going to
be performed.
 Students are instructed to display their identity cards before entering into the lab.
 Students are instructed not to bring mobile phones to the lab.
 Any damage/loss of system parts like keyboard, mouse during the lab session, it is
student’s responsibility and penalty or fine will be collected from the student.
 Students should update the records and lab observation books session wise. Before leaving
the lab the student should get his lab observation book signed by the faculty.
 Students should submit the lab records by the next lab to the concerned faculty members
in the staffroom for their correction and return.
 Students should not move around the lab during the lab session.
 If any emergency arises, the student should take the permission from faculty member
concernedin written format.
 The faculty members may suspend any student from the lab session on disciplinary
grounds.
 Never copy the output from other students. Write down your own outputs

Embedded Linux Lab Manual Page 3


INSTITUTION VISION AND MISSION

Vision:

To be as an ideal academic institution by graduating talented engineers to be ethically strong,

competent with quality research and technologies.

Mission:

 Utilize rigorous educational experiences to produce talented engineers

 Create an atmosphere that facilitates the success of students

 Programs that integrate global awareness, communication skills and Leadership

qualities

 Education and Research partnership with institutions and industries to prepare

the students for interdisciplinary research

Embedded Linux Lab Manual Page 4


DEPARTMENT VISION AND MISSION

Vision:
To empower the students to be technologically adept, innovative, self-motivated and
responsible global citizen possessing human values and contribute significantly towards
high quality technical education with ever changing world.

Mission:

 To offer high-quality education in the computing fields by providing an environment


where the knowledge is gained and applied to participate in research, for both students
and faculty.
 To develop the problem solving skills in the students to be ready to deal with cutting
edge technologies of the industry.
 To make the students and faculty excel in their professional fields by inculcating the
communication skills, leadership skills, team building skills with the organization of
various co-curricular and extra-curricular programmes.
 To provide the students with theoretical and applied knowledge, and adopt an
education approach that promotes lifelong learning and ethical growth.

Embedded Linux Lab Manual Page 5


PROGRAM OUTCOMES
PO Graduate
Name PO Statements
Attributes
Apply the knowledge of mathematics, science, engineering fundamentals,
Engineering
PO1 and an engineering specialization to the solution of complex engineering
knowledge
problems
Identify, formulate, review research literature, and analyze complex
PO 2 Problem analysis engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
Design solutions for complex engineering problems and design system
Design/
components or processes that meet the specified needs with appropriate
PO 3 development of
consideration for the public health and safety, and the cultural, societal, and
solutions
environmental considerations.
Conduct
Use research-based knowledge and research methods including design of
investigations of
PO 4 experiments, analysis and interpretation of data, and synthesis of the
complex
information to provide valid conclusions
problems
Create, select, and apply appropriate techniques, resources, and modern
Modern tool
PO 5 engineering and IT tools including prediction and modeling to complex
usage
engineering activities with an understanding of the limitations.
Apply reasoning informed by the contextual knowledge to assess societal,
The engineer and
PO 6 health, safety, legal and cultural issues and the consequent responsibilities
society
relevant to the professional engineering practice.
Understand the impact of the professional engineering solutions in societal
Environment and
PO 7 and environmental contexts, and demonstrate the knowledge of, and need
sustainability
for sustainable development.
Apply ethical principles and commit to professional ethics and
PO 8 Ethics
responsibilities and norms of the engineering practice.
Individual and Function effectively as an individual, and as a member or leader in diverse
PO 9 teams, and in multidisciplinary settings.
team work

Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to
PO 10 Communication
comprehend and write effective reports and design documentation, make
effective presentations, and give and receive clear instructions.

Demonstrate knowledge and understanding of the engineering and


Project
management principles and apply these to one’s own work, as a member
PO 11 management and
and leader in a team, to manage projects and in multidisciplinary
finance
environments.
Recognize the need for, and have the preparation and ability to engage in
PO 12 Life-long learning independent and life-long learning in the broadest context of technological
change.

Embedded Linux Lab Manual Page 6


PROGRAM EDUCATIONAL OBJECTIVES

Sl. No. PEOs Name Program Education Objective Statements

Professional career: Establish a successful professional


1 PEO - 1 career in industry, government or academia

Higher studies or R & D: gain multidisciplinary knowledge


2 PEO – 2 providing a sustainable competitive edge in higher studies or
Research and Development

Entrepreneurial: promote design, research, and


implementation of products and services through strong
3 PEO – 3
communication, leadership and ethical skills, to be an
entrepreneurial

Embedded Linux Lab Manual Page 7


PROGRAM SPECIFIC OUTCOMES

Sl. No. PEOs Name Program Specific Outcomes

Applications of Computing: Ability to use knowledge


1 PSO - 1 in various domains to provide solution to new ideas and
innovations.
Programming Skills: Identify required data structures,
2 PSO – 2 design suitable algorithms, develop and maintain
software for real world problems.

Embedded Linux Lab Manual Page 8


COURSE OBJECTIVE

CO Course Objective
1 To introduce the terminology, technology and its applications

2 To introduce the concept of M2M (machine to machine) with necessary protocols

3 To introduce the Python Scripting Language which is used in many IoT devices

4 To introduce the Raspberry PI platform, that is widely used in IoT applications

5 To introduce the implementation of web-based services on IoT devices

Embedded Linux Lab Manual Page 9


COURSE OUTCOMES

CO Course Outcomes

CO 1 Understand the design, characteristics and technologies of Internet of Things

CO 2 Interpret the impact and challenges posed by IoT networks leading to new architectural
models.
CO 3 Compare and contrast the deployment of smart objects and the technologies to connect them
to network.
CO 4 Appraise the role of IoT protocols for efficient network communication

CO 5 Elaborate the need for Data Analytics and Security in IoT.

CO 6 Illustrate different sensor technologies for sensing real world entities and identify the
applications of IoT in Industry

COPO Mapping:
a B c d e f g h i j k l 1 2

√ √
CO 1
CO 2 √ √

CO 3 √ √ √

CO 4 √ √

CO 5 √ √

CO 6 √ √ √ √

Embedded Linux Lab Manual Page 10


EMBEDDED SYSTEMS & INTERNET OF THINGS LAB
(IT605PC)

1. Functional Testing Of Devices


Flashing the OS on to the device into a stable functional state by porting desktop environment
with necessary packages.

2. Exporting Display On To Other Systems


Making use of available laptop/desktop displays as a display for the device using SSH client
& X11 display server.

3. GPIO Programming
Programming of available GPIO pins of the corresponding device using native programming
language. Interfacing of I/O devices like LED/Switch etc., and testing the functionality.

4. Interfacing Chronos eZ430


Chronos device is a programmable texas instruments watch which can be used for multiple
purposes like PPT control, Mouse operations etc., Exploit the features of the device by
interfacing with devices.

5. ON/OFF Control Based On Light Intensity


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.

6. Battery Voltage Range Indicator


Monitor the voltage level of the battery and indicating the same using multiple LED's (for ex:
for 3V battery and 3 led's, turn on 3 led's for 2-3V, 2 led's for 1-2V, 1 led for 0.1-1V & turn
off all for 0V)

7. Dice Game Simulation


Instead of using the conventional dice, generate a random value similar to dice value and
display the same using a 16X2 LCD. A possible extension could be to provide the user with
option of selecting single or double dice game.

8. Displaying RSS News Feed On Display Interface


Displaying the RSS news feed headlines on a LCD display connected to device. This can be
adapted to other websites like twitter or other information websites. Python can be used to
acquire data from the internet.

9. Porting Openwrt 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.

Embedded Linux Lab Manual Page 11


10. Hosting a website on Board
Building and hosting a simple website(static/dynamic) on the device and make it accessible
online. There is a need to install server(eg: Apache) and thereby host the website.

11. Webcam Server


Interfacing the regular usb webcam with the device and turn it into fully functional IP
webcam & test the functionality.

12. FM Transmission
Transforming the device into a regular fm transmitter capable of transmitting audio at desired
frequency (generally 88-108 Mhz)

Note: Devices mentioned in the above lists include Arduino, Raspbery Pi, Beaglebone

Embedded Linux Lab Manual Page 12


Experiment - 1
Raspberry Pi OS installation and Configuration

Installing the OS on to the device into a stable functional state by


porting desktop environment with necessary packages.

Raspberry Pi
You are going to take a first look at Raspberry Pi! You should have a Raspberry Pi computer
in 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.

Embedded Linux Lab Manual Page 13


 HDMI port — this is where you connect the monitor (or projector) that you are using
to display the output from the Raspberry Pi. If your monitor has speakers, you can also
use 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 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 have
one.
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

Embedded Linux Lab Manual Page 14


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:

Embedded Linux Lab Manual Page 15


 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.

Embedded Linux Lab Manual Page 16


Embedded Linux Lab Manual Page 17
 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).

Embedded Linux Lab Manual Page 18


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.

Embedded Linux Lab Manual Page 19


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.

Embedded Linux Lab Manual Page 20


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.

Embedded Linux Lab Manual Page 21


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.

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.

Embedded Linux Lab Manual Page 22


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.

 Click Next to start the setup.


 Set your Country, Language, and Timezone, then click Next again.

Embedded Linux Lab Manual Page 23


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

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

Embedded Linux Lab Manual Page 24


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

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.

Embedded Linux Lab Manual Page 25


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
menu: click on it to find lots of applications.
o Click on Accessories, and then click on Text Editor.

Embedded Linux Lab Manual Page 26


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

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.

Embedded Linux Lab Manual Page 27


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 and
macOS 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:

o In the window that appears, type:

Embedded Linux Lab Manual Page 28


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.

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.

Embedded Linux Lab Manual Page 29


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.

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.

Embedded Linux Lab Manual Page 30


Embedded Linux Lab Manual Page 31
 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

Embedded Linux Lab Manual Page 32


 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

Embedded Linux Lab Manual Page 33


 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

Embedded Linux Lab Manual Page 34


 Timezone — set the time zone
 Keyboard — change your keyboard layout
 WiFi Country — set the WiFi country code

Embedded Linux Lab Manual Page 35


Experiment - 2
LED and switch interfacing with RaspberryPi

Interfacing Push button and LED with Raspberry Pi is very simple. In this project It
will be given that how to interface push button switch with Raspberry Pi 4B and also
connect one LED so that when button is pressed, LED will turn ON and on button
release it will turns OFF..

Components Required
Following components are required to interface switch and LED:
 Connecting wires
 220Ω or 1 KΩ Resistor
 LED
 Bread Board
 Switch
 RaspberryPi
 Power supply Adaptor for RaspberryPi

Circuit Diagram:

Instructions: Make sure that the RPi.GPIO library installed if not, install it by executing
following commands:
 sudo apt-get update
 sudo apt-get install python3-rpi.gpio

Steps:
1. On the desktop, go the Start Menu and choose for the PYTHON 3, as shown in figure

Embedded Linux Lab Manual Page 36


below.

2. After that, PYHON will run and you will see a window as shown in below figure.

Embedded Linux Lab Manual Page 37


3. After that, click on New File in File Menu, You will see a new Window open,

4. Save this file as led_switch on the desktop,

Embedded Linux Lab Manual Page 38


5. After that write the program for led_switch 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 will blink when switch is being pressed. If
there were any errors in the program, the execution tells to correct it. Once the error is
corrected execute the program again.

Embedded Linux Lab Manual Page 39


Program:

import RPi.GPIO as GPIO

BUTTON_PIN = 16 # The number of the pushbutton pin


LED_PIN = 18 # The number of the LED pin

# Variables will change:


button_state = 0 # Variable for reading the pushbutton status

# Set up GPIO
GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbering
GPIO.setup(LED_PIN, GPIO.OUT) # Initialize the LED pin as an output
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

try:
while True:
# Read the state of the pushbutton value:
button_state = GPIO.input(BUTTON_PIN)

# Control LED according to the state of the button


if button_state == GPIO.LOW: # If the button is pressed
GPIO.output(LED_PIN, GPIO.HIGH) # Turn on LED
else: # Otherwise, the button is not pressed
GPIO.output(LED_PIN, GPIO.LOW) # Turn off LED

except KeyboardInterrupt:
# Clean up GPIO on program exit
GPIO.cleanup()

Embedded Linux Lab Manual Page 40


Experiment – 3
Temperature sensor interfacing with RaspberryPi.
Using the Temperature sensor, temperature of surrounding can be measured. In
this experiment, DHT11 temperature sensor will be interfaced with RaspberryPi
and value of temperature as well as humidity can be measured with the DHT11
sensor.

Components Required
Following components are required to interface switch and LED:
 Connecting wires
 DHT sensor
 Raspberry Pi
 Power supply Adaptor for RaspberryPi

Raspberry Pi is known for its computational power and its vast application in the field
of IoT, Home Automation etc. However, for any electronic system to interact with the real
world and get information about it, the system has to use sensors. There are many types of
sensors used for this process and the required sensor is selected based on the parameter to be
measured and its application. In this experiment, interfacing a temperature sensor DHT11 with
the Raspberry Pi will be performed.

DHT11 Sensor: DHT11 sensor measures and provides humidity and temperature values
serially over a single wire.

 It can measure relative humidity in percentage (20 to 90% RH) and temperature in
degree Celsius in the range of 0 to 50°C.

 It has 4 pins; one of which is used for data communication in serial form.

 Pulses of different TON and TOFF are decoded as logic 1 or logic 0 or start
pulse or end of a frame.

DHT11 Sensor
Embedded Linux Lab Manual Page 41
Instructions: Install and update the necessary file by running following commands:

 sudo apt update

 sudo apt install python3-pip

 sudo pip3 install --upgrade setuptools

 Now install the DHT Sensor Pyhton Library:

 sudo pip3 install Adafruit_DHT

Circuit Diagram :

DHT11 Interfacing with Raspberry Pi

Python script:

import Adafruit_DHT
import time
DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4

Embedded Linux Lab Manual Page 42


while True:
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity))
else:
print("Sensor failure. Check wiring.");
time.sleep(2);

Embedded Linux Lab Manual Page 43


\

Experiment - 4
Relay interfacing with Raspberry Pi

Using the relay, any device can be switched on or switch off with the help og
programming. In this experiment, DC motor will be turned on and off with yhe
help of relay.

Components Required
Following components are required to interface switch and LED:
 Connecting wires
 Relay
 DC Motor
 RaspberryPi
 Power supply for Relay
 Power supply Adaptor for RaspberryPi

Relay: A relay is an electromagnetic switch that can turn on and off DC as well as AC
devices.
The electromagnet gets power from the Raspberry Pi to either activate or deactivate a
(potentially) high-voltage circuit.
OR
A Relay is electromechanical device, it is used as a switch to establish electrical
connection.
• The numbers of Switches inside a relay are called the poles of the relay.
• The number of circuits being controlled per pole is called the throw of a relay.

Types of relays: There are various types of relays are based on the numbers of poles
and throw inside a relay.
1) SPST refers to single pole single throw relay.

Embedded Linux Lab Manual Page 44


2) SPDT refers to single pole double throw relay.

3) DPST refers to double pole single throw.

4) DPDT refers to double pole double throw.

Working: It works on the principle of an electromagnetic attraction. When the circuit of the
relay senses the fault current, it energizes the electromagnetic field which produces the
temporary magnetic field. This magnetic field moves the relay armature for opening or closing
the connections.

Embedded Linux Lab Manual Page 45


Circuit Diagram:

Pythan Script :

import time
import RPi.GPIO as GPIO
relay_ch = 26
GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM)
GPIO.setup(relay_ch, GPIO.OUT)
GPIO.output(relay_ch, GPIO.LOW)
time.sleep(1)
GPIO.output(relay_ch, GPIO.HIGH)
GPIO.cleanup()

Embedded Linux Lab Manual Page 46


Experiment - 5
LCD interfacing with Raspberry Pi
LCD is the most commonly used part when you are doing electronics projects with
Raspberry pi. It will help you whenever you will want to display the data. So, in
this post you are going to learn Interfacing 16×2 LCD with Raspberry Pi. We will
use the 16X2 LCD to display the data on it. You may be wondering that what does
this 16X2 means. This means that LCD has 16 columns and 2 rows. Other LCD’s
with 16X1 and 16X4 displays are also available. Each character of LCD consists of
5X10 i.e. 50 pixels.

Pin detail of 16x2 LCD:


• Pin1 (Ground): This pin connects the ground terminal.
• Pin2 (+5 Volt): This pin provides a +5V supply to the LCD
• Pin3 (VE): This pin selects the contrast of the LCD.
• Pin4 (Register Select): This pin is used to connect a data pin of an
MCU & gets either 1 or 0. Here, data mode = 0 and command mode
=1.
• Pin5 (Read & Write): This pin is used to read/write data.
• Pin6 (Enable): This enables the pin must be high to perform the
Read/Write procedure. This pin is connected to the data pin of the
microcontroller to be held high constantly.
• Pin7 (Data Pin): The data pins are from 0-7 which are connected
through the microcontroller for data transmission. The LCD module
can also work on the 4-bit mode through working on pins 1, 2, 3 &
other pins are free.
• Pin8 – Data Pin 1
• Pin9 – Data Pin 2
• Pin10 – Data Pin 3
• Pin11 – Data Pin 4
• Pin12 – Data Pin 5
• Pin13 – Data Pin 6
• Pin14 – Data Pin 7
• Pin15 (LED Positive): This is a +Ve terminal of the backlight LED of
the display & it is connected to +5V to activate the LED backlight.
Embedded Linux Lab Manual Page 47
• Pin16 (LED Negative): This is a -Ve terminal of a backlight LED of
the display & it is connected to the GND terminal to activate the LED
backlight.

LCD timing diagram:

Material Required
 RaspberryPi
 LCD (16*2)
 Potentiometer-10k
 Resistor (100ohm-10;330ohm)
 Connecting wires
 Power supply Adaptor for RaspberryPi

Embedded Linux Lab Manual Page 48


To interface the LCD with Raspberry Pi we need to install these commands to enable the
various interfaces such as I2C and SPI:
 sudo raspi-config nonint do_i2c 0
 sudo raspi-config nonint do_spi 0
 sudo raspi-config nonint do_serial_hw 0
 sudo raspi-config nonint do_ssh 0
 sudo raspi-config nonint do_camera 0
 sudo raspi-config nonint disable_raspi_config_at_boot 0

Install Blinka and Dependencies


 sudo apt-get install -y i2c-tools libgpiod-dev python3-libgpiod
 pip3 install --upgrade RPi.GPIO
 pip3 install adafruit-blinka
 pip3 install --upgrade adafruit-blinka
 sudo pip3 install adafruit-circuitpython-charlcd

Circuit Diagram Connection:

Embedded Linux Lab Manual Page 49


Raspberry Pi to 16X2 LCD Pin Connections
Raspberry Pi Pins LCD Pins

GPIO26 RS

GPIO19 EN

GPIO25 D4

GPIO24 D5

GPIO 22 D6

GPIO27 D7

Python Script:

import time
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2

Embedded Linux Lab Manual Page 50


# R aspberry Pi Pin Config:
lcd_rs = digitalio.DigitalInOut(board.D26)
lcd_en = digitalio.DigitalInOut(board.D19)
lcd_d7 = digitalio.DigitalInOut(board.D27)
lcd_d6 = digitalio.DigitalInOut(board.D22)
lcd_d5 = digitalio.DigitalInOut(board.D24)
lcd_d4 = digitalio.DigitalInOut(board.D25)
lcd_backlight = digitalio.DigitalInOut(board.D4)
# Initialise the lcd class
lcd = characterlcd.Character_LCD_Mono( lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,
lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
lcd.cursor_position(0, 0) # coloumn,row
lcd.message = “Chitkara“
lcd.cursor_position(0, 1)# coloumn,row
lcd.message = “University“
time.sleep(5)
lcd.clear()

Embedded Linux Lab Manual Page 51


Experiment - 6
Stepper motor interfacing with RaspberryPi

Stepper motor: A stepper motor is an electric motor whose main feature is that its
shaft rotates by performing steps, that is, by moving by a fixed number of
degrees. In this experiment, stepper motor will be run in both directions,
clockwise and anticlockwise.

Snapshot of different stepper Motor Cross-section of a stepper motor

Stepper motor working principle: The stepper motor working principle is Electro-
Magnetism. It includes a rotor which is made with a permanent magnet whereas a
stator is with electromagnets. Once the supply is provided to the winding of the stator
then the magnetic field will be developed within the stator. Now rotor in the motor will
start to move with the rotating magnetic field of the stator. So this is the fundamental
working principle of this motor.

Embedded Linux Lab Manual Page 52


Types of stepper motor:

Unipolar: The current always flows in the same direction. Each coil is dedicated to
one current direction, meaning either the coil A+ or the coil A- is powered. The coils
A+ and A- are never powered together.

Bipolar: The current can flow in both directions in all coils. The phases A+ and A-
are powered together.

Components Required
Following components are required to interface switch and LED:
 Connecting wires
 Stepper Motor
 ULN 2003 motor driver module
 Power supply Adaptor for ULN2003 module
 RaspberryPi
 Power supply Adaptor for RaspberryPi

Embedded Linux Lab Manual Page 53


import RPi.GPIO as GPIO
from time import sleep
#assign GPIO pins for motor
motor_channel = (29,31,33,35)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
#for defining more than 1 GPIO channel as input/output use
GPIO.setup(motor_channel, GPIO.OUT)
#Instructions for rotate stepper motor in anti-clockwise direction:
while True:
print('motor running clockwise\n')
GPIO.output(motor_channel,(GPIO.HIGH,GPIO.LOW,GPIO.LOW,GPIO.HIGH))
sleep(0.02)
GPIO.output(motor_channel,(GPIO.HIGH,GPIO.HIGH,GPIO.LOW,GPIO.LOW))
sleep(0.02) GPIO.output(motor_channel,
(GPIO.LOW,GPIO.HIGH,GPIO.HIGH,GPIO.LOW))
sleep(0.02)

Embedded Linux Lab Manual Page 54


GPIO.output(motor_channel, (GPIO.LOW,GPIO.LOW,GPIO.HIGH,GPIO.HIGH))
sleep(0.02)
#Instructions for rotate stepper motor in anti-clockwise direction:
while True:
print('motor running anti-clockwise\n')
GPIO.output(motor_channel, (GPIO.HIGH,GPIO.LOW,GPIO.LOW,GPIO.HIGH))
sleep(0.02)
GPIO.output(motor_channel, (GPIO.LOW,GPIO.LOW,GPIO.HIGH,GPIO.HIGH))
sleep(0.02)
GPIO.output(motor_channel,(GPIO.LOW,GPIO.HIGH,GPIO.HIGH,GPIO.LOW))
sleep(0.02)
GPIO.output(motor_channel,(GPIO.HIGH,GPIO.HIGH,GPIO.LOW,GPIO.LOW))
sleep(0.02)

Embedded Linux Lab Manual Page 55


Embedded Linux Lab Manual Page 56
Experiment - 7

Ultrasonic sensor interfacing with RaspberryPi

An ultrasonic sensor is just a device that converts electrical energy into sound waves

(ultrasound) that we can't hear, usually above 20 kHz. It tracks how long it takes for

those sound waves to strike an object and then bounce back to the sensor. This "echo"

helps the sensor determine how far away something is with pretty good precision. In

this experiment, the ultrasonic sensor will be used to detect distance of an object.

Ultrasonic Sensor HC-SR04: This sensor is used to measure distance. It emits


an ultrasound wave of frequency 40 000 Hz (40kHz) at a speed of 340 m/s or 0.034
cm/µs

.
Ultrasonic Sensor
The working principle of an ultrasonic sensor revolves around the emission and reception of
high-frequency sound waves. These waves range from 20 kHz which is beyond the range of human
hearing. Here's a simplified explanation of ultrasonic sensor operation:

Embedded Linux Lab Manual Page 57


Working steps of ultrasonic sensor

 Emitting Sound Waves: The ultrasonic sensor generates a burst of ultrasonic sound waves,
usually in the range of 20 kHz to 65 kHz. These sound waves travel through the air towards the
target object.
 Bouncing Off Objects: When the sound waves encounter an object in their path, they bounce
off the surface of the object.
 Measuring the Return Time: The sensor measures the time it takes for the emitted sound
waves to bounce back after hitting the object. This time interval is extremely short, typically
measured in microseconds.
 Calculating Distance: The sensor figures out how far an object is by using the speed of sound
in the air. It does this by multiplying the time it takes for sound waves to go to the object and
then coming back by the speed of sound.
 Output Data: Last, the sensor provides this distance information as an output, which can be
used in various applications, such as obstacle detection, object positioning, or navigation.

The HC-SR04 ultrasonic sensor measures distance by sending out an ultrasonic pulse and
measuring the time it takes to reflect back. The basic formula used:

Woking of Ultrasonic sensor

To build this project you will need:

 Raspberry Pi
 Ultrasonic sensor HC-SR04
 Jumper wires or connecting wires (male-to-female)
 1 × 1kΩ resistor
 1 × 2kΩ resistor (for voltage divider to protect Pi GPIO)

Embedded Linux Lab Manual Page 58


⚠️The Echo pin outputs 5V, but Raspberry Pi GPIO pins are 3.3V tolerant. Use a voltage divider
(330Ω + 470Ω) before connecting to Pi.

Embedded Linux Lab Manual Page 59


Embedded Linux Lab Manual Page 60
Python Script:

import RPi.GPIO as GPIO


import time
#GPIO Mode (BOARD / BCM)
GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER = 16
GPIO_ECHO = 18
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
def distance():
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
StartTime = time.time()
StopTime = time.time()

Embedded Linux Lab Manual Page 61

You might also like