Daily tips and tricks from the experts at Adafruit!
View this email in your browser

With MicroPython you often find yourself connecting to the serial output of a board, either to see output from a program or to interact with the Python REPL (read-evaluate-print loop).  One of the challenges of the serial port is finding a program to simplify reading and writing data to it, and an even bigger challenge is finding a program that works across different operating systems.  On Mac OSX and Linux machines you typically can count on the GNU screen program to access serial ports, but on Windows it’s a bit more challenging to find a simple serial terminal.  GUI tools like PuTTY are a great option on Windows but can be a bit confusing with so many connection options.  Wouldn’t it be nice if there was a simple serial terminal access program that worked the same on all operating systems?

It turns out there is a handy serial terminal access tool that you can use on all the major desktop operating systems!  Included in the PySerial module are two little terminal programs to list serial ports and create an interactive serial terminal.  Normally the PySerial module is used to write Python scripts that access the serial port, but included in the module are two fully featured Python scripts that provide just enough functionality to access serial ports interactively.  To install and use these tools you first need to install Python on your computer, and then use the pip tool (included with Python) to install the PySerial package.

Once the PySerial module is installed you can run the serial tools by invoking them with Python’s interpreter. For example to list all of the serial ports that are available use the serial.tools.list_ports script:

python -m serial.tools.list_ports

The tool will print out the name of any serial device connected to your computer.  This is very handy for determining the name of the serial port for a MicroPython board you’ve connected to your computer.  Then to connect to the serial port use the serial.tools.miniterm program, like:

python -m serial.tools.miniterm COM3 115200

Which would connect to a serial device on COM3 (on Windows) at 115200 baud.  Once connected you can send and receive data with the device by typing in the terminal.  You can quit the terminal by pressing Ctrl-] too.  Next time you’re at a computer and need a simple serial terminal consider installing the PySerial package and its excellent serial tools!