Suggestion for enable alternate end-of-line character

David Todd hdtodd at gmail.com
Tue Jun 27 16:19:39 UTC 2017


Good Morning, Minicom Developers,

... and thank you all for your good work.  Despite its age (and mine!), 
I just discovered and started using Minicom, and I very much appreciate 
your good work.

I did have a problem (not a bug) using it, though, and I documented a 
work-around in the community postings for Raspberry Pi and Arduino on 
Google. I've copied that below for your information.

The problem is that I needed just '\n', not '\r' or "\n\r" as line 
termination being sent over the serial interface (actually, over 
/dev/ttyACM0, from a Pi to a Uno).  The Arduino IDE serial monitor uses 
'\n', and I wrote my Pi code using '\n' as line terminator for commands 
sent to the Uno, so I needed for Minicom to use '\n' rather than '\r' as 
"end of line" (which is also consistent with standard Unix/Linux use).  
My solution was to use the translation table.

I did go through the Minicom source code, and it looks like the code 
well structured and that it would be easy to add a command option such 
as "use newline as end-of-line", and corresponding minirc.dfl option, 
then switch the newline character from '\r' to '\n'.  I chose not to do 
that to avoid creating my own private branch of Minicom source code, and 
I used the translation table instead.  But it would be much cleaner to 
have a command option in Minicom.

Just a suggestion for your consideration.

And, again, thanks for your good work!

David Todd

------------------------------------------------------------------------


Posting to the Raspberry Pi and Arduino Google lists


Arduino USB Minicom Connection to Raspberry Pi newline character

If you're having trouble getting your Arduino to recognize command lines 
coming from your Raspberry Pi over the USB port as serial input through 
Minicom, you might need to change the Minicom end-of-line character from 
'\r' or "\r\n" to simply '\n'. Here are some ways to do so.

There is no Minicom "use new-line as end-of-line" command parameter, 
which would be the preferred way to handle this. You might edit the 
Minicom source code in the vt100.c module to use '\n' instead of '\r' in 
the vt_send procedure, or translate '\r' to '\n' in that module before 
sending. Those steps would leave you with personal Minicom source 
branch, though.

An alternative is to use the translation table feature of Minicom to 
have it change '\r' to '\n' before sending. This approach allows you to 
use the standard Minicom with just a local configuration change. Here's 
how you do it.

I start by assuming that you have not set up either the system-wide 
configuration (/etc/minicom/minirc.dfl) or a personal configuration 
(/home/<your account>/.minirc.dfl). [If you have, move those aside for 
safekeeping for now, to some place where Minicom won't use them.]

Use "sudo mkdir /etc/minicom; sudo nano /etc/minirc.dfl" to create the 
system-wide configuration file and insert the following text into it 
(adjust speed to your preference):

# Machine-generated file - use "minicom -s" to change parameters.
pu port /dev/ttyACM0
pu baudrate 9600
pu rtscts No
pu localecho Yes
pu addcarreturn Yes

[Or you can simply use "minicom -s" and set the parameters from the 
Minicom parameter pages; but in the end, the minirc.dfl should look like 
the text above.]

Now we'll start Minicom and set the translation table:

sudo minicom -s
select "screen and keyboard" and press return-key
press the "o" ("oh") key to bring up "character conversion"
press the "c" key to "edit char"
enter "13" and press return-key as the character to edit
press the return-key to leave the input character as 13
edit the "change output to:" field from 13 to 10 and press return-key
press the "b" key to save the table
enter "/etc/minicom/miniconv.tbl" as the name of the file to save
press the return key to get back to the "screen and keyboard" screen
press the return key to get back to the "configuration" screen
select "save setup as .dfl" and press the return key to save
select "exit from minicom" and press the return key to exit


If you "ls /etc/minicom", you'll now see "miniconv.tbl" and"minirc.dfl".

When you invoke the program with a "minicom" command and connect to your 
Arduino as a serial connection over the USB cable, it will now send '\n 
as the line termination character, so that the .ino statement
"cmdString = Serial.readStringUntil('\n');"
works as expected to read an input line from the terminal or Raspberry 
Pi and in a manner consistent with the serial monitor of the Arduino GUI 
IDE.


Context and Motivation

I have been programming the Arduino using the Arduino GUI IDE 
environment. To read commands from the Pi (or OSX) coming into the 
Arduino, I used "cmdString = Serial.readStringUntil('\n');". That worked 
fine when I sent commands from the Arduino IDE serial monitor "send" 
line during manual testing or when I sent commands from the Pi with the 
command line terminated with '\n'.

But as my Arduino programs got larger, the slowness of the IDE 
environment became a distraction, so I installed arduino-mk. That 
speeded up the compile/upload process, but I needed Minicom to do manual 
testing of the program running on the Arduino. I quickly found that it 
wouldn't process commands correctly. I thought the problem might be 
terminal parameters -- speed or such -- but discovered that Minicom 
presented output from the Arduino correctly, so the problem had to be in 
the command line going in from the Pi.

Eventually I echoed back, from the Arduino to the Pi, the incoming 
character string in hexadecimal and found that the 0x0D character, '\r', 
was in the incoming string. I reviewed the Minicom source code and saw 
that '\r' or "\r\n" were baked into the code. I tested a solution by 
modifying the Minicom
code to send '\n' rather than '\r', and that code modification worked. 
But I really wanted to stay with the distributed version of Minicom 
rather than create my own branch.

And since the Arduino code was working correctly with the Arduino serial 
monitor and with the Arduino IDE when it watched for '\n' as the 
end-of-line character, I preferred to find a solution in the Minicom 
context rather than change my Arduino programs and break the interface 
with the Arduino IDE
serial monitor.

Reviewing the Minicom source code brought me to the internal use of the 
translation table, in vt100.c, and that prompted the idea of using the 
translation table feature as a way to end lines with '\n' rather than 
'\r' -- a simple translation on output as processed by the vt100.c code.




More information about the minicom-devel mailing list