LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2013, 07:56 AM   #1
g_paschoal
Member
 
Registered: Oct 2009
Posts: 131

Rep: Reputation: 15
read serial file /dev/ttyACM0 best way


Hi Guys,

Can you please help ? I have an arduino attached via USB cable on a raspberry PI running debian. (It could be a computer as well)

So in the debian I see it uses serial /dev/ttyACM0. So if I send one string from arduino to raspberryPI.... I can see this string on /dev/ttyACM0.

What is the best way / Practice for this ? I mean I am writing a c++ program what will take some action depending on arduino's input. So Can I just send a string like "1" ? And have my c++ program listen to that ?

Also what is the best way to monitor /dev/ttyACM0 for changes in c++ ?

Thanks, I really appreciate your help.
 
Old 09-16-2013, 11:16 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
In the command prompt, you can use stty to view and alter settings on your port, however data rate does not matter, even if it accepts it or shows it, this is straight USB not serial USB. A good setting to use is -raw to make the port raw and turn off local echo and other properties which are invasive to what you want to see.

If whatever you're attaching too talks all the time, you can see the output of /dev/ttyACM0 using the cat command and you can send "type-able" data to it using the echo, just not control characters, or not easily. Examples:

Code:
cat /dev/ttyACM0

echo run > /dev/ttyACM0
I have posted some blog entries about this topic, including C code examples, the first is an example how to parse GPS data through a serial USB connection:

http://<br /> http://www.linuxquest...e-35551/<br />

The next on is using select() to check for data from multiple descriptors.

http://<br /> http://www.linuxquest...t-35530/<br />
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot open /dev/ttyACM0: No such device codemaniac Linux - Networking 4 03-17-2010 04:54 AM
How to read serial port (/dev/ttyS0) seraph-seph Linux - Hardware 4 11-01-2006 06:55 AM
/dev/ttyACM0 in Hardware Info, but not present in /dev list linuxdreamz Linux - Newbie 4 08-17-2006 02:29 PM
How do I create a /dev/ttyACM0? Andriy Slackware 5 06-29-2006 05:11 AM
/dev/ttyACM0 ankscorek Slackware 3 02-27-2005 01:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration