Bahria University
H-11 Islamabad Campus
Internet of Things (IOT) LAB
EXPERIMENT # 01: Introduction to Thonny IDE, Micropython and ESP tools
Name of Student: …………………………………..
Roll No.: ……………………………………………
Date of Experiment: ………………………………..
Report submitted on: ………………………………..
Marks obtained: ……………………………………
Remarks: ……………………………………………
Instructor’s Signature: ……………………………...
Internet of Things (IOT) Lab [CEL-449]
Introduction to Thonny IDE, Micropython and ESP Tools
Objectives:
The objective of this lab is to familiarize students with Thonny IDE, MicroPython, and ESP tools for
programming ESP32/ESP8266 microcontrollers. Students will learn to install and configure Thonny
IDE, flash MicroPython firmware onto ESP boards, write and execute MicroPython scripts, establish
serial communication, and control GPIOs.
Introduction:
The Internet of Things (IoT) refers to a network of interconnected devices that communicate and
exchange data over the internet. These devices, equipped with sensors, microcontrollers, and actuators,
collect and transmit real-time data for automation, monitoring, and decision-making. IoT applications
span various fields, including smart homes, industrial automation, healthcare, agriculture, and
transportation.
Thonny IDE plays a crucial role in IoT development by providing a beginner-friendly environment
for programming microcontrollers like ESP32 and ESP8266 using MicroPython. It simplifies coding,
debugging, and firmware management, making it easier for developers and hobbyists to build IoT
applications. Thonny IDE supports direct interaction with IoT hardware via a built-in REPL console,
allowing real-time testing of scripts. With features like automatic device detection, syntax
highlighting, and error tracking, Thonny IDE enhances the efficiency of IoT development, enabling
seamless integration of sensors, actuators, and cloud services in smart systems.
What is MicroPython?
MicroPython is a lightweight implementation of the Python 3 programming language, specifically
designed for microcontrollers and embedded systems. It provides a simple and efficient way to
program microcontrollers like ESP32, ESP8266, STM32, and Raspberry Pi Pico using Python
syntax.
Key Features of MicroPython:
•
Compact and optimized to run on low-memory devices.
•
Provides built-in libraries for handling hardware components such as GPIOs, UART, I2C,
SPI, and PWM.
•
Includes an interactive REPL (Read-Eval-Print Loop) for real-time coding and debugging.
•
Allows scripting without compiling, making development faster and more user-friendly.
•
Supports file system operations, enabling data logging and storage on microcontrollers.
Internet of Things (IOT) Lab [CEL-449]
Why Use MicroPython?
MicroPython simplifies embedded system programming by eliminating the complexities of low-level
languages like C or C++. It is widely used in IoT, robotics, and automation applications due to its
ease of use, fast development cycle, and extensive Python ecosystem.
Lab Tasks
Task 1: Installing and Setting Up Thonny IDE
1.
Download and install Thonny IDE from https://thonny.org.
2.
Open Thonny IDE and configure MicroPython (ESP32/ESP8266) as the interpreter.
3.
Connect the ESP board to the computer via USB.
4.
Verify that Thonny detects the board under Tools → Options → Interpreter.
Task 2: Flashing MicroPython Firmware onto ESP Board
1.
Download the latest
https://micropython.org/download.
2.
MicroPython
firmware
for
ESP32/ESP8266
Install esptool.py using the command:
pip install esptool
3.
Erase the existing firmware on the ESP board using:
esptool.py --port COMx erase_flash
(Replace COMx with the actual port of the ESP board.)
4.
Flash the new MicroPython firmware:
esptool.py --port COMx --baud 115200 write_flash --flash_size=detect 0x1000 firmware.bin
5.
After successful flashing, restart the ESP board.
Task 3: Writing and Executing MicroPython Scripts in Thonny
1.
Open Thonny and select MicroPython (ESP32/ESP8266) as the interpreter.
2.
Connect to the ESP board and open the REPL (Read-Eval-Print Loop) console.
3.
Run a simple MicroPython script:
Code: print("Hello, MicroPython!")
Guide Link: https://www.youtube.com/watch?v=5ILcJ81I1Ww
Internet of Things (IOT) Lab [CEL-449]
from