Tags:
create new tag
view all tags

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

minicomConfig.png

 

Then you can save these settings as default when starting minicom.

minicomSave.png

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.

minicomHelp.png

Now you can interact with MicroPython through its Read, Evaluate, Print Loop (REPL). Here a simple example:

microPythonSession.png

-- Uli Raich - 2020-04-25

Comments

Topic attachments
I Attachment History Action Size Date Who CommentSorted ascending
Unix shell scriptsh esp32_erase.sh r1 manage 0.2 K 2020-05-07 - 10:01 UliRaich  
Unix shell scriptsh esp32_flash.sh r1 manage 0.2 K 2020-05-07 - 09:58 UliRaich  
Unknown file formatbin firmware.bin r2 r1 manage 1457.6 K 2020-05-23 - 10:36 UliRaich  
PNGpng microPythonSession.png r1 manage 60.7 K 2020-04-25 - 19:46 UliRaich  
PNGpng minicomConfig.png r1 manage 43.0 K 2020-04-25 - 18:28 UliRaich  
PNGpng minicomHelp.png r1 manage 57.7 K 2020-04-25 - 18:28 UliRaich  
PNGpng minicomSave.png r1 manage 15.1 K 2020-04-25 - 18:28 UliRaich  
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2021-07-26 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback