Go Down

Topic: Reading ttyUSB0 using the linux tail -f command (Read 30700 times) previous topic - next topic

davearn

Hi,

I having trouble moving a programed arduino from one Linux computer to another. I have looked for a thread that has already covered this but didn't find one.

I am experienced in Linux but new to the Arduino.
I have just started 'playing' with an Arduino Duemilanove. Having got the Linux version of the arduino program working under Fedora 11 x86_64 I have developed and  uploaded a simple program that reads an analogue port and outputs the value with Serial.println (while toggling a digital port which drives an LED).

uname -a on the development computer prints:
Linux fed 2.6.30.10-105.2.16.fc11.x86_64 #1 SMP Thu Feb 4 15:56:00 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux

As a first step, I have successfully read the data using:
tail -f /dev/ttyUSB0
on that computer.

I have then transferred the usb connection to a second computer running Slackware 12.2.0 (uname -a o/p: Linux myatom 2.6.27.7-smp #2 SMP Thu Nov 20 22:32:43 CST 2008 i686 Intel(R) Atom(TM) CPU  330   @ 1.60GHz GenuineIntel GNU/Linux). Note this is 32 bit in case that is significant.

I can see a device appear dynamically in /var/log/messages:

Feb  7 17:28:45 myatom kernel: usb 3-1: New USB device found, idVendor=0403, idProduct=6001
Feb  7 17:28:45 myatom kernel: usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Feb  7 17:28:45 myatom kernel: usb 3-1: Product: FT232R USB UART
Feb  7 17:28:45 myatom kernel: usb 3-1: Manufacturer: FTDI
Feb  7 17:28:45 myatom kernel: usb 3-1: SerialNumber: A9007Mzx

and I can see /dev/ttyUSB0 created.

I can also see the arduino program driven LED flashing correctly so the arduino program must be running OK.

However
tail -f  /dev/ttyUSB0
does not produce any output.

Can anyone explain why I don't get any output from the second computer please?

Any suggestions as to how to correct the problem would be very helpful.

Many thanks,

David

RanTalbott

My first guess is that the baud rate is set wrong on the Slackware system.

Try running
Code: [Select]
stty -a -F /dev/ttyUSB0 to see how it's set up.

jabber

It may be worth checking that you are in a group that has access to usb ports. Or try as root.

davearn

#3
Feb 07, 2010, 11:39 pm Last Edit: Feb 07, 2010, 11:47 pm by davearn Reason: 1
Thanks for the replies.

Jabber - I did use root for now on the Slackware system. Would get permission denied if using non root without the correct permissions.

Ran Tallbot - the baud rates are the same but there are some other differences:

On slackware stty -a -F /dev/ttyUSB0 printed:

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

On Fedora:

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 = 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

Does anything here look it might cause a problem?

RanTalbott

Hmmm,  I don't see anything that looks like it would break communications.

I suppose it cold be something about the version of tail being used.  I generally use cat to dump raw serial data to the console,  so there might be something about the optimal settings for tail that I don't know.

Have you tried running minicom to see whether it can talk to the port?

davearn

This morning I have just discovered something that might help in finding a solution:

On the Slackware system I have found that if I leave the tail -f runing for a while (long enough for a few values to have been written by the arduino) noting shows until the USB plug is removed wile the tail -f is still running.

This suggests some kind of buffering is going on which isn't flushed until the device (/dev/ttyUSB) is removed.  Does anyone know how to prvent buffering or how to flush the buffers?

Haven't got minicom installed so haven't tried it as yet.

davearn

Another update:

Originally I tried cat rather than tail -f on Fedora only to find it returned immediately without printing any data.  I tried repeatedly calling cat to perhaps 'catch' some output but I wasn't successful - hence I settled on tail -f.

I have now tried cat on the Slackware system and found it works!
Apart from finding why there is this difference between the systems, there is still one oddity to resolve.

The arduino code is:

     Serial.print("0 ");
     Serial.println(totalValue/numVals);

On Fedora using tail -f < /dev/ttyUBS0 I get one line each time eg 0 456

On Slackware using cat I get two lines: one containing 0 456 and then a separate blank line.
Using od -cx < /dev/ttyUSB on Slackwear prints:

0000000   0       3   7   8  \n  \n   0       3   7   8  \n  \n   0    
       2030 3733 0a38 300a 3320 3837 0a0a 2030

showing there is a pair of newlines characters generated!

(od -cx won't work on Fedora as, like cat, it returns immediately showing no character values).

----------------------------
Went back to Slackware while typing this and now cat is not working!

Moved the arduino back to the Fedora system and confirmed tail -f worked.
Then used stty -F /dev/ttyUSB0 -g to print out the tty settings ->
10:0:8bd:0:3:1c:7f:15:4:0:0:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

I then went back to Slackware and tried stty -F /dev/ttyUSB0 followed by the setting values above (using root).
The command reported:
stty: /dev/ttyUSB0: unable to perform all requested operations

After doing that cat didn't work but for the first time tail -f did work!


So does anyone have any idea why these differences?

I am happy to program in C, PHP or Perl - any suggestions pleae where I might find some examples in any of these languages for simply reading the USB port? (I am still finding my way around the arduino website difficult).

Many thanks for the help so far.

wayoda

Quote

I am happy to program in C, PHP or Perl - any suggestions pleae where I might find some examples in any of these languages for simply reading the USB port?


Google "perl cpan serial port" sure will turn up something.

Its a pity you don't have python on your list "pyserial" is well documented.

And you should also find something here :
http://www.arduino.cc/playground/Main/InterfacingWithSoftware

Eberhard

Go Up