Micropython New
Micropython New
Objectives:To become familiar with MicroPython and NodeMCU. Configure NodeMCU for
MicroPython.
Equipment/Instruments: NodeMCU 12E ESP8266 Board ,USB to Micro USB cable, Software-
PuTTY, PyFlasher
Theory:-
Micropython:
MicroPython is an implementation of Python 3, targeted for embedded systems and
microcontrollers. MicroPython and regular Python are very similar, so if you already know how
to write programs in Python, you already know how to program in MicroPython.
Micropython includes a small subset of the Python standard library, so not every module from
the standard library is available. However, MicroPython does include modules to access low-
level hardware, meaning there are modules to easily interact with GPIOs on microcontrollers.
MicroPython also comes with an interactive REPL (Read-Evaluate-Print Loop), which is an
often overlooked amazing feature of MicroPython. The REPL allows you to connect to a
microcontroller, execute code quickly without the need to compile or upload code. Which gives
immediate feedback on whether your program is working as intended.
ESP32/ESP8266:
The ESP32 and ESP8266 are low-cost Wi-Fi modules, perfect for DIY Internet of Things (IoT)
projects.Both come with general purpose input/output pins (GPIOs) and support a variety of
protocols, including SPI, I2C, UART, and more. The most attractive part of the ESP range is that
they come with wireless networking, separating them from their Arduino microcontroller
counterparts. All in all, the ESP series allows you to easily control/monitor devices remotely
using Wi-Fi for a very low price.
For this Experiment, we’ll be using the NodeMCU 12-E. We’ll be referencing this board and its
instructions for this particular Experiment.
The NodeMCU 12E ESP8266 Board.
Procedure:
1. Download the MicroPython Firmware
Before we connect the NodeMCU board to our PC, we need to download the most recent MicroPython
firmware and load it onto the NodeMCU. You can download it from the MicroPython download page
(https://micropython.org/download/#esp8266).
On the downloads page you’ll have 3 main choices:
Stable firmware builds for 1024kb modules and above,
Daily firmware builds for 1024kb modules and above,
Daily firmware builds for 512kb modules.
Select firmware builds for this Experiment.
2.Load Firmware Onto the NodeMCU
Once you have the firmware downloaded, it’s time to load it onto the NodeMCU board. There are two
main steps to achieve this:
Put NodeMCU into boot-loader mode
Copy across firmware to NodeMCU
To flash the MicroPython firmware onto the NodeMCU, you can choose following technique.
3.NodeMCUPyFlasher
A self-contained NodeMCU flasher with GUI that utilizes esptool.py and wxPython (Python GUI
library), developed by Marcel Stör. Use the latest release, which is available for Windows (.exe), macOS
(.dmg) and anything that runs Python.
Once you’ve plugged your NodeMCU, you should now be able to select the COM port that it is
connected on. If you don’t see it on this list, you may need to download the USB-Serial driver. Once the
driver is active, you will able to determine the COM port number by either selecting it in the drop-down
on NodeMCUPyFlasher or in your device manager (on Windows).
The window you'll see once you've successfully completed the firmware download.
REPL (Read Evaluate Print Loop) is the name given to the interactive MicroPython prompt that you can
access on the NodeMCU. Using the REPL greatly simplifies and speeds up testing out your code and
running commands.
While you can access the REPL over Wi-Fi (WebREPL), this article will only go into how to access the
REPL over a wired connection through the UART serial port.
To access the prompt over USB-serial, you will need to use a terminal emulator program. PuTTY is an
open source SSH and telnet client which you can use as a terminal emulator program to access your
NodeMCU REPL, otherwise, there is TeraTerm on Windows, built-in screen program on Mac and Linux
has picocom and minicom. There are many other terminal programs that will work, so choose your
favorite.
Once you have opened PuTTY for the first time, you will need to set up the settings configuration to
access the NodeMCU. First, we select a Serial connection type. Then, from step 3, we now know the
COM port number that the NodeMCU board is on (COM3 for this example). From there, we can set a
baud rate of 115200 and we are ready to connect. The settings can be saved as well for when you use it in
the future. The settings for this example can be seen below.
Once you connect you will be presented with a screen like below and can test out your code!
Once you're connected you'll be greeted with this screen.
Quiz:(Write your answers in separate page and attached the page with this manual)
1.What is MicroPython and how is it different from traditional Python?
2. What is NodeMCU and what are its features?
3. What are the advantages of using MicroPython with NodeMCU?
4. What is the process of configuring NodeMCU for MicroPython?
5. How do you connect NodeMCU to a computer for programming with MicroPython?
Experiment No: ___
Write program in MicroPython to send digital data on GPIO pins of
NodeMCU and glow LED connected with NodeMCU or any other
MicroPython supported board.Date(s).
Objectives:To become familiar with MicroPython and NodeMCU. Configure NodeMCU for
MicroPython.
Equipment/Instruments: NodeMCU 12E ESP8266 Board ,USB to Micro USB cable, Software-
PuTTY, PyFlasher
Micropython:
MicroPython is an implementation of Python 3, targeted for embedded systems and
microcontrollers. MicroPython and regular Python are very similar, so if you already know how
to write programs in Python, you already know how to program in MicroPython.
Micropython includes a small subset of the Python standard library, so not every module from
the standard library is available. However, MicroPython does include modules to access low-
level hardware, meaning there are modules to easily interact with GPIOs on microcontrollers.
MicroPython also comes with an interactive REPL (Read-Evaluate-Print Loop), which is an
often overlooked amazing feature of MicroPython. The REPL allows you to connect to a
microcontroller, execute code quickly without the need to compile or upload code. Which gives
immediate feedback on whether your program is working as intended.
ESP32/ESP8266:
The ESP32 and ESP8266 are low-cost Wi-Fi modules, perfect for DIY Internet of Things (IoT)
projects.Both come with general purpose input/output pins (GPIOs) and support a variety of
protocols, including SPI, I2C, UART, and more. The most attractive part of the ESP range is that
they come with wireless networking, separating them from their Arduino microcontroller
counterparts. All in all, the ESP series allows you to easily control/monitor devices remotely
using Wi-Fi for a very low price.
For this Experiment, we’ll be using the NodeMCU 12-E. We’ll be referencing this board and its
instructions for this particular Experiment.
The NodeMCU 12E ESP8266 Board.
Procedure:
1. Download the MicroPython Firmware
Before we connect the NodeMCU board to our PC, we need to download the most recent MicroPython
firmware and load it onto the NodeMCU. You can download it from the MicroPython download page
(https://micropython.org/download/#esp8266).
2.Load Firmware Onto the NodeMCU
Once you have the firmware downloaded, it’s time to load it onto the NodeMCU board. There are two
main steps to achieve this:
Put NodeMCU into boot-loader mode
Copy across firmware to NodeMCU
To flash the MicroPython firmware onto the NodeMCU, you can choose following technique.
3.NodeMCUPyFlasher
A self-contained NodeMCU flasher with GUI that utilizes esptool.py and wxPython (Python GUI
library), developed by Marcel Stör. Use the latest release, which is available for Windows (.exe), macOS
(.dmg) and anything that runs Python.
Once you’ve plugged your NodeMCU, you should now be able to select the COM port that it is
connected on. If you don’t see it on this list, you may need to download the USB-Serial driver. Once the
driver is active, you will able to determine the COM port number by either selecting it in the drop-down
on NodeMCUPyFlasher or in your device manager (on Windows).
Now just select your downloaded MicroPython firmware .bin file from the download location, select a
baud rate of 115200 (default for NodeMCU), using a dual I/O flash mode and click Flash NodeMCU.
After the process completes, you should see a screen like below.
The window you'll see once you've successfully completed the firmware download.
REPL (Read Evaluate Print Loop) is the name given to the interactive MicroPython prompt that you can
access on the NodeMCU. Using the REPL greatly simplifies and speeds up testing out your code and
running commands.
While you can access the REPL over Wi-Fi (WebREPL), this experiment will only go into how to access
the REPL over a wired connection through the UART serial port.
To access the prompt over USB-serial, you will need to use a terminal emulator program. PuTTY is an
open source SSH and telnet client which you can use as a terminal emulator program to access your
NodeMCU REPL, otherwise, there is TeraTerm on Windows, built-in screen program on Mac and Linux
has picocom and minicom. There are many other terminal programs that will work, so choose your
favorite.
Once you have opened PuTTY for the first time, you will need to set up the settings configuration to
access the NodeMCU. First, we select a Serial connection type. Then, from step 3, we now know the
COM port number that the NodeMCU board is on (COM3 for this example). From there, we can set a
baud rate of 115200 and we are ready to connect. The settings can be saved as well for when you use it in
the future. The settings for this example can be seen below.
Once you connect you will be presented with a screen like below and can test out your code!
Once you're connected you'll be greeted with this screen.
Since the NodeMCU 12E has on on-board LED attached to GPIO2, you can turn it on
and off using the following code:
>>>import machine
>>>pin = machine.Pin(2, machine.Pin.OUT)
>>>pin.on()
>>>pin.off()
the pin.on() may turn the LED off and pin.off() may turn the LED on (or vice versa)
depending on how the LED is wired on your board.
The code to make the LED connected to the NodeMCU flash.
--- Simulation of LED Blinking on https://micropython.org/unicorn/ ------
Quiz:(Write your answers in separate page and attached the page with this manual)
1. How do you configure NodeMCU for MicroPython, and what are the essential steps
involved?
2. What are GPIO pins, and how are they used to send digital data in MicroPython?
3. How do you write a program in MicroPython to send digital data on GPIO pins
ofNodeMCU, and what are the key syntax rules to follow?
4. Can you explain the process of connecting an LED to NodeMCU, and how do you make
it glow using MicroPython?
Write program in MicroPython to interface LED, ADC to NodeMCU and
using MicroPython supported board.
1.LED Blinking
2. ADC,PWM and LED