Skip to content

Latest commit

 

History

History
214 lines (142 loc) · 4.62 KB

001_serial_connection.md

File metadata and controls

214 lines (142 loc) · 4.62 KB

Serial connection

Table of Contents

screen

As soon as your microcontroller has flashed the latest MicroPython firmware, you can test a first connection with screen. For macOS screen is already available (no installation needed).

# start connection
$ screen [SERIAL-PORT] 115200

If you cannot see anything, because a script is running - press Control + x to enter REPL mode.

After detaching from the screen session (by Control + A + D), you need exit the session!

# list screen sessions
$ screen -ls

# exit screen session
$ screen -X -S [PID] quit

Screen is a great tool, but there is a more comfortable way. For example tools like picocom or minicom could be interesting. I would like to mention mpfshell and my favorite rshell.

mpfshell

In addition to a connection from the local device to the microcontroller, options such as uploads/downloads and others are required. From here, the advantages over `screen quickly become apparent.

# install mpfshell package
(venv) $ pip3 install mpfshell

# start connection
(venv) $ mpfshell -o [SERIAL-PORT]

If you like to know more details about mpfshell, visit this link. It does have really awesome features.

rshell

Now we finally come to my personal favorite rshell. Since I use this again and again in other sections (for tutorials), I also go into more detail about this tool here.

Installation

# install rshell package
(venv) $ pip3 install rshell

Basic commands

Basic commands without established connection.

# show rshell help
(venv) $ rshell -h

# list serial ports
(venv) $ rshell -l

# start rshell
(venv) $ rshell

Basic commands with established connection.

# show global help
/your/local/path> help

# show specific help for command
/your/local/path> help connect

# exit rshell
/your/local/path> exit

Connect to microcontroller

There are basically 3 options to connect to microcontroller.

First option

Here you start rshell first and in a second step you connect to the microcontroller via serial or telnet.

# start rshell
(venv) $ rshell

# use rshell command connect (serial)
/your/local/path> connect serial [SERIAL PORT]

# use rshell command connect (telnet)
/your/local/path> connect telnet [IP-ADDRESS or NAME]

Second option

Here you start the serial connection directly.

# start rshell with serial port
(venv) $ rshell -p [SERIAL PORT]

Third option (direct command execution)

Here you establish the serial connection, execute a command and close the connection.

# list boards
(venv) $ rshell -p [SERIAL PORT] boards

# list files
(venv) $ rshell -p [SERIAL PORT] ls /pyboard/

Choose the connection option according to the situation and needs. But always pay attention to whether you are working locally or on the board!

Here now a short overview about the most important commands. To follow this, establish the connection like in first or second option.

Boards

# show is_central_connected boards
/your/local/path> boards

Normally (after flashing) the board should be called pyboard.

You can change the name of your board!

# rename board (create board.py)
/your/local/path> echo 'name="esp32"' > /pyboard/board.py

Note: However, note the name change in the following examples (this has not been changed here).

Date

# show date (local)
/your/local/path> date

# show date (board)
/your/local/path> date -b pyboard

Files

List and show files

# list local files
/your/local/path> ls

# list board files
/your/local/path> ls /pyboard/

# show board file conntent on stdout
/your/local/path> cat /pyboard/boot.py

# show filetype (board)
/your/local/path> filetype /pyboard/boot.py

# show filesize (board)
/your/local/path> filesize /pyboard/boot.py

Copy files

# copy from local to board
/your/local/path> cp main.py /pyboard/main.py

# copy from board to local
/your/local/path> cp /pyboard/boot.py boot.py

Delete files

# delete file (board)
/your/local/path> rm /pyboard/example.py

Directories

# create directory (board)
/your/local/path> mkdir /pyboard/demo

# delete directory (board)
/your/local/path> rm -r /pyboard/demo/

REPL

# start python repl
/your/local/path> repl

If you like to know more, have a look on this link.

Home | Previous | Next