Linux Serial IO

Hopefully quick question. I have an LCD using the 4bit library. when I type something into the serial console in the IDE, it echos the string to the LCD

in the end, everything's going to be plugged into a gentoo box (doing the programming on a windows box) and i'd like to be able to just

echo "something" > /dev/ttyUSB0

what do I need to do on the Linux side to make this work. I can echo stuff to the screen using minicom just fine, but is there anyway to echo things to a serial port w/o any flow control/parity checking/etc from the command line?

figured it out. If anyone is interested:

#stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

make sure /dev/ttyUSB0 or whatever is your arduino, and 115200 is the baud you did your Serial.begin(XXXX) with taken from this forum:

it isn't perfect, but it works pretty good


I hope you don't mind, I copied this into the interfacing section of the Arduino wiki (playground), here:

It'd be interesting to know if the same command works on mac osx, too.

my wife has my ibook, and she's at home visiting at the moment, but i'll tell you in a few days if someone doesn't beat me to it

it should since darwin is BSD at heart, and Linux took the tty system from BSD. I know OSX has the stty command, just unsure if it's as functional as the Linux one

quick related question, I need the arduino plugged into USB so it can talk to the computer, but the computer won't be on all the time. Is it safe to power it with a power plug (with the jumper set to power plug) while it's plugged into USB as well?

quick related question, I need the arduino plugged into USB so it can talk to the computer, but the computer won't be on all the time. Is it safe to power it with a power plug (with the jumper set to power plug) while it's plugged into USB as well?

Yes that should be ok. When that jumper is set to power plug, the FTDI chip is the only thing powered by USB.

That looks great :) But how can I send now a String from the Terminal to Arduino? I would like to send just a single letter. I tried to read the original php file, but I don't understand it... I need translation!!!

Ouuu, yes... I've found a little bash script, which is for the oposite: How to read from the Terminal over the RS232 in Linux:

spawn  picocom -b 115200 /dev/ttyS0 ;
expect "L"          #the script will terminate when the letter L arrives...

Thanx & Greetings.

O.K. I've found a nicer way, how to handle my problem... here in the playground section :)

in- and out-puts from and to arduino over serial - interface in console mode :) I'll update this playground section with my serial-to-analog-out.pde and the tiny python script.

Greetz. patsch.

Patsch, to try to answer your original question, once you've set up the device with edk4971's stty line, I think you can simply do

echo -n "X"

where X is the single letter you want to send. The -n switch suppresses the trailing new line.

I'm not sure what buffering will occur, however.

Sounds like you have already found a different way, with python.

[...] it isn't perfect, but it works pretty good

I tried now the code echo -n "x" but even the TX LED on Arduino doesn't blink... so I can't connect the pc on this way with the Arduino. Thanx. Ups... I tried now the echo "x" > /dev/ttyUSB0TX is blinking, but "x" doesn't arrive... I'll use python but it still interressts me... thanx.

I am trying to set up an Arduino Diecimila to power-cycle a device under control of a Linux application. The hardware is working. The Arduino code (using 0015) looks like this:

int outputPin = 3;
int val;

void setup()
  pinMode(outputPin, OUTPUT);

void loop()
  if (Serial.available()) {
    val =;
    if (val == 'R') {
      digitalWrite(outputPin, HIGH);
    digitalWrite(outputPin, LOW);

Everything works fine from the Arduino development environment. On Linux, I set up the /dev/ttyUSB3 port using the stty command above with the correct baud rate and then echo "R" > /dev/ttyUSB3. However, the only way I can get the Arduino program to recognize the "R" is if I start another Linux session and invoke tail -f /dev/ttyUSB3 first.

Without the tail command, sending the "R" character causes the Rx LED to blink, quickly followed by the 'L' (Pin 13) LED. Starting the tail command causes the 'L' LED to blink. Sending the "R" now causes just the Rx LED to blink. I tried throwing in a Serial.flush() but that did not seem to do anything.

Am I missing something obvious? Running a tail command in the background is not a big deal, other than it 'holds' the ttyUSB3 port. If I unplug/replug the Arduino, I end up on /dev/ttyUSB4. Thanks, Norbert

This is caused by the auto-reset feature ! Every time you open a new serial connection the Arduino gets a reset.

That's why you can disable it by cutting the RESET_EN trace on Duemilanove and Mega boards.

So the tail[/] command kept the serial connection open? Now that I know what to look for, there are a lot of forum posts on this subject. I will try the 120 ohm resistor technique. ** Thanks for the fast response!** ** Norbert**

Yup, you've got it.

I know that problem all to well. Thankfully my complaints were heard and the new boards were improved :-)

Rado at suggested adding the -hupcl option on the stty command. This worked like a charm! I can now echo commands to the Arduino without any fuss or bother.