0% found this document useful (0 votes)
97 views

Python Lab Manual - EC - Dept

The document is a laboratory manual for a Python Programming course offered at G.E.C. Modasa. It contains instructions for 13 practical exercises for students to complete, ranging from installing Python and Anaconda to plotting data using Matplotlib and creating functions. It also includes steps to flash a NodeMCU microcontroller with MicroPython firmware to enable Python programming of embedded devices. The manual contains certifications, indexes, and spaces for student details, dates, marks, and signatures against each completed practical.

Uploaded by

carry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Python Lab Manual - EC - Dept

The document is a laboratory manual for a Python Programming course offered at G.E.C. Modasa. It contains instructions for 13 practical exercises for students to complete, ranging from installing Python and Anaconda to plotting data using Matplotlib and creating functions. It also includes steps to flash a NodeMCU microcontroller with MicroPython firmware to enable Python programming of embedded devices. The manual contains certifications, indexes, and spaces for student details, dates, marks, and signatures against each completed practical.

Uploaded by

carry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Python Programming

Subject Code: 3151108


Semester: V
E.C. Department, G.E.C. Modasa

Laboratory Manual

The Department Of Electronics and Communication , G.E.C. Modasa 1


CERTIFICATE

This is to certify that Mr. /Ms. _____________________________________________

_______________________________________________________________________

Enrollment no._______________________ of Seventh semester of

B.E____________________

Class has completed his/her one full semester in “ Python Programming”

satisfactorily in partial fulfillment of

Bachelor of Electronics and communication Engineering degree to be

awarded by Gujarat Technological University.

Prof._________________________

Sign _____________________

Date: - .... /... /.......

The Department Of Electronics and Communication , G.E.C. Modasa 2


INDEX

Sr. No Practical Title Date Marks Signature

1 Install python and anaconda and test it.

2 Write programs to elaborate use of python data type with


type casting
3 Write programs to elaborate use of python strings , its
indexing and slicing
4 Use conditional Statement and loops in python

5 Write programs to plot data using pyplot

6 Write a programs to elaborate use of python function

7 To become familiar with MicroPython and NodeMCU.


Configure NodeMCU for MicroPython.
8 To use WEBREPL and ESPLORER to load mcu

9 To make use inbuilt LED and blink

10 To change the PWM of inbuilt LED and control Via


switch
11 Mini Project on Micropython

The Department Of Electronics and Communication , G.E.C. Modasa 3


Practical 1

Aim: To Install python and anaconda and test it.

Objective: To get students familiarize with python environment along with the Anaconda.

Python is open source and can be downloaded freely. The anaconda is a free and open-source distribution of
the Python and R programming languages for scientific computing, that aims to simplify package management
and deployment.

Steps for Python download and installation


Step 1: Visit: https://python.org and go to the downloads tab. A drop-down will open and you will be asked
to select the version to be installed.

Step 2: Once the download has completed, go to the folder where the installation (setup) file has been saved.
Click that and start the installation process on your windows system.

Step 3: Begin installation. Just create one folder in c drive and install in that folder. Do not forget to
checkmark add to environment variable option. Click next and wait till installation is complete.

The Department Of Electronics and Communication , G.E.C. Modasa 4


Step 4: Open command prompt and type python. Is everything is installed correctly python version should
prompt. In other case you may Open python IDLE and check if it is properly installed.

Steps to install anaconda:

If you install python, while using other library you need to install support packages. Beginners can make use
of anaconda where pre install packages are already install. Here are steps to use anaconda. For the beginning
we will be using Jupyter notebook environment to learn Python.
Steps to install anaconda:
Step 1: Go to https://anaconda.org/ and select the required graphical installer and download it . In most of
the cases it will be Python 3.8 64-Bit Graphical Installer

Step 2: Select the default options when prompted during the installation of Anaconda.

Step 3: Please select anaconda to add in environment variable option.

The Department Of Electronics and Communication , G.E.C. Modasa 5


Step 4: open anaconda navigator, and then Jupyter Notebook.

Step 5: In Jupyter notebook start new note book.

The Department Of Electronics and Communication , G.E.C. Modasa 6


Practical 2

Aim: Write programs to elaborate use of python data type with type casting

Objective: To understand various data types of python and conversion and typecasting.

The Department Of Electronics and Communication , G.E.C. Modasa 7


Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 8


Practical 3

Aim: Write programs to elaborate use of python strings, its indexing and slicing

Objective: Indexing and string slicing are one of the more powerful feature of python programming. The
practical aims to provide understanding and practice for same.

Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 9


Practical 4

Aim: Write programs to elaborate Use Conditional Statement and loops in python

Objective: Conditional statements and loops are very powerful feature of any programming language. The
aim of this practical is to understand the loops and conditional statements.

Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 10


Practical 5

Aim: Write programs to plot data using pyplot

Objective: Plotting and data analytics is one of the key usage of python in real world. This practical aims
to demonstrate the use of pyplot. Those using the python IDLE will have to install supportive package.
Those who are using notebook environment can continue by calling pyplot.

The Department Of Electronics and Communication , G.E.C. Modasa 11


Note: one need to create an excel file to the notebook folder location in order to read and use it.

Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 12


Practical 6

Aim: Write a programs to elaborate use of python function

Objective: Function calling is an import feature in python programing. Here students will understand
basics, types of function and use of various function types.

The Department Of Electronics and Communication , G.E.C. Modasa 13


The Department Of Electronics and Communication , G.E.C. Modasa 14
Note: Design small application using the understanding of functions and user inputs

Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 15


Practical 7

Aim: To become familiar with MicroPython and NodeMCU. Configure NodeMCU for MicroPython.

