September 27, 2023

Within the first a part of the article , we’ve lined Micropython utilization with UiFlow and VS Code environments. In the second, we use C/C++ with extra granular system management. This time, we’ll attempt to run Micropython with an exterior library added.

Micropython with interactive console

There are two initiatives that allow Micropython for ESP32 to run exterior libraries. The primary one is M5Stack-official, and the second is unofficial The widespread half is – you possibly can run an interactive Micropython console on the controller utilizing the serial port. Sadly, that is the one solution to go. There isn’t a IDE and you may’t add a fancy, multi-file utility.

To open the console, you possibly can merely use Putty and connect with the correct COM port (COM3, in my case) with 115200 velocity.

To run the primary undertaking, one of the best ways is to observe the official README documentation, however there’s a bug within the code right here:

One file is opened in ‘w’ (write) mode and one other in ‘rb’ (learn bytes). You have to change ‘w’ to ‘wb’ to run any instance from the readme. It’s a superb codebase as a result of it’s small and M5Stack official. It accommodates upip, so you possibly can embody extra official libraries after connecting to the Web. It’s also possible to lengthen the codebase with extra libraries earlier than the construct (some additional libraries can be found in one other official repository Nonetheless, TensorFlow is a fancy library with a number of dependencies, so utilizing the unofficial undertaking is less complicated.

The Tensorflow Micropython Examples undertaking gives pre-built pictures to obtain instantly from GitHub. For our controller, you want the ESP32 model (no ESP32 S3) for 16MB reminiscence.

Simply open the GitHub Actions web page, choose the latest inexperienced construct and obtain the most recent model.

Micropython and C++

Then extract the zip package deal and burn it utilizing command ‘ -p /dev/ttyUSB0 -b 460800 –earlier than default_reset –after hard_reset –chip esp32 write_flash –flash_mode dio –flash_size detect –flash_freq 40m 0x1000 bootloader/bootloader.bin 0x8000 partition_table/partition-table.bin 0x10000 micropython.bin’. Guarantee you’ve gotten handed the USB port to WSL utilizing usbip and allowed all customers to make use of it with chmod (see the primary half for particulars).

With this undertaking, you possibly can import the microlite library, which is strictly the one you want – TensorFlow Lite for Microcontrollers. If you wish to lengthen this undertaking with your individual libraries, you possibly can add these to the cloned supply code and construct it with the next instructions:

git submodule init

git submodule replace --recursive

cd micropython

git submodule replace --init lib/axtls

git submodule replace --init lib/berkeley-db-1.xx

cd ..

supply ./micropython/instruments/ && ci_esp32_setup_helper v4.3.1

supply ./esp-idf/ #as you possibly can see, esp-idf is already included 

pip3 set up Pillow

pip3 set up Wave

rm -rf ./micropython-modules/microlite/tflm

cd ./tensorflow


cd ../micropython

make -C mpy-cross V=1 clear all

cd ../boards/esp32/MICROLITE_SPIRAM_16M

rm -rf construct clear construct

Your binaries are positioned below the boards/esp32/MICROLITE_SPIRAM_16M/construct listing.

This manner, you possibly can add extra libraries or your individual program to the picture, however you continue to want to make use of the interactive console to run it.


This three-part workshop aimed to make the most of M5Stack Core2 for AWS controller with AWS IoT connection and ML included. Let’s attempt to sum up all attainable methods to try this.

Language Administration methodology Execs Cons
Micropython UiFlow Python Low studying curve/simple UI OTA updates No Tensorflow obtainable Not sufficient for advanced use circumstances
VS Code with vscode-m5stack-mpi plugin Python Full IDE (Visible Studio Code) No Tensorflow obtainable
Tensorflow Micropython Examples Micropython with TensorFlow Lite for Microcontrollers Functionality to construct the undertaking with extra libraries or customized code included Necessity to run the code from interactive Python console.
C/C++ VS Code with PlatformIO and FreeRTOS All libraries obtainable Advanced code (C/C++) Advanced configuration
Arduino IDE All libraries obtainable Straightforward and highly effective sufficient IDE Arduino management loop limitation
ESP-IDF Small answer, with out even a devoted IDE (plugins for CS Code or Eclipse obtainable) Advanced dependency Administration

As you possibly can see, we’ve tried varied approaches and found their benefits and drawbacks. Now, you possibly can resolve if you want full management and use pure C/C++, or perhaps you like way more pleasant Python. You possibly can select which IDE or a minimum of plugin you’d like to make use of, and whether or not you wish to make the most of OTA to replace a complete firmware or solely to switch knowledge between your gadgets and the cloud.