Tags:
create new tag
view all tags

Communicating with MicroPython

First steps

You do not know the Python? No problem! We will go through some of the basics.

Python is a very powerful, modern programming language, which is supported by a big number of code libraries, extending its capabilities. Like with natural languages, you will not master it in just a few hours. However, Python has the reputation of being easy to learn. During the lectures, we will see some of the basics programming features, just enough allowing us to work on the exercises.

Python is an interpreted language, meaning that unlike for C, C++, Pascal, Fortran ... our programs do not need to be compiled before being executed. You can talk to the interpreter through REPL, the Read, Eval, Print Loop directly. Standard Python (CPython) is quite resource hungry, resources that are not available on microcontrollers. Therefore, we use a stripped down version of Python, MicroPython, adapted to small computers. While MicroPython does not supply all the bells and whistles you find in CPython, the look and feel is almost identical and MicroPython has additional features giving access to the connected hardware.

Before going any further, connect the ESP32 to the PC through the micro USB cable.

The ESP32 CPU card has got a USB to serial interface on board which permits the PC to talk to the MicroPython interpreter. This interface is seen as a serial port on the Linux system:

serialPorts.png

The QinHeng Electronics USB Single Serial board corresponds to the USB to serial converter on the ESP32, and it can be accessed through the device /dev/ttyACM0. On some systems, /dev/ttyUSB0 is used instead.

Communicating with the ESP32

There are three programs on the PC that we can use to communicate with the ESP32:

  • thonny: This is an Integrated Development Environment (IDE) and we can actually live with just this program. It has a shell window for communication with MicroPython's REPL, you can edit programs (scripts) and run them, and you can transfer files between the PC and the ESP32
  • minicom: A terminal emulator allowing us to talk to the MicroPython, but without the possibility of editing programs or transferring them to the ESP32
  • ampy: Allows file transfers and running of scripts which have been edited on the PC.
With the ESP32 connected, start minicom. You may have to press the enter key or even press the reset button on the ESP32 board to get the REPL prompt ">>>". Press ^d (control key and d key simultaneously) to invoke a soft reset, which will show the MicroPython version.

minicom.png

You can exit minicom typing ^a x (control a followed by x)

You can do the same thing in the shell window of thonny:

thonnyBasic.png

Since we have access to REPL now, we can start playing. As you can see below, Python can be used as a powerful calculator

firstSteps.png

With the development system set, we are ready to write our first Python programs

-- Uli Raich - 2022-10-14

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng firstSteps.png r1 manage 40.6 K 2022-10-14 - 18:35 UliRaich  
PNGpng minicom.png r1 manage 26.8 K 2022-10-14 - 18:16 UliRaich  
PNGpng serialPorts.png r1 manage 64.6 K 2022-10-14 - 17:58 UliRaich  
PNGpng thonnyBasic.png r1 manage 81.0 K 2022-10-14 - 18:20 UliRaich  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2022-10-15 - 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