Objective: Nodemcu is one of the widely use IOT device. Micropython is an embedded version of python.
It aims to use the ease of python for the single device applications. Students can first learn how to flash
micropython to Nodemcu.

By default NodeMcu comes with lua firm ware. So one needs to flash MCU with micropython firm ware. For
that purpose we can make use Esplorer and nodemcu falsh master software for windows. However using
python pip command one can flash the Node mcu.
Esplorer : https://esp8266.ru/esplorer/
MCU flasher: https://github.com/nodemcu/nodemcu-flasher
Steps to flash Node mcu:
Step 1: go to https://micropython.org/ and from download select Node MCU. Select latest stable micropython
binary file and download and store it.

Note: For next steps make sure you have installed JAVA on your computer.

The Department Of Electronics and Communication , G.E.C. Modasa 16


Step 2: Connect Node mcu with laptop/Pc and open Esplorer software

Step 3: Connect Node MCU with pc. Open device manager and identify the com port. Select the same com
port and reset hardware. Select baud rate 9600.

Note : If you have already flashed Nodemcu , you will most likely receive above message. In that case use
Node mcu flasher leave everything same and proceed. Do not forget to close Esplorer while doing this.

The Department Of Electronics and Communication , G.E.C. Modasa 17


Step 4: Flashing lua tonode mcu

Step 5: Use same procedure to see lua version on Esplorer. Close Espolorer. Open flasher programe. Go to
config , use it to divert and open binary file for micro python already downloaded. And flash it.

Step 6: Open Esplorer and use baude rate of 11500. Upon reset you should see the python version.

Note: if above method do not work for you. Try alternate method provided below.

The Department Of Electronics and Communication , G.E.C. Modasa 18


Step 1: Open command prompt. Type python , if python added to environment you should see a version of
python promt.

Step 2: use command, pip install esptool ( In case pip isn’t recognized use. CD.. to divert to folder where
python pip is installed)

Step 3: esptool.py --port COMX erase_flash ( Press and hold FLash while erasing firmware)

Step 4: Use following command. Make necessary change about file name and location when needed.
esptool.py --chip esp8266 --port COM8 write_flash --flash_mode dio --flash_size detect 0x0 esp8266-
20191220-v1.12.bin

Note: Please verify file name, location well in advanced using ls command.

Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 19


Practical 8

Aim: To use WEBREPL and ESPLORER to load mcu

Objective: REPL stands for Read Evaluate Print Loop, and is the name given to the interactive MicroPython
prompt that you can access on the ESP8266. Using either WebREPL or local REPL one can easily access the
Node Mcu. Purpose of this practical is to elaborate the use of REPL.

To access the NodeMcu via REPL follow the steps

Step 1: Open Explorer connect NodeMcu, select baud rate 11500 , upon hard ware reset of NodeMcu , one
can see the python version on display.

The Department Of Electronics and Communication , G.E.C. Modasa 20


Step 2: At the bottom of REPL you will send option to NodeMcu. Type following command.
import_webrepl setup

Step 3: after the above command it will ask you to either enable or disable the REPL type E and send.
Step 4: upon asking the password type Y and set a password.
Step 5: Close Explorer. Open wifi setting of computer. Select NodeMcu or in Some cases Node. By default,
password would be micropythoN
Step 6: Opne Webrepl client. Click on connect. Use password given in step 4.

Note: The code is for only reference. The students are instructed to follow their own code.
Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 21


Practical 9

Aim: To make use inbuilt LED and blink

Objective: By using the ESPLORER one can blink the onboard LED. We need to import machine, Port and
Time class in order to complete the task. Objective behind this practical is to understand calling of packages
and class and also understand the onboard LED port usage.

Steps to perform practical:

Step 1: open Esplorer and start go to setting and uncheck NodeMcu and select micropython.

import time
import machine
pin = machine.Pin(2,machine.Pin.OUT) $ built in LED
while True:
pin.on()
time.sleep(1)
pin.off()
time.sleep(2)

Here , time.sleep() will generate number of seconds delay. pin.on() either turn off or turn on the LED based
on the wiring of the boards. Upon loading the code , hardware reset the board you should see led blinking at
2 seconds delay forever.

Step 2: Go to script. And start typing above command.


Step 3: After which use send to ESP button available at the bottom
Step 4: You should see the sent code on left hand side display. Upon reset LED should glow appropriately
Note: The code is for only reference. The students are instructed to follow their own code.
Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 22


Practical 10

Aim: To change the PWM of inbuilt LED and control Via switch

Objective: PWM is an important feature for many practical applications. The practical aims to explore the
concepts.

Step 1: open Esplorer and start go to setting and uncheck NodeMcu and select micropython.

from machine import Pin, PWM


pin = machine.Pin(2,machine.Pin.OUT) $ built in LED
pwm0 = PWM(Pin(0)) # create PWM object from a pin
pwm0.freq() # get current frequency
pwm0.freq(1000) # set frequency
pwm0.duty() # get current duty cycle
pwm0.duty(200) # set duty cycle
pwm0.deinit() # turn off PWM on the pin
pwm2 = PWM(Pin(2), freq=500, duty=512) # create and configure in one go

Here, upon changing the pwm2 parameter LED blinking should be affected. Try to make changes and observe
the output.

Step 2: Go to script. And start typing above command.


Step 3: After which use send to ESP button available at the bottom
Step 4: You should see the sent code on left hand side display. Upon reset LED should glow appropriately
Note: The code is for only reference. The students are instructed to follow their own code.

Remarks:

The Department Of Electronics and Communication , G.E.C. Modasa 23

You might also like