You are on page 1of 20

Name: Tejas Dhulugade

Roll No.:8427

Practical 2
Aim: Perform LED Glow on Raspberry Pi

Code:
You are now ready to write some code to switch the LED on. Turn on your Pi
and open the terminal window.

Create a new text file “LED.py” by typing the following:

nano LED.py

Type in the following code:

import Rpi.GPIO as GPIO


import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
print “LED on”
GPIO.output(18,GPIO.HIGH)
time.sleep(l)
print “LED off”
GPIO.output(18,GPIO.LOW)

Once you have typed all the code and checked it, save and exit editor with
“Ctrl+x”
then “y” then “enter”.

Running the Code:


To run this code type:

sudo python LED.py


Name: Tejas Dhulugade
Roll No.:8427

Output:
Name: Tejas Dhulugade
Roll No.:8427
Name: Tejas Dhulugade
Roll No.:8427

Practical 3
Aim : Execute linux Commands on Raspberry Pi

1. ls command

2. mkdir command

3. cd command :-

4. rmdir command

Here we are checking that are file properly remove or not

5. If-config command
Name: Tejas Dhulugade
Roll No.:8427
6. Ping command

7. sudo raspi-config

8. sudo apt-get update

9. sudo apt-get upgrade


Name: Tejas Dhulugade
Roll No.:8427

Practical 4
Aim: Controlling Raspberry Pi with Telegram
Code:
Configuration code for Telegram:
Name: Tejas Dhulugade
Roll No.:8427
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip
sudo pip install telepot
clear
mkdir TelegramLEDdemo
cd TelegramLEDdemo

Code for Telegram:

import RPi.GPIO as GPIO


import time
import sys
import telepot
import datetime
import random
from telepot.loop import MessageLoop
def on(pin):
GPIO.output(pin,GPIO.HIGH)
return
def off(pin):
GPIO.output(pin,GPIO.LOW)
return
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
def handle(msg):
chat_id=msg['chat']['id']
command=msg['text']
print('received:%s'% command)
if command == 'ON':
GPIO.output(11,GPIO.HIGH)
elif command == 'OFF':
GPIO.output(11,GPIO.LOW)
bot=telepot.Bot('888312600:AAF0ynJ6tXnIuIux3WdaIvUUyHudFmHksDs')
bot.message_loop(handle)
print("i am listening")

while 1:
time.sleep(1)
Name: Tejas Dhulugade
Roll No.:8427
Running Code:

pi@raspberrypi:~/TelegramLEDdemo $ nano tele.py


pi@raspberrypi:~/TelegramLEDdemo $ sudo python tele.py
i am listening
received:Hii
received:ON
received:OFF

Output:
Name: Tejas Dhulugade
Roll No.:8427
Name: Tejas Dhulugade
Roll No.:8427

Practical 5
Aim: RFID Interface with Raspberry Pi
Code:
RFID Steps:
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config
Select interfacing option and then select spi
Click yes and the ok hence finish
Reboot
lsmod /grep spi
sudo apt-get install python-spidev python3-spidev
cd
pwd *if /home/pi is displayed then we are on correct
path* git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
sudo python setup.py install
clear
cd
pwd
git clone https://github.com /pimylifeup/MFRC522-pythin.git
cd MFRC522-python

🡪nano filename.py
Writing.py
import RPi.GPIO as GPIO
import SimpleMFRC522
reader =SimpleMFRC522.SimpleMFRC522()
try:
text=raw_input(‘enter new data on
card’) print(“now place card”)
reader.write(text)
print(“data written”)
Name: Tejas Dhulugade
Roll No.:8427
finally:
GPIO.cleanup()

Reading.py
import RPi.GPIO as GPIO
import SimpleMFRC522
reader=SimpleMFRC522()
try:
id,text=reader.read()
print(id)
print(text)
finally:
GPIO.cleanup()
Output:
Name: Tejas Dhulugade
Roll No.:8427

