0 valutazioni Il 0% ha trovato utile questo documento (0 voti) 3 visualizzazioni 25 pagine IoT File
Il documento fornisce una panoramica di vari comandi Linux e programmi Python eseguiti su Raspberry Pi. Viene descritto l'uso di comandi come 'ls', 'mkdir', 'rm', e 'ping', insieme a diversi esperimenti Python per calcolare operazioni matematiche, gestire stringhe e interagire con l'LCD. Ogni esperimento include il codice sorgente e l'output previsto.
Titolo e descrizione migliorati con IA
Copyright
© All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo,
rivendicalo qui .
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
Go to previous items Go to next items
Name
# 2
at Hells
3 wn 2glee Seis
Jona! psi
berend deol Mee ee
fe eT ana Blahs
c Lt? fete prjet a 4h
Vpnnf Rivets vaing
Ez pe Handle Siviaiblel Ma T>4
; by Zep ~
4S 212 4)
Q ~ [wart din onto | F124)
im LCD Acredn, a
1 ne tp neod o file |) 2h ¥
Dead niet wend,
. I tz 11 214
LL we ty ight On EY ty eS
12 woes (re Tus put ais x Z
p Avsitoh. bez
13 WAP that covtyole ann | 613 [><
RGB LED and ditplay
Levens L¥iple colors.
1M |wAe ta welerface a clzloe
CPrarcaten Aavtite I=Sepuctnt}
oliapadody
il Sh air Experiment -1
en
: ‘Start Raspberry Pi and try various Linix commands in command terminal window: Is, ed,
‘touch, my, rm, man, mkdir, rmdir, tar, gzip, cat, more, less, ps, sudo, cron, chown, chgrp, ping etc,
Linux Commands:
1. Is: It lists directory contents of files and directories.
* Display All Information About Files/Directories Using $ Is -1
‘* Open Last Edited File Using Is -t
* Display File Size in Human Readable Format Using Is—th
2. ed: ed command in linux known as change directory command. It is used to change current
working directory.
‘Syntax:
+ Sed [directory]
ed /: this command is used to change directory to the root directory
© ed dir_1/dir_2/dir_3: This command is used to move inside a directory from a
directory
ed .. : this command is used to move to the parent directory of current directory, or
the directory one level up from the current directory.
ed “dir name”: This command is used to navigate to a directory with white spaces,
3. touch: Used to create, change and modify timestamps of a file. It is used to create a file without
any content.
Syntax to create a new file: touch file_name
Syntax to create multiple files: touch File!_nare File2_name File3-name
4. my: my stands for move. mv is used to move one or more files or directories from one place to
another in file system. a
Ithas two distinct functions:
© Itrename a file or folder.
* Itmoves group of files to different directory.
Syntax: my [Option] source destinationINSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur a
” Name: Abhishek Parihar | Class; BTech-CSE (VII Sem) | Subject: JOT Lab
S. rm: rm stands for remove here. rm command is used to remove objects such as files, directories,
symbolic links and so on from the file system,
‘Syntax: mm [OPTION]... FILE...
6. man: man command in Linux is used to display the user manual of any command
Syntax: $man [OPTION]... [COMMAND NAME]...
inux allows the user to create directories
7. mkdir: mkdir command in
Syntax: $man [OPTION]... [COMMAND NAME]...
8. rmdir: rmdir command in Linux allows the user to create directories
Syntax: rmdir [-p] [-v | -verbose] [-ignore-fail-on-non-empty] directories ...
9. tar: The Linux ‘tar’ stands for tape archive, is used to create Archive and extract the Archive files,
Syntax: tar [options] [archive-file] [file or directory to be archived]
10. gzip: gzip command compresses files.
Syntax: gzip [Options] [filenames]
Example: $ gzip [Link]]
1. eat: It reads data from the file and gives their content as output-Tt helps us to create, view,
concatenate files.
: Scat filename
Comman:
12, more: more command is used to view the text files in the command prompt, displaying one
screen at a time in case the file is large (For example log files). The more command also allows the
user do scroll up and down through the page.
Syntax:
more [-options] [-num] [#/pattern] [Hlinenum] [file_name]
‘© [options]: any option that you want to use in order to change the way the file isE OF ENGINEERING AND NOLOGY
Mohanlal Sukhadia University, Udaipur
am Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: 101
Se INSTIT’
fe -Pe-€, = 8 -U)
splay per screen. «[ +/pattern}
displayed. Choose any one from the followings: (-
© E-num): type the number of lines that you want to
replace the pattern with any string that you want to find in the text file.
[Hinenum): use the line number from where you want to start displaying the text
content.
[file_name]: name of the file containing the text that you want to display on the
screen.
13. Less: less command is linux utility which can be used to read contents of text file one page (one
screen) per time. It has faster access because if file is large, it don’t access complete file, but access it
page by page.
Syntax: less filename
14. ps: ps for viewing information related with the processes on a system which stands
as abbreviation for “Process Status”
Syntax: ps [options]
15. sudo: sudo (Super User DO) command in Linux is generally used as a prefix of some command
that only superuser are allowed to run.
n process, which runs
16. cron: automates the scheduled task at a predetermined time. It is a
as a background process.
Syntax: cron [-] [-I] [-L loglevel]
Change the file Owner or group. Whenever you want to
17. chown: chown command is used
change ownership you can use chown command.
Syntax:
[OWNER][: (GROUP]] FILE...
chown [OPTION]... -reference=RFILE FILE...
18, chgrp: cherp command in Linux is used to change the group ownership of a file or
directory.
Syntax:
© Chgrp [OPTION]... GROUP FILE...sh oTTT TR e ENG
a INSTITUTE OF ENGINEERING AND TECHNOLOGY
E Mohanlal Sukhadia University, Udaipur
* Name: Abhishek Parihar | Class: BTec! VII Sem) | Subject: JOT Lab
© chgrp [OPTION]... -Feference=RFILE FILE...
19. ping: PING (Packet Internet Groper) command is used to check the network connectivity
between host and server/host.
20. chmod: the chmod command is used to change the access mode of a file,
The name is an abbreviation of change mode.
Syntax: chmod [reference] operator][mode] file
21. curl: curl is a command line tool to transfer data to or from a server, using any of the supported
protocols,
Syntax: curl {options} [URL...]
22. echo: echo command in linux is used to display line of text/string that are passed as an argument.
‘Syntax: echo [option] [string]
23. exit: exit command in linux is used to exit the shell where itis currently running, It takes one
more parameter as [N] and exits the shell with a return of status N.
‘Syntax: exit [n]
24, find: It can be used to find files and directories and perform subséquent operations on them. It
supports searching by file, folder, name, creation date, modificatjén date, owner and permissions.
Syntax: $ find [where to start searching from]
[expression determines what to find] [-options) what to find]
{ip command which gives details of all the users
25, Finger: command is « user information |
logged in.
Syntax: $finger{username]INSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: OT Lab
26. Free: command which displays the total amount of free space available along with the amount of
memory used and swap memory in the system, and also the buffers used by the kernel.
Syntax: $free [OPTION]
27. Grep: The grep filter searches a file for a particular pattern of characters, and displays all lines
that contain that pattern,
‘Syntax: grep [options] pattern [files]
28. Kill: command in Linux (located in /bin kill), is
processes manually. kill command sends a signa
t-in command which is used to terminate
‘4 process which terminates the process.
YINSTITUTE OF ENGINEERING AND TECHNOLOGY |
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: JOT Lab
Experiment -2
Aim: Write a python program to read your name and print Hello message with name on Pi.
Source Code:
from machine import Pin, 12C
from pico_i2c_led import I2cLed
from time impon sleep
12C_ADDR = 0x27
12C_NUM_ROWS =2
12C_NUM_COLS = 16
ide = I2C(
led = I2cLed(i2c, 12C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
‘NAMES = [Abhishek Parihar"]
while True:
for name in NAMES:
[Link]()
[Link]("Hello")
Ied.move_to(0, 1)
[Link](name)
sleep(2)Mohanlal Sukhadia University, Udaipur
‘Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: IOT Lab
© INSTITUTE OF ENGINEERING AND TECHNOLOGY
vy
Output:Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: IOT Lab
Experiment -3
' Aim: Write a python program to read two numbers and print their sum, difference, product and
division on Pi.
Source Code:
import time
time-skeep(0.1)
i
int(input("Enter First Number:"))
‘num? = int(input("Enter Second Number:"))
ch = input("Enter Operation +,-.*//:")
result = 0
result = num! + num2
ssult = num - num2
result=num| * num2
result = num/num2 \
print(result)
Output:INSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: IOT Lab
Experiment — 4
Aim: Write a python program to read a string and print word and character count of string on Pi
Source Code:
import time
[Link](0.1)
text = input("Enter a String: ")
words = [Link]()
wordCount = len(words)
charCount = 0
for w in words:
charCount += len(w)
print("Total Words:", wordCount)
print("Total Characters:", charCount)
Output:E OF ENGINE 3 AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: JOT Lab
INSTT
Experiment — 5
Jim: Write a python program to find area and perimeter of given shapes(Rectangle, Triangle, Circle)
on Raspberry Pi.
Source Code:
(Rectangle)
import time
print("Rectangke")
[Link](1)
width = float(input("Enter the Width of a Rectar
height = float(input("Enter the Height of a Rectangle: "))
area = width * height
perimeter = 2 * (width + height)
[Link](1)
prini("\nArea of a Rectangle js“%.21" % area)
[Link](1) g
print("Perimeter of Rectangle is: %.2f" % perimeter)
‘Output:
E
Pens ee ae
Peete ort ae
rosa oe CE
pec)INSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VIE Sem) | Subject: JOT Lab
(Triangle)
import time
import math
print("Triangle")
er first side: "))
nd side: "))
ide: "))
Moat(input("
Moat(input(”
=(atb+c)/2
DP Output:
(Circle)
import time
import math
print("'Circle")
[Link](1)
radius = float(input("'Enter the radi
diameter = 2 * radius
fa circle: "))
>» circumference = 2 * mat! radius
area = [Link] * radlus* radius
[Link](1)
print("Diameter of a Circle = %.2f" % diameter)
[Link](!)
print("Circumference of a Circle = %.2f" % circumference)
[Link](1)
print(""Area of a Circle = %.2!" % area)
Output:INSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: JOT Lab
Experiment - 6
2 Write a python program to Print a name 'n’ times, where name and n are read from standard
input, using for and while loops on Raspberry Pi
Source Code:
(Using while loop)
import time
[Link](0.1)
name = input("Enter name: ")
num = int(input("Enter number:"))
i=o
while(i != num):
print(name)
re
(Using for loop)
import time
[Link](0.1)
name = input("Enter name: "
((input("Enter
for i in range(0,nGim):
print(name)
Output:
errsINSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: JOT Lab,
Experiment -7
Aim: Write a python program to Handle Divided by Zero Exception on Raspberry Pi
Source Code:
import time
[Link](0.1)
print("Enter two numbers n1 and n2")
al
n2
int(input("Enter n1: "))
«(input("Enter n2: "))
nl /n2
print("Result:", div)
except ZeroDivisionError: 3
print("Zero division is handled")
print("Out ——
Output:
Preece me RT)
Para Se
ce aD
oe Tl
aesINSTITUTE OF ENGIN IN
Mohanlal Sukhadia Uni
Name: Abhishek Parihar | Class: BTech-
AND TECHNOLOGY
ersity, Udaipur
‘SE (VII Sem) | Subject: 101 fab
Exp
iment —8
Aim: Write a python program to Print current time for 10 times with an interval of 10 seconds on
Raspberry Pi
Source Code:
import time
fori in range (10):
[Link]()
[3]
mm =1{4]
ss=t{5]
print(" {:02d},{:02d}, {:02d)".format(hh, mm, ss))
[Link](19)
Output:
Crm
Creo
Cree}
eoeers
Creed
CoreINS’
fUTE OF ENGINER, RIN'
Mohanlal Sukhadi
Name: Abhishek Parihar | C
ND TECHNOLOGY
ry, Udaipur
i (VII Sem) | Subject: JOT Lab
a Univ
ss: BTech-C§
| Sa ae ee sees
Experiment — 9
ie Wile» program to Display the Aten of ResangtelCircle/Trianole tn LED Soreun by the heh
‘of keyboard on Raspberry Pi, ‘ectangle/Circle/Triangle in LCD Screen by the help
Source Code:
from machine import Pin, 12C
i2c_led import I2cLed
import sleep
import math
12C(0, sda=Pin(0), s
addr = [Link]()[0]
(1), freq=100000)
led = I2cLed(i2c, addr, 2, 16)
[Link]()
[Link]("LCD OK!")
—- KEYPAD --
(2, [Link]), Pin(3, [Link]), Pin(4,
[Link]), Pin(S, Pin-OUT)]
[24°35 '\),
[4.5.6 BY,
[7.895 °C],
[e008 Dy
]
def get_key():
forrin range(4):
rows(r].value(1)
for cin range(4):
if cols{c].value():
rows[r).value(0)
sleep(0,3) # debounce
return keysfr}[e}
rows[[Link](0)
return NoneRING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: OT Lab
NUMBER INPUT
dar ge. numbertpromp0
[Link]()
Jed, putstr(prompt)
Jed.move_to(0, 1)
Jed.moye_10(0, 1)
4 confirm
Lp
Jed.move_10(0, |)
[Link]("3:Triangle")
choi
choice = ae
Pedclear
width = get_number(" Width:
height = get_number("Height
area = width * height
perim = 2 * (width + height)
[Link]()
[Link]("Area:")
ed.move_t0(6, 0)
[Link](str(area))
led.move_t0(0, 1)
———[Link]("Per:")
—_led.move_to(5, 1)
‘ed. putstr(str(perim))INSTITUTE OF E RING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: [OT Lab
SIRCLE
choice
radius = get_number("Radius:")
area = [Link]* radius * radius
cire=2 * [Link]* radius
[Link]()
[Link]("Area:")
Ied.move_to(6, 0)
Jed putstrstr{round(area, 2)))
led.move_to(0, !)
[Link]("Cire:")
led. move_10(6, !)
Jed. putstr(str(round(cire, 2)))
RIANGLE -~
_number{"Base:")
height = get_number("Height:")
area = 0.5 * base * height
[Link]()
[Link]("Triangle")
Ied.move_t0(0, 1)
[Link]("Area:")
Jed.move_to(6, !)
led putstr(str(area))
Output:TUTE OF ENGINEE 3 AND TECHNOLOGY
: Mohanlal Sukhadia Uni ersity, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: JOT Lab
Experiment — 10
E # Write a program to Read a file line by line and print the word count of cach line. on Raspberry
i.
Souree Code:
import time
# Multi-line string
text =""eiurhewyu ueiwrhy uie
ruyheiurhyfeui eryhrieu
ueryth 88eloeju cudyu ruyheiurhy euieuih
euhrfituihniu"™
lines = text split("\n")
line_no=1
for line in lines:
words = [Link]()
print("Line”, line_no, "Words =", len(words))
line_no+=1
[Link](0.1)3INEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: IOT Lab
Experiment — 11
Aim: Write a program to Light an LED through Python program on Raspberry Pi
Souree Code:
from machine import Pin
from time import sleep
ledl = Pin(5, [Link])
Jed2 = Pin("LED", [Link])
while True:
led! .toggle()
[Link]()
sleep(0.5)
Output:
s i |
=
a
Be-A-S- KA EBD MSR
ae)——— See vO a _
TITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parthar | Class: Blech-CSE (VIE Sem) | Subject: FOT Lab
Experiment - 12
Aim: Write a program to Get input from two switches and switch on corresponding LEDS on
Raspberry Pi
Source Code:
from machine import Pin
from time import sleep
Jed = Pin(28, [Link])
BUTTON = Pin(15, [Link], Pin.PULL_DOWN)
Jed2 = Pin(21, [Link])
> BUTTON? = Pin(14, [Link], Pin.PULL_DOWN)
buttonState =0
buttonState2 = 0
while True:
if BUTTON. value() == I:
buttonState = 1 - buttonState
sleep(0.03)
if buttonState =
[Link]()
else:
[Link]()
elif BUTTON2 value
DuttonState2 = 1 - buttonState2
sleep(0.03) ’
if buttonState2 = I: hem
led2.0n()
) else:
Jed2.0f%0)
Output:
a:
EINSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: 1OT Lab
Experiment — 13
Aim: Write a Micro Python program that controls an RGB LED and displays multiple colors (Red,
Green, Blue, Yellow, Cyan, Magenta, White) on Pi.
Source Code:
from machine import Pin
from time import sleep
# Define RGB pins
red = Pin(2, [Link])
green = Pin(1, [Link])
D blue = Pin(0, [Link])
# Function to tun OFF LED
def off):
[Link](0)
[Link](0)
[Link](0)
# Function to set color
def set_color(r, g, b):
[Link](r)
[Link](e)
[Link](b)
# Main loop
while True:
set_color(1,0,0) # fed
sleep(1)
off)
set_color(0, 1,0) #Green
sleep()
off)
set_color(0,0, 1) # Blue
sleep()
off
set_color(I, 1,0) # Yellow
sleep(1)
off)
set_color(0, 1,1) #Cyan
sleep(1)INSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: JOT Lab
—
off)
set_color(1, 0,1) # Magenta
sleep(1)
off)
set_color(1, 1,1) # White
sleep(1)
off)
Output:ERING AND TECHNOLOGY
University, Udaipur
(VI! Sem) | Subject: JOT Lab
TUTE OF ENG
Mohanlal Sukhadi
Name: Abhishek Parihar | Class: BTech-CS!
Experiment - 14
Aim: Write a program to interface a common anode 7-segment display using MicroPython and
implement an ascending and descending counter controlled by a switch on Pi.
Source Code:
from machine import Pin
from utime import sleep
segment pins (A, B, C, D, E, F, G, DP)
Pin(4, [Link]),
Pin(6, [Link]),
Pin(7, [Link]),
Pin(8,
Pin@, Pi
Pin(2, Pi
Pin(0,
J
#4 Common Anode digits (0-9 only)
digits =[
{0,0,0,0,0,0,1,1], #0
[1,0,0,1,1,1,1,1], #1
0,0, 1,0,0,1,0,1], #2
. [0,0,0,0,1,1,0,1], #3
[1,0,0,1,1,0,0,1), #4
; [0,1,0,0,1,0,0,1], #5
[0,1,0,0,0,0,0,1], # 6
[0,0,0,1,1,1,1,1), #7
[0,0,0,0,0,0,0,1], # 8
[0.0,0,0,1,0,0,1] #9
J
# Tum OFF all segments (for common
def reset():
for pin in pins:
[Link](1)
reset()
OUT),
OUT),
oun),
OUT) # DP (not used)
(ode + HIGH = OFF)Ke INSTITUTE OF ENGINEERING AND TECHNOLOGY
Mohanlal Sukhadia University, Udaipur
Name: Abhishek Parihar | Class: BTech-CSE (VII Sem) | Subject: IOT Lab
SS ea ee He
while True:
# Ascending (switch ON — 0)
if [Link]() = 0:
for i in range(10):
if [Link] = 1:
for j in range(8):
pins{j].value(digits[iJ[j))
sleep(1)
# Descending (switch OFF — 1)
else:
for i in range(9,
for j in range(8):
pins(j}-value(digits(iJ{i))
sleep(!)
Output:
Potrebbero piacerti anche Lezione 1 PDF
Nessuna valutazione finora
25 pagine
Lezione 1 PDF
Nessuna valutazione finora
18 pagine
Modulo 3 PDF
Nessuna valutazione finora
143 pagine