Timing accuracy of serial object and Arduino
I built a custom foot pedal that has various buttons and encoders all connected to an arduino board, which goes into my Mac Pro USB port. I’m currently getting data from the pedal by pinging every 10ms with a metro connected to a serial object at 115200. Each cycle first bangs the serial, then bangs a message (which is the number 0) that goes to serial and is therefore sent to arduino initiating it to respond with the current state of all buttons and encoders.
The setup basically works but the timing is horrible. The data comes back from the arduino every 10 ms for maybe 5-10 cycles, then there will be silence for 20-50ms, then a burst with all the missing data, and so on. This timing inaccuracy is unacceptable for my application as the foot pedal needs to capture real-time movements, similar to an expression pedal.
Note the arduino code is set to 115200 along with the serial object, so there is no incompatibility there. I've already experimented with changing the ping rate up to 30ms and down to 4ms, with no significant improvement in the problem.
Any ideas on how to improve the timing accuracy?
Hi
in my experience 115200 is unusable if you're asking for multiple sensor data across the serial-usb bus; try lowering to 38400, 19200 or 9600. This might clean up the bottleneck.
Brendan
Also, I would need to see your code and patch, but I've found that one-way communication can be more reliable than handshaking as you describe; I just terminate my sensor data bundle with Serial.println, and use [select 13 10] and [zl group] after the serial object. YMMV
Have you tried Arduivis?
Brendan
Thanks for the helpful ideas. I will try shortly. In the mean time, attached is the code that is problematic.
I've also tried @drain 1 and @chunk 8 in the serial object (it's an 8-byte response), but neither resolved the issue. Any thoughts on using these attributes?
I'll report back soon after trying your other suggestions.
Thanks,
Jack
I've had same experience as Brendan. Just send all your data from arduino all the time, instead of handshaking. Adjust your delay(x) in the arduino code as low as you really want to go. I usually have it set around 5ms.
Thanks guys for the excellent suggestions! I just got it up and running by dropping the handshake and just having Arduino sending all the time via Serial.println. I'm going to do a bunch more testing with different baud rates and delay times over the next day or two. I'll post the final solution that works best, but this is looking very promising so far.
Took me a while to nail this down, but I've been running now for a week or so with Arduino sending out Serial.print.ln at 38400 baud and then Max metro banging my serial object at 3 ms. For my application slowing the baud rate further introduced too many gaps in the continuous data to work well. But at 38400 it's working quite well, so thanks again for the input!
38400 is indeed the magic number, in my experience. But everyone's setup/demands are different.
:)