I am trying to collect analog data on 4 pins on the Arduino Mega 2560. My project requires collecting data at 1 millisecond frequency. I am using Firmata interface (xyz program in Arduino examples) for reading data on Arduino board.
On my windows laptop (Hewlett Packard 4440 G1), I am using pyFirmata to read and process data. The program consists of two threads, one that collects data from the Arduino and uses pyFirmata commands. Once the data is collected in the form of a tuple, this thread puts the data into a queue, which the other thread accesses. The second thread extract the datapoints from the queue and then plots it every second using matplotlib and the FuncAnimation command. A Fast Fourier Transform is also applied to the data, and the results of the analysis are used to emit a soundwave for half a second every second.
When I run the program at 1 millisecond collection rate, I get huge pauses in the board.read() calls. I end up collecting only about 50% of data. When I change the sampling interval to 10 millisecond, I am able to collect 98% of the data. Also, removing the second thread from the program doesn't improve the sampling accuracy by more than 1-2%, so the extra features don't seem to be the main issue.
Is there a way to improve performance at 1 millisecond level or get a better understanding of the cause of the pauses?
Thanks
Meghana
Links:
PyFirmata: pyFirmata/pyfirmata at master · tino/pyFirmata · GitHub
Matplotlib: http://matplotlib.org/api/animation_api.html
Fast Fourier Transform: Fast Fourier Transform -- from Wolfram MathWorld