Minicom Introduction Installation
Minicom is the next common serial debugging tool for Linux. In Ubuntu environment, use the following command to install
sudo apt-get install minicom
Configuration
Need to be configured before use, perform
sudo minicom -s
You can open minicom and enter the configuration mode, use the arrow keys, select the items you want to configure, such as Serial port Setup , enter the configuration, you can see multiple configuration items, the cursor is at the bottom.
Need to modify a configuration, then enter the corresponding letter, the cursor will jump to the corresponding item, after editing, enter the confirmation, the cursor back to the bottom.
Generally, you need to modify
A - Serial DeviceE - Bps/Par/BitsF - Hardware Flow Control
A configuration item that specifies the USB device. General USB to serial port will generate the device/dev/ttyusbx,x is a numeric sequence number. You can perform the following command to confirm the
ls -l /dev/ttyUSB*
E configuration items, according to the actual situation, specify the baud rate and other parameters
F Configuration items, hardware flow control, depends on whether your device has. If not, or if you are not sure, you can switch the default Yes to No by turning it off first.
After the change, enter back to the previous interface, at this time remember, choose Save Setup as DFL to save the changes just as the default configuration, to avoid the next use will need to be configured again.
Finally, selecting exit exits the Configuration interface and opens minicom. Selecting exit from Minicom will exit Minicom directly.
Exit
minicom Use the prefix key ctrl-a, that is, to perform special operations, you need to press CTRL + A, and then press a key to use the corresponding function.
CTRL + A, then press Z, you can view help, from the help can be seen, when exiting, you must press CTRL + A, and then press X
Configure permissions
Minicom itself does not require sudo permissions, but because it is necessary to open the serial device/dev/xxx, sudo is generally required to start the minicom.
Here we can modify the permissions of the next serial device, so that after the use of sudo.
Method One: Use the command to change
Simply and rudely use the chmod command to modify
sudo chmod 666 /dev/ttyUSB0
Mode two: Configuring Udev rules (recommended)
Modifying a configuration file
sudo vim /etc/udev/rules.d/70-ttyusb.rules
Add a row
KERNEL=="ttyUSB[0-9]*", MODE="0666"
After modification, you will need to reseat the device to regenerate the device node.
Automatically set device name
If you use only one device on a daily basis, the device name is fixed as/dev/ttyusb0, which can be opened minicom each time.
But when you might need to use multiple serial ports, the problem comes, and each time you need to check the device name
Re-Configure the next minicom, manually changed to this device, in order to use. It's not convenient at all.
Here are two ways to solve the problem
Mode one: Automatically modify the configuration file
Create a configuration file first
sudo vim /etc/minicom/minirc.ttyUSBx
The contents are as follows
# Machine-generated file - use "minicom -s" to change parameters.pu port /dev/ttyUSB0pu rtscts No
Write script ~/.myminicom.sh, automatically detect the device, and according to the selected device, modify the configuration file, and then open the minicom
com() {ports=`ls /dev/ttyUSB*`select port in $ports;do if [ $port ]; then echo "You select the choice '$port'" port=${port##*/} sed -i "s/\(pu port .*\/dev\/\).*/\1$port/" /etc/minicom/minirc.ttyUSBx exec minicom ttyUSBx [email protected] break else echo "Invaild selection" fidone}
Introduce this function in ~/.BASHRC
echo 'source ~/.myminicom.sh' >> ~/.bashrcsource ~/.bashrc
You can call this function directly using the command com , automatically list the device, press the number key to select.
Mode two: Use parameters to specify the device (recommended)
After studying the parameters of mincom, it is found that there is a simpler implementation, using the-D parameter of minicom.
Also write scripts ~/.myminicom.sh
com() { ports_USB=$(ls /dev/ttyUSB*) ports_ACM=$(ls /dev/ttyACM*) #arduino ports="$ports_USB $ports_ACM" select port in $ports;do if [ "$port" ]; then echo "You select the choice '$port'" minicom -D "$port" [email protected]" break else echo "Invaild selection" fi done}
Introduce this function in ~/.BASHRC
echo 'source ~/.myminicom.sh' >> ~/.bashrcsource ~/.bashrc
Once added, you can use com command calls.
Use effect
[email protected]:~$ com1) /dev/ttyUSB02) /dev/ttyUSB1#?
Enter the number at this time, select the open serial device you want, enter.
Automatically save log
Let minicom automatically save the log, you can easily debug.
To view the parameters, minicom can use the-c parameter to specify the save log file. The script is then perfected, and the log is automatically named by date and saved to the/tmp directory.
Note that the TMP directory shuts down, and if you want to persist the log, you need to modify it to a different directory.
The modified script is as follows
com() { ports_USB=$(ls /dev/ttyUSB*) ports_ACM=$(ls /dev/ttyACM*) #arduino ports="$ports_USB $ports_ACM" datename=$(date +%Y%m%d-%H%M%S) select port in $ports;do if [ "$port" ]; then echo "You select the choice '$port'" minicom -D "$port" -C /tmp/"$datename".log "[email protected]" break else echo "Invaild selection" fi done}
Pause output
CTRL + A is a special function prefix button for mimicom, but another useful function is to pause the screen output.
When the device starts a large output log, the screen content is largely unclear. You can now press CTRL + A to pause the output for easy viewing of the log you need.
Open minicom Timestamp
In minicom, press CTRL + A and then N to activate the timestamp and add the current system timestamp before each line of log.
It is more convenient to observe the startup time and so on.
Send Receive File
Device-side support, press CTRL + A, and then press S, you can send files to the device side.
Press CTRL + A, and then press R to receive the file.
Wrap Line
You can use the Mimicom line-wrapping feature when your log may be in a single line that is longer than the screen width of log (such as kernel cmdline, which is printed at startup).
When you start minicom, add the-w option, or in minicom, press CTRL + A and press W.
More versatility
You can use Minicom-h to view it, or in Mincon, press CTRL + A and then press Z to view it.
What other use features or tricks, also welcome message to tell me.
The code is short and can be copied directly to the version of the article, or access the https://github.com/zqb-all/EasierMinicom
If you feel that this article is helpful to you, please click on the recommendation Oh ~ ~
How to use minicom gracefully