MicroPython allows for very easy prototyping and validation of basic PCB functionality. If you have the good fortune to find yourself using it on a project, the next thing you'll do after building and flashing it is connecting to the REPL over serial port.
Controlling a remote system via a tty is something programmers have
been doing basically from the beginning of time, so there's lots of
software built for it. minicom
and screen
are the two I've come
across, and they get the job done. But what if it could be even
simpler?
I hacked a bash two-liner that I've put in a function in my bashrc. You just configure the USB tty and the master tty in raw mode with a couple of adjustments to allow SIGINT and add carriage returns. Here it is:
function raw-term() {
# stty flags explanations:
# `raw` disables canonical mode (which causes odd input buffering and interception of tabs)
# `opost` = enable output postprocessing
# `onlcr` = translate \n -> \r\n on output
# `-echo` = disable double-printing of characters (and this weird endless print loop it can get into)
# `isig` = allow ^C for interrupt, etc.
#
# In `info stty` (and in flag names), input/output are from the **tty**
# perspective, not user. So when I *input* characters with the
# keyboard, they are *output* by the tty and hence are controlled by
# *output* flags.
stty -F "$1" 115200 raw opost onlcr -echo
# Hook up stdin and stdout to tty
# backgrounded `cat` receives SIGINT as well in response to ^C as it is in same pgrp
sh -c "set -e; stty raw isig -echo; cat - >\"$1\" & cat \"$1\""
}
Please send comments to blogger-jack@pearson.onl.