Picocom is a lightweight, simple terminal
software for working with serial ports. It is good, almost perfect for most tasks
dealing with embedded electronics. However, some features are missing in the stock
version. When bad data come to the port, they are echoed in binary form and the
random control characters then can break the terminal setting and result in weird
character mapping and other oddities; this was a problem especially with the ESP8266
chip, which sends garbage on reset. There was also missing control of the RTS pin.
Several functions were added in the form of a patch:
- Hex dump - control characters (anything that is <0x20 or >=0x80, and
is not CR and LF) are displayed as [xx] formatted hex numbers. It can be switched off by the --nohex option or extended to all bytes by the --hexall one.
- Hex send - on Ctrl-A Ctrl-H]] an input line shows, allowing entering of a string
of hexadecimal values, with or without separators; these are then translated to binary and sent to the port.
- Colorizing - different messages are shown in colors; by default, system is
yellow, local echo is red, and data from remote are green. Hex numbers are shown in dark (if the foreground is bright) or vice versa.
- Terminal reset - Ctrl-A Ctrl-O runs the "reset" utility, which resets the
terminal. Good when it gets confused by control characters.
- Shell - Ctrl-A Ctrl-Z spawns local shell. Good for quick tasks or lookups
without having to leave the terminal. Can be also used for setting the serial line parameters via e.g. stty, but this may confuse the picocom's port state reporting.
- Real port state reading - on startup, when port is not being reset, its actual
configuration is read from the port's own control structures instead of using fixed assumptions.
- Custom baud rates - the commandline setting now takes an arbitrary speed,
on Ctrl-A G a baud rate can be entered directly. If the value is nonstandard, it is inserted into the array for manual baud rate changes by up/down.
- List of baud rates - the default list of baud rates for manual up/down changes
can be set to custom values or values can be added as a comma-separated list. The --baudlist option replaces the default list, the --baudadd adds the values to the list. Preexisting lists are DEFAULT, CP2101, CP2102, MIDI, and CAN. Up to 64 values can be specified. Handy for easier swapping between few different baud rates.
- Toggling RTS - in addition to toggling and pulsing DTR the software can now
toggle the RTS line, by Ctrl-A Ctrl-E.
- Setting of DTR and RTS - the --dtr 0|1 and --rts 0|1
set the state of the port's outputs to the desired value on startup.
- Port modem line display - on showing of options (Ctrl-A Ctrl-V), and on every
output control line change, the control signals are read from the port and shown.
- Real time monitoring of port modem lines - the select() call is amended with 100msec
timeout, the modem bits are checked, discrepancies are listed; e.g. RI going up is shown as [RI+] , DSR going down is shown as [dsr-] . Can be disabled with --nomodem.
- Key help - on Ctrl-A ? the list of control key combinations is shown.
Example: run picocom on /dev/ttyUSB0, at 115200 bps, with local echo and colors, with DSR high and RTS low:
picocom -b 115200 -c -C --dtr 1 --rts 0 /dev/ttyUSB0
Usage is: picocom [options] <tty device>
--<f>low s (=soft) | h (=hard) | n (=none)
--<p>arity o (=odd) | e (=even) | n (=none)
--<d>atabits 5 | 6 | 7 | 8
--color (-C), --colorbright (-B)
--imap <map> (input mappings)
--omap <map> (output mappings)
--emap <map> (local-echo mappings)
<map> is a comma-separated list of one or more of:
crlf : map CR --> LF
crcrlf : map CR --> CR + LF
igncr : ignore CR
lfcr : map LF --> CR
lfcrlf : map LF --> CR + LF
ignlf : ignore LF
bsdel : map BS --> DEL
delbs : map DEL --> BS
<?> indicates the equivalent short option.
Short options are prefixed by "-" instead of by "--".
Version compiled at
Sat Mar 3 10:27:57 CET 2018
The binary is compiled for PC Linux, using gcc-4.9.2.
Compiling for Raspberry Pi (armhf architecture) was uneventful; make did the job smoothly. Binaries of the version of code compiled at Sat Mar 3 10:24:27 CET 2018:
A fault was found in the select() call, where the timeout for checking modem flags was specified in microseconds instead of in nanoseconds (some odd specs shenanigans).
The changes were therefore read 10,000 times per second instead of 10 times. This was very noticeably slowing the code on slower machines, namely raspberry pi.
The term_get_modem_flags was unnecessarily calling term_find, iterating through the term structure without need to.
250000 and 500000 were added to list of default baudrates.
No warranty, it's software and so it has more bugs than an anthill. Original code is GPLv2, this naturally follows.
Custom baud rates are implemented by using term.c from jmesmon's fork, here.
The files are:
- maybe a line interface with command history (readline?) - ctrl-L for entering a line with command history, allow history file?
(with a #define in source code, to avoid need for libreadline and to avoid additional memory footprint), allow some escape sequences for entering hex bytes (maybe "" as send 0x01, "\" as send ""?)
- in hexall mode, generate new line on a timeout (to show binary data that come in chunks)
- maybe populating the baudrates field from a command, for CAN bus, MIDI, DMX, and other buses
- screenshots of the terminal window