Communication Debian -> Arduino - setting the transmission parameters tty


Arduino is connected to the USB. I want to Debian to Arduino send the number “1”.
I want to send the digit “1” to light up the LED.

I have uploaded to the Arduino such a program

   Simple LED sketch
  int led = 13; // Pin 13
  void setup()
      pinMode(led, OUTPUT); // Set pin 13 as digital out
     // Start up serial connection
     Serial.begin(9600); // baud rate
 void loop()
     String input = "";
     // Read any serial input
     while (Serial.available() > 0)
         input += (char); // Read in one char at a time
         delay(5); // Delay for 5 ms so the next char has time to be received
     if (input == "1")
         digitalWrite(led, HIGH); // on
     else if (input == "2")
         digitalWrite(led, LOW); // off

I tried this command

echo '1' > /dev/ttyUSB0

Before calling the command, I set the following transmission parameters:

stty -F /dev/ttyUSB0 9600 parodd cs8 -cstopb crtscts

After calling the above command checked current settings

root@pic:/home/pic# stty -F /dev/ttyUSB0 -a
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
parenb parodd cs8 hupcl -cstopb cread clocal crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt
-echoctl -echoke

Why can not I send the number “1”?

What is the Parity setting on the Arduino ?
What is the Parity setting on the stty ?

Do they match ?

Parity is set well.

I found a partial solution by performing steps:

  1. I open the first console and entered
tail -f /dev/ttyUSB0
  1. I open the second console and entered
echo -n "1" > /dev/ttyUSB0

This solution works well.

Question? How to do the same by opening only one console stty?

I have come across a few Threads in which people try to send data to an Arduino using echo and I don't think any of them found a solution. A big part of the problem is that the Arduino usually resets when the serial port is opened.

I suggest you write a short Python program to send the data and then you can call that from the command line. This Python - Arduino demo should be a good starting point.


Thank you for guidance and help.