Practical 6
Aim : Show Pulse Width Modulation on Raspberry Pi
Code: import RPi.GPIO as GPIO import time

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(19,GPIO.OUT) P
= GPIO.PWM(19,100)
P.start(0) while(1):

for x in range(50):
P.ChangeDutyCycle(x) time.sleep(0.1) for x in
range(50):

P.ChangeDutyCycle(50-x) time.sleep(0.1)

Output :
Name: Tejas Dhulugade
Roll No.:8427

Practical 7
Aim: Show how RPi Camera capture the image
Code:
Create two separate file:

FOR CAPTURING IMAGE-


nano image

CODE-
import pi camera
from time import sleep
cam =picamera.PiCamera()
cam =cam.start preview()
cam.annotate text "Hello World!!!” #displays text on image

cam.hflip=True #flip camera horizontally


True/False
cam.vflip=True #flip camera vertically True/False
sleep(5)
cam.capture(“image1.jpg”) #adding loop to take five
pictures in a row

for in range(5):
sleep(3)
cam.capture( ‘/home/pi/camerademo/pic%s.jpg’ % i)
cam.stop_preview()

RUN THE FILE-


Name: Tejas Dhulugade
Roll No.:8427
sudo python image.py

FOR CAPTURING VIDEO-


nano video

CODE-
import picamera
from time import sleep
cam=picamera.PiCamera()
cam.start_prevlew()
cam.start recording(home/pl/camerademo/fan.h264)
sleep(10)
cam.stop recording()
cam.stop preview()

RUN THE FILE-


sudo python video.py

Output:
Name: Tejas Dhulugade
Roll No.:8427

Practical 8
Name: Tejas Dhulugade
Roll No.:8427

Aim: Convert Raspberry Pi as a Webserver


Code:
Steps:
One of the most popular uses of the Raspberry Pi is as a web
server that lives on
your local network. Whether you need an Intranet for your office
or a small
server for doing web development, the Pi is a great choice. In
fact, at Tom’s
Hardware, we have a local Pi web server that we use to deliver the
content for
our laptop battery test, which involves continuous surfing over
Wi-Fi.
To get your web server working, you’ll need a Raspberry Pi that’s
connected to
your local network and running a fairly-recent version of the
Raspbian operating
system. These instructions will work on just about any
model, including the
powerful Raspberry Pi 4 and diminutive Raspberry Pi Zero
W. If you need to
Name: Tejas Dhulugade
Roll No.:8427
install Raspbian, see our tutorial on how to set up a
Raspberry Pi or, better yet,
how to do a headless install (no keyboard or screen
required).
1. Navigate to the command prompt / terminal. You can get
there by hitting
CTRL+ALT+T from the Raspbian desktop or connecting remotely
via SSH if you
have that configured. Some users also configure the Raspberry Pi
to boot
directly to the command prompt.
2. Update your packages by typing
sudo apt-get update
This will make sure that you get the latest versions of every file
you download
after this.
3. Install apache2 with the command:
sudo apt-get install apache2 -y
4. Install php for your sever by typing:
sudo apt-get install php libapache2-mod-php -y
5. Install mariadb so you can use a mysql database with your
website. You start
Name: Tejas Dhulugade
Roll No.:8427
by typing:
sudo apt-get install mariadb-server
Then, after the download is finished. You must do the formal
install by typing:
sudo mysql_secure_installation
You will be asked for a root password. You can leave it
blank.
6. Install the php-mysql connector so php pages can access the
DB.
sudo apt install php-mysql
7. Restart apache2 so all of the changes are running. sudo
service apache2 restart
8. Test your server. On the Raspberry Pi itself, you should be
able to go to
http://localhost and see a test page. From another computer on the
same
network, you should be able to get there by visiting
http://raspberrypi.local or
http://raspberrypi, provided that your Raspberry Pi's
hostname is raspberrypi.

Practical 9
Name: Tejas Dhulugade
Roll No.:8427
Aim: Show the working of Fingerprint module on Raspberry Pi

Connection :

Code : It will Automatically generate when you will install fingerprint module

Output :
Name: Tejas Dhulugade
Roll No.:8427

You might also like