Vous êtes sur la page 1sur 4

7/9/2011

Main Site Blog Playground Forum Store Help | Sign in or Register

Arduino playground - LinuxTTY

search

The play ground is a publicly -editable wiki about Arduino. Interfacing... Manuals and Curriculum Board Setup and Configuration Development T ools Interfacing With Hardware Output Input User Interface Storage Communication Power supplies General Interfacing with Software Code Library and T utorials Libraries Tutorials Suggestions & Bugs Electronics Technique Sources for Electronic Parts Related Hardware and Initiatives Arduino People/Groups & Sites Exhibition Project Ideas Languages PARTICIPATE Create an account Suggestions Formatting suggestions All recent changes PmWiki WikiSandBox training Basic Editing Cookbook (addons) Documentation index T ODO: Is there any problem with buffering (and if so, how do we flush) if we send content with no end of line:
echo -n "Hello" > /dev/ttyUSB0

Arduino and Linux TTY


Elliott Kipp/edk4971 posted in the forums on how to configure a linux tty with the correct parity, baud, etc to talk to arduino. Repeating it here: 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 Y ou can then do:
echo "Hello Arduino" > /dev/ttyUSB0 to send the string (followed by a newline) to your arduino.

T aken from this forum: http://www.crystalfontz.com/forum/showthread.php?p=19562 Y ou can also do:


tail -f /dev/ttyUSB0 to read what your arduino has to tell you.

Using 'screen' to provide an interactive session with arduino


this first comment on todbot's post on serial c code to talk to arduino shows how to get an interactive session with arduino using the screen command.
screen /dev/cu.usbserial 9600

I haven't tested this yet.

arduino.cc/playground//LinuxTTY

1/4

7/9/2011
edit SideBar

Arduino playground - LinuxTTY

Using 'screen' and the SimpleMessageSystem to provide an interactive session with Arduino
1) Program the Arduino with the example code include in the SimpleMessageSystem library (leave the baud rate at 9600 for this example). 2) Open a terminal window. 3) Enter the following command (that differs slightly from above): stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts 4) Start screen by typing the following: screen /dev/ttyUSB0 9600 5) Start by pressing the enter/return key to clear the Arduino's buffer. 6) T ype the following commands, followed by pressing the enter/return key for each message (please be warned that the characters will not appear as you type them, but the Arduino rx/tx leds will blink, this is considered normal behavior): w d 13 1 ra rd T he first message will turn on a let connected to port 13. T he second message will return the value of all the analog inputs. T he third message will return the value of all the digital inputs. 8/7/08-by Roland Latour (rolandl@cavenet.com) T here's a better way. 'screen' actually forks a second process to catch data coming the other way. So you need a helper process. My shell script package does that, and interprets and formats the data. Now with a GUI provided by the Xdialog command. Run 'wget http://user.cavenet.com/rolandl/SMS1.tgz' to get the tarball. Added 6/16/2009-by Lee:

Workaround for using cat /dev/ttyUSB0 and screen /dev/ttyUSB0 on a Linux computer.
On my system, the Arduino development environment doesn't close the port /dev/ttyUSB0 quite right. T he scheme for my project is to send serial data out the USB type B connector on my Arduino Mega into a file. Open the file in a spreadsheet..

arduino.cc/playground//LinuxTTY

2/4

7/9/2011

Arduino playground - LinuxTTY


cat /dev/ttyUSB0 > datafile gnumeric < datafile

Specifically: The arduino-0015 development application does not close or release /dev/ttyUSB0 on Linux systems completely. As a result, "cat /dev/ttyUSB0" fails if you have used the serial data display in the Arduino development application. T o re-capture the data use "screen"
screen /dev/ttyUSB0 // Kill screen with ^ak or control-a k

An alternate way to stop the screen program: Display the process table and kill screen using the PID in column two.
ps aux // see screen and SCREEN processes. Note PID in column 2 kill 9264 9265 // screen is gone and "cat /dev/ttyUSB0" now works

Background about the environment for these commands. My Arduino hardware is an Arduino Mega that has a USB type B port built in. The program application uses serial data setup and printing straight out of the Arduino Programming Notebook. In the Arduino development environment, I can see the data being printed by the Arduino board using the Serial Monitor button. This should work before you can get data from /dev/ttyUSB0. T he computer runs a mix of Ubuntu 7.10 and 8.04. Serial port code fragments:
setup() { Serial.begin(9600); } loop() { Serial.print("Total "); Serial.println(total_count/1000); }

End of note by Lee. Added 9-jun-2011 - by The Dare Guy (http://twitter.com/thedareguy):

Simple communication using 'cu' in Linux (tested in Ubuntu 10.04 LTE)


Find what USB port uses Arduino when you plug it into your computer. It can be something like /ttyUSBx or /ttyACMx (this is my case). T o find the answer unplug the Arduino from the USB, run a Terminal (Applications > Accesories > T erminal) and type:
$ cd /dev $ ls tty* ... tty8 tty9

arduino.cc/playground//LinuxTTY

3/4

7/9/2011

Arduino playground - LinuxTTY


ttyS0 ttyS1 ...

Plug in the Arduino into the USB and type in the terminal:
$ ls tty*

Y ou will find a new device! My case:


... tty8 tty9 ttyACM0 ttyS0 ttyS1 ... <-- New device

Y our program in Arduino must have initialised Serial Interface at a speed with Serial.begin(<speed>). T he interface you are going to run ('cu') is so simple that every keypress will be sent to the serial device without echo, and every char sent by Arduino will be sent to your screen. T here is no chance to stop 'cu', only by killing the T erminal window you are running. T ype in the terminal:
$ cu -l /dev/<device> -s <speed>

In my case:
$ cu -l /dev/ttyACM0 -s 115200

All done! If 'cu' is not installed, type in the Terminal:


$ sudo apt-get install cu

T hat's all folks! 9-jun-2011 - by T he Dare Guy (http://twitter.com/thedareguy)

Share |

arduino.cc/playground//LinuxTTY

4/4

Vous aimerez peut-être aussi