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?
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.
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?
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.
Nick_Pyner:
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.