Week 6
Week 6
Week 6
1.AVRISP mkII: This is a popular external programmer used for burning code onto AVR microcontrollers, which are the
microcontrollers used in most Arduino boards. You would select this option if you have an AVRISP mkII or a compatible
programmer connected to your Arduino board.
2.USBtinyISP: Another external programmer that is compatible with AVR microcontrollers. Select this option if you are using a
USBtinyISP programmer.
3.Arduino as ISP: This option allows you to use one Arduino board as a programmer to upload code to another Arduino board. It's
a useful option for certain advanced projects.
4.Arduino as AVRISP mkII: Similar to the "Arduino as ISP" option, this allows you to use an Arduino board as a programmer,
emulating an AVRISP mkII programmer.
5.Parallel Programmer: This option is used with older Arduino boards that might have a parallel programming header.
6.ArduinoISP: This is a special sketch that you can upload to an Arduino board to turn it into a programmer. You would select this
option when using the Arduino board as a programmer.
7.No Programmer: Use this option if you want to upload code using the bootloader via the USB-to-serial interface. This is the
default and most common choice.
IIT Kharagpur Introduction to Internet of Things Week 6 2
Python
Why python?
Python IDE
Python IDE is a free and open source software that is used to write codes, integrate several modules and libraries.
It is available for installation into PC with Windows, Linux and Mac.
Examples: Spyder, PyCharm, etc.
String Dictionary
x = ‘This is Python’ d = {1:‘item','k':2}
print x >>This is Python
print x[0] >>T
print x[2:4] >>is
Controlling Statements
Functions in Python
if x > y:
return x, y
else:
return y, x
Output:: (100,10)
Functions in Python
Output:: 10 10
Global variables:
These are the variables declared out of any function , but can be accessed inside as well as outside the function.
Local variables:
These are the ones that are declared inside a function.
var = 10
def example(): g_var = 10
var = 100 def example():
print(var) l_var = 100
example() # calling the function print(g_var)
print(var) example() # calling the function
Output:: 100
10 Output:: 10
IIT Kharagpur Introduction to Internet of Things Week 6 8
Python
Modules in Python
Any segment of code fulfilling a particular task that can be used commonly by everyone is termed as a module.
import random
for i in range(1,10):
val = random.randint(1,10)
print (val)
try: Example:
Opening a File:
Python allows you to read and write files
Open() function is used to open a file, returns a file object
No separate module or library required
open(file_name, mode)
Three basic steps
Mode: Four basic modes to open a file
Open a file
r: read mode
Read/Write w: write mode
Close the file a: append mode
r+: both read and write mode
Closing a file:
Close(): This is done to ensure that the file is free to use for other resources
file.close()
PIL is supported till python version 2.7. Pillow supports the 3x version of python.
conv_image=image.convert(‘L’)
Conversion between modes other that ‘L’ and ‘RGB’ needs conversion into any of these 2 intermediate mode
Networking in Python
A socket is one endpoint of a two way communication link between two programs running on the
network. The socket mechanism provides a means of inter-process communication (IPC) by establishing
named contact points between which the communication take place.
Types:
▪ Stream Sockets referred as "SOCK_STREAM"
▪ Datagram Sockets referred as "SOCK_DGRAM”
▪ Raw Sockets referred as "SOCK_RAW”
https://beej.us/guide/bgnet/pdf/bgnet_a4_c_1.pdf
▪ bind() system call is used to binds the function with the particular IP and port.
▪ listen() system call hears to the various connections present in the network and
selects the particular client to serve.
▪ The connect() function is then called on the client with three arguments, namely
the socket descriptor, the remote server address and the length of the address
data structure.
▪ A send() is used to send the message either from the client to server or vice
versa.
▪ The recv() function is used to receive the messages at the both ends.
Sending messages separately to each recipient consumes extra bandwidth and processing time.
Simple client-server program in Python, where the client requests the current time and date from the
server and then prints the same.
Start up of Raspberry Pi
Pin Configuration
Set up of Raspberry Pi
• HDMI cable.
• Monitor.
• Key board.
• Mouse.
• 5volt power adapter for raspberry pi.
• LAN cable . Official Supported OS :
• Min- 2GB micro sd card • Raspbian
• NOOBS
Some of the third party OS :
Default installed :
• UBUNTU mate
• Python
• Snappy Ubuntu core
•C
• Windows 10 core
• C++
• Pinet
• Java
• Risc OS
• Scratch
• Ruby
Enable SSH
Step1 : Open command prompt and type sudo raspi-config and
press enter.
Step2: Navigate to SSH in the Advance option.
Step3: Enable SSH
Applications
• Media streamer
• Home automation
• Controlling BOT
• VPN
• Light weight web server for IOT
• Tablet computer
a. [32]
b. ['34']
c. ['u', 'i', 8, '34']
d. [32,'u', 'i', 8, '34']
a. [32]
b. ['34']
c. ['u', 'i', 8, '34']
d. [32,'u', 'i', 8, '34']
How many GPIO (General Purpose Input Output Pin) pins are there in Raspberry Pi 4?
a. 30
b. 14
c. 40
d. 41
How many GPIO (General Purpose Input Output Pin) pins are there in Raspberry Pi 4?
a. 30
b. 14
c. 40
d. 41
a. Sublime Text
b. PyCharm
c. Spider
d. None of the above
a. Sublime Text
b. PyCharm
c. Spider
d. None of the above
Sublime Text, PyCharm, Spyder, and Jupyter are few of the examples of Python IDE.
a. 0
b. 9
c. -2
d. Will raise an exception
a. 0
b. 9
c. -2
d. Will raise an exception
a. Pass
b. Continue
c. Break
d. Skip
a. Pass
b. Continue
c. Break
d. Skip
As per basics of Python programming, pass is a null operation. The interpreter does not ignore a pass statement, but
nothing happens and the statement results into no operation.
a. List
b. Dictionary
c. Both List and Dictionary
d. Tuple
a. List
b. Dictionary
c. Both List and Dictionary
d. Tuple
a. 11
b. 0
c. Will raise an error
d. Will raise an exception
a. 11
b. 0
c. Will raise an error
d. Will raise an exception
Which of the following symbol is used to comment out multiple lines at once in python?
a. $
b. #
c. %
d. None of these
Which of the following symbol is used to comment out multiple lines at once in python?
a. $
b. #
c. %
d. None of these
Unlike other programming languages Python doesn't support multi-line comment blocks out of the box. The recommended
way to comment out multiple lines of code in Python is to use consecutive # single-line comments.
With on-board Raspberry Pi camera, which one of the following is NOT correct for image related operations in Python?
With on-board Raspberry Pi camera, which one of the following is NOT correct for
image related operations in Python?
a. 64
b. 32
c. Both 64 & 32
d. 128
a. 64
b. 32
c. Both 64 & 32
d. 128
The Raspberry Pi Zero 2 W includes a new Broadcom BCM2710A1 SOC providing a 1GHz quad-core 64-bit ARM
Cortex-A53 CPU and 512MB RAM.
a. Ctrl + E
b. Ctrl + O
c. Ctrl + X
d. None of these
a. Ctrl + E
b. Ctrl + O
c. Ctrl + X
d. None of these
Ctrl + O writes the code to a file. Ctrl + X exits the nano editor.
a. s = socket.socket(socket.AF_NET, socket.SOCK_STRAM)
b. s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
c. s = socket.socket(socket.AF_UNX, socket.SOCK_TCP)
d. s = socket.socket(socket.AF_INET, socket.SOCK_UDP)
a. s = socket.socket(socket.AF_NET, socket.SOCK_STRAM)
b. s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
c. s = socket.socket(socket.AF_UNX, socket.SOCK_TCP)
d. s = socket.socket(socket.AF_INET, socket.SOCK_UDP)
AF_UNIX or AF_INET represent socket family. SOCK_STREAM or SOCK_DGRAM represent socket type.
Which of the following is correct to open a text file for write mode?
a. open('file.txt', ‘w’)
b. open('file.txt', ‘+w’)
c. open('file.txt', ‘w+’)
d. open('file.txt', ‘o+w’)
Which of the following is correct to open a text file for write mode?
a. open('file.txt', ‘w’)
b. open('file.txt', ‘+w’)
c. open('file.txt', ‘w+’)
d. open('file.txt', ‘o+w’)
‘w’ mode is for writing into a text file. ‘r’ mode is for reading a text file.
a. String
b. Tuple
c. Bool
d. All of these
a. String
b. Tuple
c. Bool
d. All of these
Immutable Objects are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object
can't be changed after it is created.
a. Yes
b. No
c. Not Applicable
a. Yes
b. No
c. Not Applicable
What is the value that is assigned to the variable f in the given piece of python code?
a. 50
b. 50.68
c. Welcome to python
d. All of these
What is the value that is assigned to the variable f in the given piece of python code?
a. 50
b. 50.68
c. Welcome to python
d. All of these
x='17'
y='23'
z=x+y
print(z)
a. 40
b. 6
c. 1723
d. 30
x='17'
y='23'
z=x+y
print(z)
a. 40
b. 6
c. 1723
d. 30
a. Microcomputer
b. Minicomputer
c. Operating system
d. Assembler
a. Microcomputer
b. Minicomputer
c. Operating system
d. Assembler
a. to pyth
b. SyntaxError: invalid syntax
c. e to pyt
d. to pyt
a. to pyth
b. SyntaxError: invalid syntax
c. e to pyt
d. to pyt
This slice includes all characters from index 8 up to, but not including, index 14. Therefore, the output is the
substring "to pyt", which consists of the characters at indices 8 through 13 of the original string t1.
Which of the following represents the command used for rebooting Raspberry Pi?
a. sudo reboot
b. sudo apt-get rebooting
c. pip install rebooting
d. All of these
Which of the following represents the command used for rebooting Raspberry Pi?
a. sudo reboot
b. sudo apt-get rebooting
c. pip install rebooting
d. All of these
a. True
b. False
a. True
b. False
What is the data type of the variable ls in the following piece of Python code?
ls= {1: "item", "key": "21", "year": 2022}
a. dictionary
b. list
c. tuple
d. All of these
What is the data type of the variable ls in the following piece of Python code?
ls= {1: "item", "key": "21", "year": 2022}
a. dictionary
b. list
c. tuple
d. All of these
a. True
b. False
a. True
b. False
What are the socket types that exist in Python based socket programming?
What are the socket types that exist in Python based socket programming?
a. Yes
b. No
a. Yes
b. No
Which of the following must be used to terminate a loop and move to the next code after the loop?
a. list
b. try
c. continue
d. break
Which of the following must be used to terminate a loop and move to the next code after the loop?
a. list
b. try
c. continue
d. break
Select the option that does not represent a keyword in Python language?
a. while
b. if
c. try
d. integer
Select the option that does not represent a keyword in Python language?
a. while
b. if
c. try
d. integer
Raspberry Pi does not support any other language other than Python?
a. True
b. False
Raspberry Pi does not support any other language other than Python?
a. True
b. False
True
False
True
False
Fill in the blanks. Python IDE is available for installation into PC with __________.
Windows
Linux
Mac
All of these
Fill in the blanks. Python IDE is available for installation into PC with __________.
Windows
Linux
Mac
All of these
No
Yes
No
Yes
1
2
5
7
1
2
5
7
The variable that is declared inside the function in Python is called a Global variable.
True
False
The variable that is declared inside the function in Python is called a Global variable.
True
False
file = open(‘data.txt’, ‘r ’)
file = open_text(‘data.txt’, ‘r ’)
file = read_text(‘data.txt’, ‘r ’)
file = read(‘data.txt’, ‘r ’)
file = open(‘data.txt’, ‘r ’)
file = open_text(‘data.txt’, ‘r ’)
file = read_text(‘data.txt’, ‘r ’)
file = read(‘data.txt’, ‘r ’)
Pillow
Numpy
Panda
None of these
Pillow
Numpy
Panda
None of these
True
False
True
False
Ctrl + E
Ctrl + O
Ctrl+V
None of these
Ctrl + E
Ctrl + O
Ctrl+V
None of these
List
Dictionary
Both List and Dictionary
Tuple
List
Dictionary
Both List and Dictionary
Tuple
Actuator
Raspberry Pi
Sensor
None of these
Actuator
Raspberry Pi
Sensor
None of these
True
False
True
False
True
False
True
False
a. True
b. False
a. True
b. False
Which among the following libraries in Python do you use to generate and plot graphs
a. numpy
b. time
c. matplotlib
d. random
Which among the following libraries in Python do you use to generate and plot graphs
a. numpy
b. time
c. matplotlib
d. random
A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?
a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno
A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?
a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno
a. three
b. zero
c. four
d. one
a. three
b. zero
c. four
d. one
•Integer
•Float
•Either integer or float
•Range
•Integer
•Float
•Either integer or float
•Range
Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy
Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy
What are variables that are declared and has its scope within a function in python called?
a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable
What are variables that are declared and has its scope within a function in python called?
a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable
a. raspicapture
b. raspicam
c. raspisnap
d. raspistill
a. raspicapture
b. raspicam
c. raspisnap
d. raspistill
a. True
b. False
a. True
b. False
a. List
b. Tuple
c. Dictionary
d. All of these
a. List
b. Tuple
c. Dictionary
d. All of these
a. Immediate variables
b. Global variables
c. Local variables
d. None of these
a. Immediate variables
b. Global variables
c. Local variables
d. None of these
a. File mode
b. File object
c. File name
d. None of these
a. File mode
b. File object
c. File name
d. None of these
a. True
b. False
a. True
b. False
a. image.show()
b. image.open()
c. image.name()
d. image.mode()
a. image.show()
b. image.open()
c. image.name()
d. image.mode()
a. Client-server
b. P2P
c. All of these
d. None of these
a. Client-server
b. P2P
c. All of these
d. None of these
In python, ”with” ensures the file is closed after the operation is completed, but not when an exception occurs.
a. True
b. False
In python, ”with” ensures the file is closed after the operation is completed, but not when an exception occurs.
a. True
b. False
a. True
b. False
a. True
b. False
a. Ctrl+O
b. Ctrl+X
c. Ctrl+A
d. None of these
a. Ctrl+O
b. Ctrl+X
c. Ctrl+A
d. None of these
a. Yes
b. No
a. Yes
b. No
a. Yes
b. No
a. Yes
b. No
a. Actuator
b. Raspberry Pi
c. All of these
d. None of these
a. Actuator
b. Raspberry Pi
c. All of these
d. None of these
a. Mechanical switch
b. Electrochemical switch
c. None of these
d. All of these
a. Mechanical switch
b. Electrochemical switch
c. None of these
d. All of these
a. True
b. False
a. True
b. False
a. True
b. False
a. True
b. False
Which among the following libraries in Python do you use to generate and plot graphs
a. numpy
b. time
c. matplotlib
d. random
Which among the following libraries in Python do you use to generate and plot graphs
a. numpy
b. time
c. matplotlib
d. random
A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?
a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno
A programmer needs to execute a python code that requires RAM support of 1GB SDRAM, Quad cortex [email protected]
CPU, 400 MHz video core IV GPU, and 802.11 wireless communication support. Select the appropriate device where
the code can be executed?
a. Raspberry Pi zero
b. Raspberry Pi 2 model B
c. Raspberry Pi 3 model B
d. Arduino Uno
a. three
b. zero
c. four
d. one
a. three
b. zero
c. four
d. one
•Integer
•Float
•Either integer or float
•Range
•Integer
•Float
•Either integer or float
•Range
Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy
Which of the following is the extension for your python file in Raspberry Pi?
a. .py
b. .pi
c. .rpi
d. .rpy
What are variables that are declared and has its scope within a function in python called?
a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable
What are variables that are declared and has its scope within a function in python called?
a. Global variable
b. Local variable
c. Hierarchical variable
d. Dangling variable
a. raspicapture
b. raspicam
c. raspisnap
d. raspistill
a. raspicapture
b. raspicam
c. raspisnap
d. raspistill