Go Down

Topic: Linux Serial IO (Read 9 times) previous topic - next topic

edk4971

Jan 13, 2007, 11:00 pm Last Edit: Jan 13, 2007, 11:00 pm by edk4971 Reason: 1
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

Code: [Select]
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?

edk4971

#1
Jan 14, 2007, 12:03 am Last Edit: Jan 14, 2007, 12:08 am by edk4971 Reason: 1
figured it out. If anyone is interested:
Code: [Select]

#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:
http://www.crystalfontz.com/forum/showthread.php?p=19562

it isn't perfect, but it works pretty good

neillzero

Nice!

I hope you don't mind, I copied this into the interfacing section of the Arduino wiki (playground), here:
http://www.arduino.cc/playground/Interfacing/LinuxTTY

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

edk4971

#3
Jan 14, 2007, 04:06 am Last Edit: Jan 14, 2007, 04:39 am by edk4971 Reason: 1
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

edk4971

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?

karlcswanson

Quote
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.

patsch

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:

Code: [Select]
#!/usr/bin/expect
spawn  picocom -b 115200 /dev/ttyS0 ;
expect "L"          #the script will terminate when the letter L arrives...



Thanx & Greetings.

patsch

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

http://www.arduino.cc/playground/Interfacing/Python

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.

neillzero

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
Code: [Select]
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.

patsch

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

I tried now the code
Code: [Select]
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
Code: [Select]
echo "x" > /dev/ttyUSB0TX is blinking, but "x" doesn't arrive...
I'll use python but it still interressts me... thanx.

nhoeller

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:

Code: [Select]
int outputPin = 3;
int val;

void setup()
{
 Serial.begin(9600);
 pinMode(outputPin, OUTPUT);
}

void loop()
{
 if (Serial.available()) {
   val = Serial.read();
   if (val == 'R') {
     digitalWrite(outputPin, HIGH);
     delay(5000);
   }
   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

madworm

#11
May 10, 2009, 01:17 am Last Edit: May 10, 2009, 02:55 am by madworm Reason: 1
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.

http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

nhoeller

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

madworm

Yup, you've got it.

I know that problem all to well. Thankfully my complaints were heard and the new boards were improved :-)
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

nhoeller

Rado at http://ubuntuforums.org/showthread.php?t=1105457&p=7266130 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.

Go Up