Pages: [1]   Go Down
Author Topic: Serial Comunication On Linux, compiled on Windows  (Read 683 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm new to Arduino so please bear with me if i have missed something obvious. Using an Uno i have create a little temperature sensor that writes out the current temp every 10 seconds over the usb (serial) interface. I have created and compiled the code on my Windows machine, and if I use the serial monitor on in the windows IDE i can see the information fine.

What I want to do now is plug the Arduino into my Linux Nas (server 11.04) and write a little app to pull the temperature out and write it to a file. When I plug the device into my Linux box, it comes up on /dev/ttyACM0. If i try and talk to it via tail -f /dev/ttyACM0 it just sits at the prompt and i get no output. However, if at this point i then pull the device out, the temperature information then drops onto the terminal screen.

It's as if something is buffering the output, and as i un plug the device its clearing the buffer. I've not had a go at writing an application to try and get the information out, I'm not sure if the same thing will happen and would like to understand what's going on before i go any further.

Cheers
Luke
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Tail is waiting until the device closes before it is able to process the data.  It doesn't know where the "end" of the data to tail from is until then.

You could use "cat /dev/ttyACM0" instead - it might work.

What you should really be doing is opening the serial port with software that is "serial aware" and can configure baud rates and such.

You can use "stty -F /dev/ttyACM0 <baud>" to temporarily configure the baud rate if you need to, but you are better off directly manipulating the serial port from within software.

There are libraries for most of the popular scripting languages (perl, python, php, etc) to operate with serial ports.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Thanks that would explain what's happening with tail then. I will check it with cat as well.

I'll have a look at a application tonight to get the data out. Is specific language you would recommend using?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49048
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I will check it with cat as well.
Use cat piped to tee, to see the output and write it to a file at the same time.
Logged

Atlanta, GA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use picocom to set the don't reset on disconnect (-r) and to set the serial rate (-b 115200)
picocom -r -b 115200 /dev/ttyUSB0

and head to get my output

I call a bash script every five minutes to read, clean up, write and post to pachube

Code:
#!/bin/sh
FILEDATE="`date +%Y%m`"
FILEOUT="/etc/lgt-$FILEDATE.log"
DATE="`date +%Y%m%d%H%M%S' '%d-%b-%Y' '%T`"
USBOUT="`/opt/bin/head -n2 /dev/ttyUSB0`"
#echo "$DATE"
echo "$DATE $USBOUT" | tr -d '\n' >> $FILEOUT
T6="`echo $USBOUT | tr -d '\n' | cut -d "]" -f 5 | cut -d "[" -f 1`"
curl --request PUT --header "X-PachubeApiKey: xxxxxx"  --data "23,$T6" "api.pachube.com/v2/feeds/xxxx.csv"
echo "$T6"
exit 0


Logged

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

For info using 'cat' worked fine, just need to write my application now. Thanks for everyone suggestions!  smiley
Logged

Pages: [1]   Go Up
Jump to: