Micropython file set for the ESP32 MCU provides a lot of functionality

Micropython Programming: A Useful Collection for the ESP32 MCU

Micropython is a sub-set of the Python 3 programming language. Designed for ease of use on microcontrollers, it can be used as an operating system for the advanced ESP32 microcontroller.

The ESP32 with Micropython is essentially a complete computing system, and we often refer to it as a microprocessor rather than just a microcontroller. It actually has an operating system that allows you to create/delete directories and files.

We have created an educational kit for using Micropython with the ESP32, with a blind motor that you can use in your home. This is a great gift for anyone interested in learning how to use the ESP32. Please see the links at the bottom of this page for more info.

The table below displays a list of files preloaded onto the ESP32, with a description of the purpose of each file. This is the same list that will appear the first time that you successfully connect to your local WiFi network. After the first successful boot, you can still load the page with this command in the REPL interface:

>>> import home

Micropython File List


FILENAMEDESCRIPTION
The HOME Script:
home.py The home page (this page you are reading) is a special script that provides easy access to the files stored on this device. Some of the files can be run as stand-alone programs (under the categories of Actuators and Sensors), and others are support files (not stand-alone) that provide specific functions for other scripts.
Actuators: Blind Motor Control, Window Openers, Low Voltage Relays, LEDS:
motor.py Blind motor control with interactive slider. You can set the percentage of travel with the interactive slider, or roll the shade to its fully deployed or fully retracted position. You can also STOP the motor anywhere.
relays.py Relay module control (4 channel). These low voltage relays can be used to switch devices ON and OFF. They are used in the motor kit to trigger the group transmitter for motorized blinds and shades.
leds.py Stand-alone file that demonstrates control of GPIO pins in browser (can turn LEDS on/off). You would need to connect a LED (and resistor) to see it work.
start_oled_demo.py Stand-alone file that demonstrates OLED horizontal scrolling and static text display.
Sensors: Data Streaming Using Simulated Distance Sensor:
start_data_repl.py This is a demonstration of the absolute simplest form of sensor reporting, via the serial REPL communications console. It uses a randomized data source as a simulated distance sensor.
start_data_server.py This stand-alone file builds on the previous file, adding a browser screen that displays the real-time data stream in your browser and on the OLED display.
start_data_MQTT.py This stand-alone file adds another layer of reporting that that broadcasts sensor data via MQTT to an MQTT host. We use these devices to transmit sensor data to the Node-RED gauges running on the Raspberry Pi (or you can send the data to cloud displays such as Blynk and ThingSpeak).
start_email.py Stand-alone file sends email with authentication mail server. Typically used for email and text alerts regarding sensors.
System: Templates, Support & Resource Files:
LIB This is a library folder that contains system files. It is in the path by default, so you do not have to include it when calling a script.
start_ftp.py Stand-alone file that provides FTP capability for file transfers to and from the ESP32 MCU. This should be run stand-alone as it uses a lot of memory.
code_view.py This is the file that displays the raw, careully commented Micropython code. We have structured it to be the most readable, and most understandable, rather than the absolute fastest.
error_codes.py Stand-alone file that generates a list of possible operating system error codes. This can be useful for understanding errors that are generated by the try/except construct.
start_clock.py Stand-alone file that demonstrates code for real-time clock display that is updated by internet time standards, with alternative server backup. Has a good demonstration of Micropython string manipulation, generators with yield construct, and asynchronous timing behavior.
start_gpio_status.py Stand-alone file that shows status of GPIO pins in browser. A simple example of data display.
start_picoweb.py Stand-alone file that demonstrates Picoweb web server. It loads index.html as demo page, and we have included it in this section as it is often used for data display.
index.html Demo HTML file for display on Picoweb, a compact but powerful web server. You can run the file start_picoweb to see it displayed by the web server.
start_wifi.py Stand-alone file that connects to station mode WiFi router specified by direct coding. Edit this file by inserting your WiFi network settings (SSID and PWD)
start_ap_mode.pyStand-alone WiFi file that starts WiFi AP (Access Point) mode, while also running in Station mode. The ESP32 is capable of running AP mode and Station mode simultaneously!
start_form.py Stand-alone file demonstrates HTML FORM POST method of user input. For example, it could be used for WiFi config settings. It also contains an example of socket timeout structure (auto-reboot disabled).
template_boot_notice.py Template file that is used to display notice of manual reboot requirement by user. Used when there is not enough memory (or there is a conflict) that prevents use of socket web server to provide countdown screen to return to home page when script is terminated.
template_reboot.py Stand-alone file demonstrates HTML FORM POST method of user input. This template file loads socket web server for browser screen display, and also provides countdown screen to return to home page when script is terminated.
test_json.py Stand-alone file that tests for retrieval of json key/value pairs from designated file.
boot.py System file that always executes first when the microcontroller boots up. It is better to put any code to be auto-loaded in main.py because it can be interrupted with a CTRL-C serial REPL command (boot.py cannot be easily interrupted).
connect_wifi.py WiFi file that attempts to connect at boot time. It will try 30 times to connect. If it fails, it will launch config_wifi.py so that the user can enter WiFi network settings for SSID and PWD.
config_wifi.py WiFi configuration file that is launched if connect_wifi.py file fails to connect. It prompts the user to enter the local WiFi network connection parameters (SSID, PWD).
config.txt Configuration file that contains json key/value pairs re board settings, such as WiFi connection settings.
constants.py System file that has i2c pin configuration and other ESP32 board settings stored as constants. Please enter your Wifi SSID and PWD at the top of this file as it is used by certain emergency restoration files, such as start_wifi.
main.py System file that (if it exists) is always executed after boot.py at boot time. It is usually the best place to put any auto-executing code at boot time as it can be interrupted by serial REPL command (CTRL-C).
webrepl_cfg.py System file that contains webREPL password when the microcontroller boots up with boot.py.

You can purchase educational kits for blinds and window openers, and our control products in our online DIY automation store.

Stay tuned, if you're interested; we are taking the journey into IoT and automation, writing about every step we take!

Adrian Biffen
Senior Partner
RollerTrol Automation Systems

We sincerely hope you enjoy our advanced technology products; if you have any questions, please contact us at any time!

Articles in this series:

Part 1: Micropython for the ESP32: Connecting to Your WiFi Router Network

Part 2: Micropython for the ESP32 Microcontroller: REPL Communications

Part 3: Micropython for the ESP32: FTP Fast File Transfer

Part 4: Micropython for the ESP32: Pre-loaded Programs (you are here)

Part 5: Micropython for the ESP32: DC Motor Reversing Switch

Part 6: Micropython for the ESP32: WiFi Blind Motor Educational Kit Components

Part 7: Micropython for the ESP32: Error Codes and Definitions