Go Down

Topic: Efficiently polling arduino sensors over USB from host (Read 419 times) previous topic - next topic

Cerin

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?

MichaelMeissner

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.

Nick_Pyner


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.

Cerin



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.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview