Getting Started with AI/ML on Microcontrollers
Step-by-Step Guide to Setting Up and Running "Hello World with AI" on the ESP-EYE.
Hey ! This is where I share stuff about design, engineering of everyday things. Subscribe to get it all in your inbox! đ
Iâm starting learning about TinyML a.k.a âMachine Learning for Embedded Systemsâ, and Iâm logging my journey. This post is about how to setup your toolchain, and deploy the âHello Worldâ on the ESP-EYE.
BTW, I used Linux Terminal throughout the post. But I think you can easily this everything under Windows and macOS.
Install ESP-IDF Toolchain
Install IDF Toolchain unter Linux using docker. If you need to know how to install docker, read this.
docker pull espressif/idf
Thatâs all, but there is the option to use different versions. To download a specific docker image version or âtagâ, specify it as espressif/idf:TAG
, for example:
docker pull espressif/idf:release-v4.0
For more detailed info about ESP-IDF toolchain, you can read the ESP-IDF Programming Guide.
And if you want to dig more into IDF Docker you can follow this link.
Download Tensorflow Micro
clone the repository: https://github.com/espressif/tensorflow/
git clone https://github.com/espressif/tensorflow/
Hello World
Compile Hello World
Generate the âHello Worldâ example with the following command:
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_hello_world_esp_project
Go the the example project directory
cd tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32/prj/hello_world/esp-idf
Then build with idf.py
docker run --rm -v $PWD:/project -w /project espressif/idf idf.py build
Run Hello World
To flash your device (replace /dev/ttyUSB0 with the device serial port):
docker run --rm -v $PWD:/project -w /project --device=/dev/ttyUSB0 espressif/idf idf.py flash -p /dev/ttyUSB0
Workflow Inside A Docker Container
Sometimes is useful to work directly from Docker, for example for debugging purposes.
Letâs get inside the container:
docker run --rm -v $PWD:/project -w /project --device=/dev/ttyUSB0 -it espressif/idf
Now that youâre inside the container, you can run IDF commands directly:
idf.py build
idf.py flash -p /dev/ttyUSB0
If you want to see the debug output using the serial port. Note: you need use docker with --device=/dev/ttyUSB0
to be able to use monitor the serial port.
idf.py monitor
Use Ctrl+] to exit.
You could use combine the following commands:
idf.py --port /dev/ttyUSB0 flash monitor
You can find More info about IDF Monitor here.
Building more examples
You can more examples if you check the README files under
tensorflow/lite/micro/examples/<EXAMPLE_NAME>/README.md
.
These are the following examples available at the moment:
$ tree -L 1 tensorflow/lite/micro/examples/
tensorflow/lite/micro/examples/
âââ doorbell_camera
âââ hello_world
âââ image_recognition_experimental
âââ magic_wand
âââ micro_speech
âââ network_tester
âââ person_detection
âââ person_detection_experimental
8 directories, 0 files
This file
tensorflow/lite/micro/examples/hello_world/README.md
for instance, describes how to configure and build hello_world example.
Conclusion
TinyML is a new and growing field, for that reason itâs still evolving but that means that there is a lot room for improving, and most important. TinyML enables a new set of real-world applications.
I hope you enjoy this introduction. Until next time ;)
If youâre finding this newsletter valuable, share it with a friend, and consider subscribing if you havenât already.
Cheers,
Daniel! đ