I'm looking for a fast (and safe, in terms of stability) way to send sensor data from an Arduino UnoR3 in real time to a Computer (in my case a MacBook Pro) with a sample rate of at least 1kHz.
I tried following:
Sending sensor values with the related timestamp (in microseconds): I use 7 bytes for each sample [1 Header byte, 2 bytes for the sensor value (10/(16)bit-Int), and 4 bytes for a 32-bit unsigned long (time in microseconds)] and send them right away.
On the receiving end i mainly use Processing (Im relatively new to Processing though): Reading the bytes in, converting them in integers and safe them in a file or plot them.
For sampling rates of 1sample/10ms my code runs smooth and i even can plot the data in "real-time".
For higher frequencies i ran into following problems:
If i want to plot things, my peripherals freeze and program stops after some time. I have no clue why... maybe serial buffer overflow??
If i just save the data in a text file (without plotting) it works but with a delay of around 20-30seconds on total sampling times of 10seconds (10000 samples). Meaning that somewhere seems to be a bottleneck and i cant keep up with the sent samples from the Arduino. Is it possible that the serial bus is the bottleneck here? How can i speed things up? (I'm working with a baudrate 115200bits/s and also 230400bits/s)
How can i improve this while still be able to process data in almost real-time (e.g plotting). Is this even possible or do you recommend logging the data in a text file first and then plot?
Will it helps to send the data in packages (10samles = 70bytes)?
I added a timestamp on each sample, since i observed some delay between the actual sensor measurement and the input on the receiving end. I thought that would allow me to plot and postprocess accurately in "real"-time (with a little delay). Any other ideas?
I would appreciate some input and advice!
Thanks in advance!