Accessing the Python interpreter
MicroPython
MicroPython implements the Python 3.4 syntax. It is Open Source and can be downloaded from its
GitHub repository . There are versions for different kinds of processors and descriptions on how to build and flash the interpreter. The ESP32 port is based on the ESP-IDF development environment provided by Espressif, the company behind the ESP processors. They also provide the
xtensa-esp32-elf-gcc cross compiler and associated libraries. Going into details on how we built the interpreter would go beyond the limits of what this course can teach. Let's suppose that the interpreter is already installed in the ESP32 flash and ready to run.
Details about MicroPython is found in its
documentation, which has a chapter dedicated to
ESP32 functionality.
For convenience a MicroPython firmware binary, as well as the scripts needed to erase the ESP32 flash and to program it with the firmware are given here:
https://iotworkshop.africa/pub/IoT_Course_English/AccessingThePythonInterpreter/firmware.bin
https://iotworkshop.africa/pub/IoT_Course_English/AccessingThePythonInterpreter/esp32_erase.sh
https://iotworkshop.africa/pub/IoT_Course_English/AccessingThePythonInterpreter/esp32_flash.sh
Instead of using the scripts you can also erase the flash with
make erase
After building the interpreter, you can flash it with
make deploy
Accessing the interpreter though the serial line
In order to connect to the ESP32 we need a serial terminal emulator like
minicom, gtkterm or seyon. Later on we will use
thonny as an editor to write our Python scripts and save them on the PC but also to connect to the ESP32 through
thonny's command window.
Here I give you an example how to configure
minicom for use with MicroPython on the ESP32. First you must start minicom as root with the option "-s":
minicom -s
Then you can save these settings as default when starting
minicom.
Finally you can start minicom normally without any options and you will see that MicroPython says "hello" with its characteristic prompt: ">>>".
In the screen dump below I typed the command
help()
and you see the first part of MicroPythons answer.
Now you can interact with MicroPython through its Read, Evaluate, Print Loop (REPL). Here a simple example:
--
Uli Raich - 2020-04-25
Comments