ESP32 On-board LED Blinking With MicroPython and Mu Editor

by iTronify in Circuits > Microcontrollers

588 Views, 0 Favorites, 0 Comments

ESP32 On-board LED Blinking With MicroPython and Mu Editor

mueditor4.png

Make the on-board LED on your ESP32 development board blink with MicroPython.

Supplies

ESP32 development board with MicroPython installed

Micro USB cable (make sure it is a data cable and not a power-only cable!)

"Mu Editor" MicroPython IDE installed

Introduction

You have prepared a MicroPython script and are ready to run it on you ESP32 (development board). You want the ESP32 to run without being connected to your computer. After testing and debugging it is ready to be flashed to your ESP32 development board.

In this tutorial we will use the "Mu Editor" IDE to write and run our MicroPython script.

Prerequisites

Before running into further troubleshooting, make sure following prerequisites are met:

  • You need an ESP32 (development board) with MicroPython installed. We use the ESP32-DevKit-V1.
  • You need a micro-USB cable supporting data-transfer. Power-only cables will not work.

Write the Script

We wrote a MicroPython script to make the on-board LED blink. The on-board LED is connected to GPIO2 so it is easy to control.

Our script is very easy:


from machine import Pin

from time import sleep


led = Pin(2, Pin.OUT)

while True:

led.value(not led.value())

sleep(0.5)

Flash the Script to the ESP32 Development Board

When saving your script, you need to save it with name "main.py". If you give it another name, it will not run automatically.

We save our script in a folder called "Blinking LED".

We save the file as "main.py" and click on "Files":

In the "Files on your computer" box, you right-click on "main.py" and choose "Write to main.py on device".

If flashing succeeded, the file will appear in the "Files on your device" section:

Press the on-board "EN" or "RST" button to restart your ESP32 development board. Only after pushing this button, the script will run independent on the ESP32.