Go Down

Topic: Serial Comunication On Linux, compiled on Windows (Read 1 time) previous topic - next topic



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.



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.


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?


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.
The art of getting good answers lies in asking good questions.


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

FILEDATE="`date +%Y%m`"
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


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

Go Up