Problem interfacing with Uno from kubuntu cli

Heya, I'm sorry if this is a really newb question, but Ive been reading through the guides and can't seem to get past this-

I have an arduino uno that is plugged into a mini computer running kubuntu 12. The arduino is recognised as ttyAMC0 and I can get it to work by loading the ardunio software and then using the serial connection within it, however I can't seem to get it working via the command line. The arduino has a simple program that will toggle the pins for a second when it gets that number passed through to it, and has an led on the pin to see if it works.

I am trying:

sudo echo "9" > /dev/ttyACM0

This makes the red "L" light on the arduino flash three times, but it does nothing else. If I pass "9" through the arduino software's serial monitor this works. I am thinking that it is something to do with the Baud rate, but have tried adding a 9600 to the end of the command and this still does the same.

This is using "Arduino-0022" software.

Any help is greatly appreciated, even if it is just pointing to where I should be looking,

Thanks, and apologies again for if this is something really Dumb

Set the baudrate: stty -F /dev/ttyACM0 speed 9600
stty has many options, but you only have to set the baudrate to make it work with the Arduino.
After that the "echo" command.

If you open the serial monitor, the Arduino is also reset. Perhaps that makes a difference. You have to show your sketch if you are not sure how you handle CarriageReturn and LineFeed.

In this thread http://arduino.cc/forum/index.php/topic,152105.0.html you will find some useful stty options. My first idea is that the echo command also resets the Arduino (which explains the three blinks of the L LED), but due to the reset the '9' character is lost.

Before changing the serial port configuration, however, I would start by getting a proper linux serial terminal such as minicom or (my recommendation) screen.

Hello everyone!

I have the same problem as the thread starter.

I have an arduino Uno communicating over usb2serial with the arduino IDE (and its serial monitor) which is running on ubuntu 12.04 64bit. I can interface the arduino over serial using CuteCom and screen.

However, i'm not able to open the port on the cli and echo my commands to the /dev/ttyACM0. I can only do it when I open the device using CuteCom, but then the answer from the arduino gets caught by CuteCom and does not show on the shell.
So there is no problem with permissions or anything, it's simply a matter of properly initializing the port.

I know that I have to use stty, I followed the instructions on the playground but without success.

What I've done so far:

Initialize the port using the serial monitor from arduino IDE and then read the parameters with stty like so:

stty -a < /dev/ttyACM0

which tells me:

speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = ;
eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 0; 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

Ok fine so i put it together to use these parameters to open the port (i tried with and without raw option):

stty -F /dev/ttyACM0 cs8 9600 raw -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

... but no luck!

When I do

echo "led 1" > /dev/ttyACM0

nothing happens except restarting the arduino! The pin 13 led blinks 3 times and then once again.

I've read something about the DTR pin and if this pin is set high, the arduino reboots (to upload sketches and what not). But thats why im using the -hupcl option right?

This is driving me nuts, it shoudn't be that complicated to open the serial port to the arduino and talk to it on the command line...

I would really appreaciate your help.

PS: using a different progam or python to open the port is not an option. I need a pure shell solution.

Hi, when I tried some of these options myself I was quite disappointed, gave up and followed the hardware approach: a 10uF capacitor between RESET and GND works for me (the only downside is that you need to put it in place before connecting the Arduino).

I use a fd to get around this (google bash fd for more information)

For example:

void setup() {
  Serial.begin(9600);
  Serial.println("Enter a digit between 0 and 9 for squaring");
}
void loop() {
  while(!Serial.available());
  int i=Serial.read()-'0';
  if(i>=0 && i<=9)Serial.println(i*i);  
}

~/arduino$ stty -F /dev/ttyACM0 sane raw -echo 9600
~/arduino$ exec 6<>/dev/ttyACM0
~/arduino$ line <&6
Enter a digit between 0 and 9 for squaring
~/arduino$ echo 3 >&6
~/arduino$ line <&6
9
~/arduino$ echo 8 >&6
~/arduino$ line <&6
64

It can be unreliable at shell prompts but works much better in scripts.

stimmer:
I use a fd to get around this (google bash fd for more information)

Wonderful :).
+1

Thanks stimmer!

Although I haven't figured out yet what this is doing, it works!

EDIT: I think it basically does the same thing as screen, it holds the port open, but in the background. Then you can echo to it and read line by line.