Elektor ESP32 Programming Micro Controllers in Micro Python

Техникалык шарттар
- Продукт аты: Programming Microcontrollers in MicroPython
- Author: Clemens Valens
- Examples үчүн: Raspberry Pi Pico and ESP32
- ISBN: 978-3-89576-722-7 (Print), 978-3-89576-723-4 (eBook)
- Жарыялоочу: Elektor International Media BV
Продукт колдонуу нускамалары
- Introduction
- Welcome to the guide on programming microcontrollers in MicroPython. This guide provides examples for using MicroPython with Raspberry Pi Pico and ESP32.
- Баштоо
- Before you begin, ensure you have the necessary hardware, such as Raspberry Pi Pico or ESP32 board, and the book “Programming Microcontrollers in MicroPython.”
- Programming Microcontrollers
- Follow the step-by-step instructions provided in the book to program microcontrollers using MicroPython. The book includes examples and explanations to help you understand the concepts.
- Кошумча ресурстар
- For additional resources and support, visit the Elektor website at www.elektor.com.
Көп берилүүчү суроолор
1. Can I use this book for programming other microcontrollers?
мурдагыamples and instructions in this book are specifically tailored for Raspberry Pi Pico and ESP32. While some concepts may apply to other microcontrollers, it is recommended to refer to specific documentation for different models.
2. Is prior programming experience required?
Basic programming knowledge is beneficial but not mandatory. The book includes beginner-friendly examples to help you get started with MicroPython programming.
“`
Introduction
The Makerfabs MakePython ESP32 Kit intended to help learners getting started with MicroPython on the ESP32. This Kits includes the most common electronic components and modules, for the starters to learn the basic knowledge of MicroPython and usage of uPyCraft IDE. 12 basic lessons help starters to learn the usage and program skills about MicroPython.
The total learning time for this kits& lessons is about 20 hours.
What is MicroPython?
Python is one of the most widely use simple and easy-to-learn programming languages around.
MicroPython is a lean implementation of the Python 3 programming language that has been pared down to run efficiently on microcontrollers. It is a relatively simple but powerful language that is easy for beginners to pick up and has been gaining popularity in schools as an introductory language. MicroPython has nearly all of the features of Python, which means that interacting with hardware is now easily accessible to beginners and seasoned Python programmers alike.
MicroPython goal is to make programming digital electronic as simple as possible, so it can be used by anyone. Currently, MicroPython is used by hobbyists, researchers, teachers, educators, and even in commercial products.
Продукт тизмеси

Makerfabs MakePython ESP32 Pin figure:

MicroPython Development Tool
Installing uPyCraft IDE Windows PC
There many codes& programming methods with MicroPython. For this tutorial, we use uPyCraft IDE, which is the most simple& easy way for starts to skip into MicroPython. You can learn more about uPyCraft IDE on their GitHub repository or explore the uPyCraft IDE source code. Click this link to download uPyCraft IDE for Windows: https://randomnerdtutorials.com/uPyCraftWindows.
After a few seconds you should see a similar file (uPyCraft_VX.exe) in your Downloads folder
Double-click that file. A new window opens with the uPyCraft IDE software.
A Simple code for blinking an LED on ESP32 as follows:
Get Start with uPyCraft IDE
Open uPyCraft IDE. Let’s take a closer look at each section of uPyCraft IDE:
1->Folder and files
2->Editor
3->MicroPython Shell/Terminal
4->Tools
a. Folder and files
This section shows several folders and files. The device folder shows the files that are currently stored on your ESP board. If you have your ESP32 connected via serial to uPyCraft IDE, when you expand the device folder, all files stored should load. By default, you should only have a boot.py file. To run your main code, it is recommended to create a main.py file.
boot.py: runs when the device starts and sets up several configuration options;
main.py: this is the main script that contains your code. It is executed immediately after the boot.py.
The sd folder is meant to access files stored on SD cards this is only works with boards like the PyBoard that come with an SD card slot.
The uPy_lib shows the built-in IDE library files.
The workspace is a directory to save your fileс. Булар files are saved in your computer in a directory defined by you. This is a special useful to keep all your files organized at hand.
When using uPyCraft for the first time, to select your working directory, click the workspace folder. A new window pops up for you to choose your workspace path. Create a new folder or select an existing folder to be your working directory.
Андан кийин, барыңыз File > Reflush Directory to update the directory.
*Note: to change your user directory, simply go to Tools >InitConfig and click the workspace directory folder to choose a different path.
b. Editor
The Editor section is where you write your code and edit your .py files. You can open more than one file, and the Editor will open a new tab for each file.
c. MicroPython Shell/terminal
On the MicroPython Shell you can type commands to be executed immediately by your ESP board without the need of uploading new files. The terminal also provides information about the state of an executing program, shows errors related with upload, syntax errors, prints messages, etc…
d. Tools
The icons placed at the rightmost side allow you to quickly perform tasks. Each button is labeled in the figure below:
Жаңы file: creates a new file on the Editor;
Open file: open a file from your computer;
Save file: saves a file;
Download and run: upload the code to your board and execute the code;
Stop: stop the execution of the code – it’s the same as entering CRTL+C on the Shell to stop all scripts from running;
Connect/Disconnect: connect or disconnect to your board via Serial. You must select the serial port first in Tools > Serial;
Undo: undo last change in the code Editor;
Redo: redo last change in the code Editor;
Syntax check: checks the syntax of your code;
Clear: clear the Shell/terminal window messages.
Establishing a communication with the board
After having the MicroPython firmware installed (MicroPython Firmware already installed when you get
Makerfabs MakePython ESP32), connect it to your computer through an USB cable, follow the steps:
1. Tools > Board and select the board you’re using. Select the esp32
2. Go to Tools > Serial and select the com port your ESP is connected to(download the USB driver at: https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)
3. Press the Connect button to establish a serial communication with your board.
You will see “>>> “ appear in the Shell window after a successful connection with your board. You can type the print command to test if it’s working. Try to print: >>>print(“hello, world”)
It should print the “Hello,World” message. Only if you see that message, you can continue with this tutorial. Otherwise, make sure you have established a serial communication with your board or that you’ve flashed successfully the MicroPython firmware on your board.
Creating the main.py file on your board
1. Press the “New file” button to create a new file.
2. Press the “Save fileсактоо үчүн ” баскычын басыңыз file сиздин компьютериңизде.
3. A new window opens, name your file main.py and save it in your computer:
4. After that, you should see the following in your uPyCraft IDE (the boot.py file in your device and a new tab with the main.py file):
5. Click the “Download and run” button to upload the file to your ESP board
6. The device directory should now load the main.py file. Your ESP has the file main.py stored.
Uploading the first Script: Blinking LED
Ok, so let’s begin to try to upload a very basic LED blink script into MakePython ESP32 board.
1. Copy the following code to the Editor on the main.py file:
2. Press the “Stop” button to stop any script from running in your board
3. Click the “Download and Run button” to upload the script to the ESP32.
4. You should see a message saying “download ok” in the Shell window, it means that the updates succeed.
To run the script that was just uploaded to your board, you need to press the “Stop” button, then press the on-board ESP32 RST (RESET) button to restart your board and run the script from the start.
If you want to run the program on power, you can write code in the main.py file
* Note that when there much files in your MakePython boards, it is suggested to delete un-necessary files. Right click the file and select the “delete” to delete these files.
MakePython Lessons
1. Lesson1: LED Control
This is the most basic lesson, in which we will learn how to control the digital output pins with
MicroPython, by control the lighting of an LED.
Материал:
1*LED;
Resistor: 1*330R;
Jump wires;
Instructions: The short pin on the left is negative and the long pin on the right is positive.
The purpose of resistor is to limit the current, avoid burning LED lamp with too much current.
Wiring: Connect the long LED pin to the end of the 330R resistor, the other end of the resistance is connected to 3.3v, the short pin of the LED lamp is connected to the IO5 of ESP32. As follows:
түзүү а file:Open the uPyCraft IDE by clicking , and click save ,to name the Settings file, select your own save path. You can then program in the LED documentation:
*Note: The first time you open the uPyCraft IDE, the workSpace path does not exist. When you click, the workSpace dialog
box will pop up. You can create a workSpace directory to store the user’s files by selecting the directory you want to store.
Code and comments:
import time #use the time class from machine import Pin #use the machine.Pin class led=Pin(5,Pin.OUT) #create LED object from pin5,Set Pin5 to output try:
while True: #repeat the following code led.value(1) #turn off (Set high level) time.sleep(0.5) #waiting for 0.5 seconds led.value(0) #turn on (Set low level) time.sleep(0.5) #waiting for 0.5 seconds except KeyboardInterrupt: pass
Grammar explanation:
led=Pin(5,Pin.OUT):
Create an LED object and set it to output mode
while:
Used to loop through a program, that is, under certain conditions, loop through a segment of a program to handle the same task that needs to be processed repeatedly
led.value(1):
Set the led pin value to high level. Since the other pin is connected to 3.3v, there is no voltage difference between the two pins.
led.value(0):
Set the pin value to low level, there is a voltage difference between two pins, there is a current through, the LED light is on.
time.sleep(0.5):
Delay 0.5 seconds, in this time the control will be sleep and do nothing.
The experimental results:
Click the to save and the to run, you will see the LED lights blinks with interval of 0.5 seconds.
You can try changing it to other pins yourself. For example, change to led=Pin(4,Pin.OUT) , then connect the wire to IO4, and the light will flash, or the delay is changed to time.sleep(1),The light flickers slowly, with interval of1s. You can also try to increase the number of LED lights and keep them on and off.
Кеңейтүү:
You can also control the LED lighting by sending command through serial port.
*Note: If your lights are still flashing, that means the code is still running, press to stop the program running. Write the code after “>>>” and press enter after each line:
Description:
This MakePython ESP32 Kits includes the basic components and guidance for MicroPython starters. With the 12 experiments in this guide, you will be able to make simple electronic projects with MicroPython on ESP32, and the basic knowledge& usage of IOT projects.
About Makerfabs
Makerfabs is open hardware facilitator based on Shenzhen, China, We make open hardware projects and help our customers project prototyping& small batch production, includes PCBA/ Molding/ OEM. Contact service@makerfabs.com көбүрөөк маалымат үчүн.
Документтер / Ресурстар
![]() |
Elektor ESP32 Programming Micro Controllers in Micro Python [pdf] Колдонуучунун колдонмосу ESP32 Programming Micro Controllers in Micro Python, ESP32, Programming Micro Controllers in Micro Python, Micro Controllers in Micro Python, Controllers in Micro Python, in Micro Python, Python |

