Pages: [1]   Go Down
Author Topic: Can't find a good way to get Arduino's printings  (Read 907 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 35
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello there.

I'm making a musical keyboard, and the hardware part is almost done (in scale), the keyboard basically prints on serial the keys states as fast as Arduino can. However, I couldn't figure out a good way to "read" these states into variables in a C++ program.

I've tried to use the arduino-serial program from todbot.com, but it returns garbage data, also, I tried to use tail (popen), but it's too slow and cat (popen) can't get small pieces of data.

An alternative is to use something like dd and limit the number of bytes, however, despite it should work, i don't know if it's an neat way to do this, because dd isn't intended to do this kind of reading.

The program on PC will actually play the songs for every key, so I really need a good reading rate. I don't want to waste any data from Arduino, and I think it's very possible because the PC is much faster than it.

Thank you.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However, I couldn't figure out a good way to "read" these states into variables in a C++ program.
Why not? What did you try?

Quote
The program on PC will actually play the songs for every key...
Songs? Or notes?

What program on the PC? What operating system?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 35
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why not? What did you try?
The ways that actually works are using dd which I don't want to use, and reading the port like a file in C++ using (e.g.) indata (from ifstream), the last works very well, but It's not standard.

So I don't know any other way to do this.

Quote
Songs? Or notes?

What program on the PC? What operating system?

Notes (sorry my english) i'm going to write my own program using something like OpenAL... it's not the point right now though.

Unix-like, POSIX compatible (e.g. GNU/Linux, BSD, Solaris, Msc OS, etc.)

Thank you.
« Last Edit: August 25, 2010, 08:57:41 am by 2stl » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the last works very well, but It's not standard.
Is that a problem? Why?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 35
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is that a problem? Why?
Isn't it? I'm not very experienced, but I think it isn't okay to read from a port like if it were a file... at least I think programs like dd, trail, or cat doesn't do this.

However, if it's okay to read a port as a file (using indata), then it's solved. I doubt this method is "solid" though.

Thank you.
« Last Edit: August 25, 2010, 12:56:36 pm by 2stl » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are typically classes that manage the complexity of reading from the serial port. But, the serial port is simple a source of bytes of data, just like a file. The only real difference is that a file has a hard end-of-file marker and a stream (like the serial port) may not. You might read to the end of the data, and then try to read again, and by now more data has appeared on the port, so the read will succeed, whereas when you encounter an end-of-file on a file, no subsequent reads will ever succeed.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 35
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You might read to the end of the data, and then try to read again, and by now more data has appeared on the port, so the read will succeed, whereas when you encounter an end-of-file on a file, no subsequent reads will ever succeed.
I see... this is pretty much what I am doing, however, I don't know if the constant readings(/accessing) can cause some kind of undesired behaviour... like overheating of the USB controller, asynchronism (because the port may "slow down" I think), or something like this.

I don't know if this is a "stable" solution and it doesn't look any reliable imho. I'm not an expert also, so i'll not be surprised if I'm wrong.

Is there a kind of "test" that I can make to know if it's stable (like letting the entire system working for a lot of time (24hs?)) ?

Thank you.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this is pretty much what I am doing, however, I don't know if the constant readings(/accessing) can cause some kind of undesired behaviour... like overheating of the USB controller, asynchronism (because the port may "slow down" I think), or something like this.
I'm pretty sure the electrons that are moving to move the serial data are not going to overheat the USB controller.

Serial data is, by definition, asynchronous, so that won't be a problem.

The port doesn't slow down because there is a lot of data, or only a little data. The Arduino will be pumping data down the line as fast as it can. It will be up to your program to read it faster than the Arduino sends it.

That leaves the "something like this" part. I suppose that anything that goes wrong fits into that category.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 35
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay. So I think it's solved...

Thank you very much PaulS!

Now I'm gonna begin to code the hard part smiley-grin.
Logged

Huntsville, Alabama, USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 327
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reading from a port as if it were a file is one of the most important features of Unix, Linux, etc.  In fact, in this family of operating systems, you can read from any device as if it were a file.

-Mike
Logged

Pages: [1]   Go Up
Jump to: