Difference: CommunicatingWithTheESP32 (1 vs. 2)

Revision 22022-10-15 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="MinimalLectures"
Changed:
<
<

hello

>
>

Communicating with MicroPython

First steps

 
Changed:
<
<
Article text.
>
>
You do not know the Python? No problem! We will go through some of the basics.
 
Changed:
<
<
-- Uli Raich - 2022-10-15
>
>
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

<--/commentPlugin-->
\ No newline at end of file
Added:
>
>
META FILEATTACHMENT attachment="serialPorts.png" attr="" comment="" date="1665770306" name="serialPorts.png" path="serialPorts.png" size="66146" user="UliRaich" version="1"
META FILEATTACHMENT attachment="minicom.png" attr="" comment="" date="1665771416" name="minicom.png" path="minicom.png" size="27477" user="UliRaich" version="1"
META FILEATTACHMENT attachment="thonnyBasic.png" attr="" comment="" date="1665771609" name="thonnyBasic.png" path="thonnyBasic.png" size="82960" user="UliRaich" version="1"
META FILEATTACHMENT attachment="firstSteps.png" attr="" comment="" date="1665772500" name="firstSteps.png" path="firstSteps.png" size="41536" user="UliRaich" version="1"
 
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