Pages: [1]   Go Down
Author Topic: Linux Serial IO  (Read 8527 times)
0 Members and 1 Guest are viewing this topic.
McGuire AFB, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
« Last Edit: January 13, 2007, 05:00:46 pm by edk4971 » Logged

McGuire AFB, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

figured it out. If anyone is interested:
Code:
#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
« Last Edit: January 13, 2007, 06:08:04 pm by edk4971 » Logged

London
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

McGuire AFB, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: January 13, 2007, 10:39:53 pm by edk4971 » Logged

McGuire AFB, NJ
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Chicago IL
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That looks great smiley
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:
#!/usr/bin/expect
spawn  picocom -b 115200 /dev/ttyS0 ;
expect "L"          #the script will terminate when the letter L arrives...


Thanx & Greetings.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

Greetz.
patsch.
Logged

London
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
[...] it isn't perfect, but it works pretty good
I tried now the code
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
Code:
echo "x" > /dev/ttyUSB0
TX is blinking, but "x" doesn't arrive...
I'll use python but it still interressts me... thanx.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

« Last Edit: May 09, 2009, 07:55:13 pm by madworm » Logged

• 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!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, you've got it.

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

• 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!

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: