Python Lab Manual - EC - Dept
Python Lab Manual - EC - Dept
Laboratory Manual
_______________________________________________________________________
B.E____________________
Prof._________________________
Sign _____________________
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.
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.
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.
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.
Remarks:
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:
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:
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.
Note: The code is for only reference. The students are instructed to follow their own code.
Remarks:
Objective: Function calling is an import feature in python programing. Here students will understand
basics, types of function and use of various function types.
Note: The code is for only reference. The students are instructed to follow their own code.
Remarks:
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.
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.
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.
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:
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.
Step 1: Open Explorer connect NodeMcu, select baud rate 11500 , upon hard ware reset of NodeMcu , one
can see the python version on display.
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:
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.
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.
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.
Here, upon changing the pwm2 parameter LED blinking should be affected. Try to make changes and observe
the output.
Remarks: