Pages: [1]   Go Down
Author Topic: Efficiently polling arduino sensors over USB from host  (Read 307 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's the best way to program an arduino so its sensors can be quickly polled over USB?

I have a small project with a few dozen on/off contact sensors and a half-dozen analog sensors that I want to be able to quickly relay value changes to a "host" computer. It's a mobile platform, so I'd like the system to be as close to real-time as possible.

My thinking is to use a pull-method by adding any sensor that's changed since the last polling to a special buffer, and when the host polls the arduino, send it the most recent values in the buffer and then clear it.

Is there a more efficient push-method, where the arduino can notify the host of sensor changes?
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1766
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure just write to the USB (assuming you are using it as a serial channel) whenever the sensor changes or when the host sends a command telling you to send the sensor.  On the host side, you would just do a blocking read, waiting for input.  Depending on the OS, you might be able to use a signal/interrupt to know when input is available, or just have a separate task reading the USB and sending whatever signal you need.
Logged

Dee Why NSW
Offline Offline
Edison Member
*
Karma: 30
Posts: 1682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What's the best way to program an arduino so its sensors can be quickly polled over USB?

I have a small project with a few dozen on/off contact sensors and a half-dozen analog sensors that I want to be able to quickly relay value changes to a "host" computer. It's a mobile platform, so I'd like the system to be as close to real-time as possible.

My thinking is to use a pull-method by adding any sensor that's changed since the last polling to a special buffer, and when the host polls the arduino, send it the most recent values in the buffer and then clear it.

Is there a more efficient push-method, where the arduino can notify the host of sensor changes?

If you really want it quick, wouldn't it be both simpler and preferable to accept a data stream over USB rather than poll a buffer?  That way you minimise the operations and ensure the information is coming as fast as the Arduiono can send it.

You can use "if no change do next" conditions to determine what is sent.
Logged

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


If you really want it quick, wouldn't it be both simpler and preferable to accept a data stream over USB rather than poll a buffer?  That way you minimise the operations and ensure the information is coming as fast as the Arduiono can send it.

You can use "if no change do next" conditions to determine what is sent.

Yes, of course. I wasn't sure if this was possible. Thanks.
Logged

Pages: [1]   Go Up
Jump to: