0% found this document useful (0 votes)
10 views63 pages

Unit 3

This document serves as an introduction to Python programming and Raspberry Pi, covering key concepts such as data types, variables, operators, control structures, functions, and exception handling in Python. It also provides an overview of Raspberry Pi models, their specifications, and functionalities, highlighting its use in physical computing. The content is structured to aid beginners in understanding both Python and Raspberry Pi integration.

Uploaded by

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

Unit 3

This document serves as an introduction to Python programming and Raspberry Pi, covering key concepts such as data types, variables, operators, control structures, functions, and exception handling in Python. It also provides an overview of Raspberry Pi models, their specifications, and functionalities, highlighting its use in physical computing. The content is structured to aid beginners in understanding both Python and Raspberry Pi integration.

Uploaded by

Karan Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

UNIT…3

Introduction to Python and Raspberry Pi

Miss. Divya P. Surwade


Assistant Professor
(E&C Dept, KCES’s COEM)
Content
•Python :- Python • List
IDE • Dictionary
•Data types • Writing to a File
•Variable • Reading from a File
•Operator • handling
•Branches exceptions.
•Loops
• functions
Content
•Raspberry Pi: - commands
•Models of • configuring R pi3
Raspberry pi • Interfacing of
•R Pi 3 hardware Digital and Analog
• GPIO pins sensors.
• operating system
for R pi3
• Basic of Linux
Introduction of Python
• Python is a very popular general-purpose
interpreted, interactive, object-oriented, and high-
level programming language.
• It was created by Guido van Rossum during 1985-
1990.
• It was designed with focus on code readability and
its syntax allows us to express concepts in fewer
lines of code.
Key Features of Python

• Python’s simple and readable syntax makes it beginner-


friendly.
• Python runs seamlessly on Windows, macOS and Linux.
• Includes libraries for tasks like web development, data
analysis and machine learning.
• Variable types are determined automatically at runtime,
simplifying code writing.
• Supports multiple programming paradigms, including
object-oriented, functional and procedural programming.
• Python is free to use, distribute and modify.
Python IDE
• A Python Integrated Development Environment (IDE) is a
software application that provides a comprehensive set of
tools for developing software in Python.
• It is a combination of tools like a code editor, code
compiler, and code debugger with an integrated terminal.
• Python IDE helps in making web pages, apps, new
software, etc.
• Key Features and Benefits:-

1) Code Editor:
IDEs offer advanced code editors with
features like syntax highlighting, auto-
completion, and code refactoring.
2) Debugging:
They include powerful debugging tools to help identify and
fix errors in the code.

3) Integration:
They integrate with various tools and platforms, making it
easier to develop and deploy Python applications.

4) Project Management:
IDEs can manage projects, including version control
integration, build automation, and package management.
Common Python IDEs:
• PyCharm:
A powerful and feature-rich IDE from JetBrains, known
for its performance and extensive features.
• Spyder:
A popular IDE designed for scientific computing and
data analysis, with features for debugging, profiling, and
variable inspection.
• Jupyter Notebook:
An open-source web application that allows users to
create and share documents containing live code,
equations, visualizations, and narrative text.
• Thonny:
A free and beginner-friendly IDE with a simple interface
and built-in Python 3.
• Visual Studio Code (VS Code):
A versatile text editor with strong support for Python
development, including syntax highlighting, code
completion, and debugging.
• IDLE:
A simple and built-in IDE that comes with Python
installations.
Python data types are actually classes, and the defined variables are
their instances or objects. Since Python is dynamically typed, the data
type of a variable is determined at runtime based on the assigned
value.
So Let’s Discuss the all Data Types in Python-

1. Numeric Data Types in Python


Integers - This value is represented by int class. It contains positive or
negative whole numbers (without fractions or decimals). In Python,
there is no limit to how long an integer value can be.

Float - This value is represented by the float class. It is a real number


with a floating-point representation. It is specified by a decimal point.
Optionally, the character e or E followed by a positive or negative
integer may be appended to specify scientific notation.
Complex Numbers - A complex number is represented by a complex
class. It is specified as (real part) + (imaginary part)j . For example -
2+3j
2. Sequence Data Types in Python

The sequence Data Type in Python is the ordered collection of similar


or different Python data types. Sequences allow storing of multiple
values in an organized and efficient fashion.
There are several sequence data types of Python:
Python String
Python List
Python Tuple
1) String Data Type
Python Strings are arrays of bytes representing Unicode characters. In
Python, there is no character data type Python, a character is a string
of length one. It is represented by str class. Strings in Python can be
created using single quotes, double quotes or even triple quotes. We
can access individual characters of a String using index.
2) List Data Type
Lists are just like arrays, declared in other languages which is an ordered
collection of data. It is very flexible as the items in a list do not need to be of the
same type.
Creating a List in Python
Lists in Python can be created by just placing the sequence inside the square
brackets[].
Access List Items
In order to access the list items refer to the index number. In Python,
negative sequence indexes represent positions from the end of the array.
Negative indexing means beginning from the end, -1 refers to the last
item, -2 refers to the second-last item, etc.
3) Tuple Data Type
Just like a list, a tuple is also an ordered collection of Python objects.
The only difference between a tuple and a list is that tuples are
immutable. Tuples cannot be modified after it is created.
Creating a Tuple in Python
In Python Data Types, tuples are created by placing a sequence of values
separated by a ‘comma’. Tuples can contain any number of elements
and of any datatype (like strings, integers, lists, etc.).
3) Boolean Data Type in Python

Python Data type with one of the two built-in


values, True or False.

4) Identity Operators in Python

In Python, is and is not are the


identity operators both are used to check if
two values are located on the same part of
the memory. Two variables that are equal do
not imply that they are identical.
is True if the operands are identical
is not True if the operands are not identical
Dictionary Data Type
A dictionary in Python is a collection of data values, used to store data
values like a map, unlike other Python Data Types that hold only a
single value as an element, a Dictionary holds a key: value pair. Key-
value is provided in the dictionary to make it more optimized. Each
key-value pair in a Dictionary is separated by a colon : , whereas each
key is separated by a ‘comma’.

Create a Dictionary in Python


Values in a dictionary can be of any datatype and can be duplicated,
whereas keys can’t be repeated and must be immutable. The dictionary
can also be created by the built-in function dict().
Accessing Key-value in Dictionary
In order to access the items of a dictionary refer to its key name. Key can
be used inside square brackets. Using get() method we can access the
dictionary elements.
variable
• A variable in Python serves as a named storage location in the
computer's memory, used to hold data values.
• It's a fundamental concept in programming, allowing the storage
and manipulation of information within a program.
• Unlike some other programming languages, Python doesn't require
explicit declaration of a variable's data type; it dynamically infers
the type based on the assigned value.
• Creating and Assigning Values to Variables
• A variable is created the moment a value is
assigned to it using the assignment operator (=).
Operators
• In Python programming, Operators in general are used to perform
operations on values and variables. These are standard symbols used
for logical and arithmetic operations. In this article, we will look into
different types of Python operators.
• OPERATORS: These are the special symbols. Eg- + , * , /, etc.
• OPERAND: It is the value on which the operator is applied.
Arithmetic Operators in Python
• Python Arithmetic operators are used to perform basic
mathematical operations like addition, subtraction,
multiplication and division.
Comparison of Python Operators
• In Python Comparison of Relational operators compares the
values. It either returns True or False according to the condition.
Logical Operators in Python
• Python Logical operators perform Logical AND, Logical
OR and Logical NOT operations. It is used to combine conditional
statements
Assignment Operators in Python
• Python Assignment operators are used to assign values to the
variables. This operator is used to assign the value of the right
side of the expression to the left side operand.
• Assignment Operators in Python
Operator Associativity in Python
• If an expression contains two or more operators with
the same precedence then Operator Associativity is
used to determine. It can either be Left to Right or
from Right to Left.
Branches
• Conditional statements in Python are used to execute certain
blocks of code based on specific conditions. These statements
help control the flow of a program, making it behave differently in
different situations.
1) If Conditional Statement -
• If statement is the simplest form of a conditional statement. It
executes a block of code if the given condition is true.
If else Conditional Statements

• Else allows us to specify a block of code that will execute if


the condition(s) associated with an if or elif statement
evaluates to False.
• Else block provides a way to handle all other cases that don't
meet the specified conditions.
elif Statement

• elif statement in Python stands for "else if." It allows us to


check multiple conditions , providing a way to execute
different blocks of code based on which condition is true.
• Using elif statements makes our code more readable and
efficient by eliminating the need for multiple nested if
statements.
Match-Case Statement in Python
• match-case statement is Python's version of a switch-case
found in other languages. It allows us to match a variable's
value against a set of patterns.
Loops
• Python provides three ways to execute loops, all of which offer
the same basic functionality. However, they have different syntax
and condition-checking times.
• Python programming loops are instructions to repeat something
multiple times until a specific condition is met. In Python, we can
run either a single or several statements over and over through a
loop command.
• Types of Loops in Python
• Below, we have listed and discussed different loops in Python,
along with the syntax and examples of each:
• While Loops in Python
• For Loops in Python
• Nested loop
1. While Loops
• It is used in Python programming to execute a block of
statements until the given condition is true. Once the condition
is evaluated as false, the program executes the line
immediately after the loop.
• While Loop in Python Syntax

• Python indentation is a way of grouping statements.


• The statements indented using the same number of spaces are
considered part of the same code block.
While Loop Example

Output:-
2) For Loops
• It is designed to iterate over a sequence, such as a list,
dictionary, tuple, set, and string. Iteration is the process of
traversing a sequence.
• Syntax-
Nested Loop
• In Python, the nested loop refers to using a loop within
another loop.
• Every single iteration of the outer loop has an inner loop
executing its iterations.
• For example, if the outer loop has a and the inner loop has b
iterations, the total iterations will be a x b.
• This means that for every outer loop iteration, the inner loop
executes b times.
• Syntax-
Functions
• Python Functions is a block of statements that return
the specific task.
• The idea is to put some commonly or repeatedly done
tasks together and make a function so that instead of
writing the same code again and again for different
inputs, we can do the function calls to reuse code
contained in it over and over again.
• Some Benefits of Using Functions
• Increase Code Readability
• Increase Code Reusability
Python Function Declaration

• The syntax to declare a function is:


Types of Functions in Python

• Below are the different types of functions in Python:


• Built-in library function: These are Standard functions in
Python that are available to use.
• User-defined function: We can create our own functions
based on our requirements.
Creating a Function in Python
• We can define a function in Python, using the def keyword.
Calling a Function in Python
• After creating a function in Python we can call it by using the
name of the functions Python followed by parenthesis
containing parameters of that particular function.
• Below is the example for calling def function Python.
Python Function with Parameters
• Function Syntax
def function_name(parameter: data_type) -> return_type:
"""Docstring"""
# body of the function
return
expression
Handling Exceptions.
• In Python, exception handling is a crucial mechanism for
managing runtime errors gracefully, preventing program
crashes, and ensuring smooth execution.
• It involves using try, except, else, and finally blocks to catch
and handle exceptions that may occur during program
execution.
• Try and Except Blocks
• The core of exception handling lies in
the try and except statements. Code that might raise an
exception is placed within the try block.
• If an exception occurs during the execution of the try block,
Python immediately transfers control to the
corresponding except block.
Else and Finally Blocks
• The else block is executed only if no exceptions occur in
the try block. It is useful for code that should run only when
the try block succeeds.
• The finally block is executed regardless of whether an
exception occurred or not. It is used to perform cleanup
actions such as closing files or releasing resources.
Raspberry Pi
• Raspberry pi is the name of the “credit card-sized computer
board” developed by the Raspberry pi foundation, based in the
U.K.
• It gets plugged in a TV or monitor and provides a fully functional
computer capability.
• The Raspberry Pi is a series of powerful, small single-
board computers.
• Raspberry Pi is launched in 2012
• The original device had a single-core Processor speed of device
ranges from 700 MHz to 1.2 GHz and a memory range from
256 MB to 1 GB RAM.
• It also provides a set of general purpose
input/output pins allowing you to control electronic
components for physical computing and explore the
Raspberry pi Diagram
Raspberry Pi model -
• There have been many generations of raspberry Pi from Pi 1
to Pi 4. There is generally a model A and model B.
Model A is a less expensive variant and it trends to have
reduce RAM and dual cores such as USB and Ethernet.
List of Raspberry pi models and releases year

