1

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!

1
  • You might be interested in the Telemetry library in combination with the command line interface for plotting the data (among other things). It is exactly designed for this sort of things ; also, it is well tested and reliable (I can send without issues data at maximum serial port rate). Arduino library is here Full disclaimer: I am the author of both
    – Overdrivr
    Commented Mar 5, 2016 at 23:40

1 Answer 1

1

You are sending data at ~70kbps. Provided you use serial rate greater than this (115.2 kbps or faster on the Arduino) there should be no problem, assuming you samples are processed quickly enough. This seems to be the case.

Your problem seems to be on the Mac. With a quad core CPU on a fast multitasking machine this should not be an issue. If you are having problems this would be in how you are processing the data. I am not familiar with Processing but you could do this in any language. You need to separate the data logging from the processing and display task. This could be as simple as running a logger and piping the data into a display program.

This is not an Arduino issue (or even a Mac issue), you should ask on https://stackoverflow.com/. NOTE if you want help there you will need to give more detail of the code you are running in the Mac.

1
  • So i guess i'm more or less on the right track. Thanks for clearing things up a bit!
    – Lilly2015
    Commented Apr 14, 2015 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.