• pi 1 model B - 2012 • Pi 3 Model B+ -2018


• pi 1 model A – 2013 • Pi 3 Model A+ -2019
• pi 1 model B+ -2014 • Pi 4 Model A - 2019
• pi 1 model A+ - 2014 • Pi Model B - 2020
• Pi 2 Model B - 2015 • Pi 400 - 2021
• Pi 3 Model B- 2016
The Raspberry Pi’s core components are shown in the Below figure
Top 6 Models of Raspberry Pi

1. Raspberry Pi Zero-
This is the cheapest Raspberry model produced by the company.
One can get it for as low as $5. The Raspberry Pi Zero does not
come with Wi-Fi or Bluetooth, but it can be made internet
accessible via USB.

2. Raspberry Pi 1
Raspberry Pi 1 Model B was released in 2012. Initially, it had 26
GPIO pins, 256MB RAM capacity, and a single CPU core.
In 2014, the Raspberry Pi B+ was released with a starting RAM
capacity of 512MB and 40 GPIO pins. Raspberry Pi Model B+
is sold at $25
3. Raspberry Pi 2 B
• In February 2015, Raspberry released the 2B model. Compared to
the prior releases, Raspberry Pi 2 B significantly improved,
specifically in memory and speed.
• The RAM capacity was increased to 1GB.
• Pi 2B comes in the standard size, with 4 USB ports.
• It is currently priced at about $35, which is pretty affordable.

4. Raspberry Pi 3
Raspberry Pi 3 B was released in 2016. The B+ version, which
came out in 2018.
Raspberry PI 3 offers the user a wide range of use. It comes with
the standard HDMI and USB ports, 1GB RAM, and Wi-Fi and
Bluetooth connections in addition to the already functional
Ethernet.
5. Raspberry Pi 4B
• Released in 2019, Raspberry 4B is a vast improvement from
its predecessors, with a varying memory capacity from 2GB
RAM to 8GB RAM.
• Pi 4B is an ideal Raspberry model as it is suitable for
virtually every use case with higher RAM capacity to satisfy
even the most dedicated programmers.

6. Raspberry Pi 400
• This model is unique as it comes in the form of a keyboard.
It was launched in 2020 and operated with 4GB RAM.
• It comes with standard USB ports and needs just a monitor
and mouse to make it a home computer set.
• Pi 400 costs $70 and can be used effectively in classrooms.
R Pi 3 hardware
• The Raspberry Pi 3 is a popular and versatile hardware
platform often used in Internet of Things (IoT) projects.
• Its small size, low cost, and connectivity options make it
suitable for a wide range of applications, according to various
sources.
• Here's a more detailed look at its hardware features and how
they contribute to IoT applications:

CPU and Memory:

• The Raspberry Pi 3 features a Broadcom BCM2837 SoC with


a quad-core ARM Cortex-A53 processor running at 1.2 GHz.
• It has 1 GB of LPDDR2 RAM.
2. Connectivity
• Wireless: Includes 802.11n Wi-Fi and Bluetooth 4.1 (BLE).
• Ethernet: A 10/100 Ethernet port for wired networking.
• GPIO: A 40-pin GPIO header for connecting various sensors
and peripherals.
• USB: Four USB 2.0 ports for connecting peripherals and
accessories.
• Video/Audio: HDMI and RCA output, plus a CSI camera
connector.
3. Storage:
• Uses a microSD card for operating system and data storage.

4. Power:
• Powered via a 5V 2.5A micro USB port.
5. Dimensions and Weight:
• Small size (85.60 mm × 53.98 mm × 17 mm) and light weight
(45 g).

How it's used in IoT


• Data Collection:
• Data Processing:
• Connectivity:
• Control and Automation:
• Development Platform:
Examples of IoT applications using Raspberry Pi 3:

Smart home automation (controlling lights, thermostats, etc.).

Environmental monitoring (collecting data from weather stations,


soil sensors, etc.).

Industrial IoT (collecting data from machines, controlling


processes, etc.).

Educational projects (teaching programming and electronics).


GPIO Pins
Basic of Linux commands
https://
www.slideshare.net/slideshow/unit-3-completepptx/251790912

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy