Optimizing data acquisition

This is the first of a new series (tag) Dancing with Wolfram.  Occasionally, I need to work through programming strategies in Wolfram, and I need a place to store my ideas.  Perhaps they will be useful to others.

The problem

When collecting data from a sensor, one wants to generate a list of {x, y} pairs where x is typically time and y is the sensor reading.  One way of doing this is to create an empty list and then using Mathematica’s AppendTo function to add elements to the list.  The problem with this approach, however, is that it is not very efficient.  The function call makes a copy of the original list each time, and when the list of data gets very large, the time it takes to store a data point increases.  Below, I’ve plotted the average time needed to store a datapoint as a function of the list size.  For comparison, I’ve collected data (times measured on a Raspberry Pi v2)  using AppendTo with a list (blue dots) and adding key -> value pairs to an association (orange dots).

list-association-gr1

After about 1000 data points, the AppendTo a list approach starts to take increasingly longer times.  I was unable to collect any data beyond 10,000 data points since AppendTo started running into memory issues.  It is not unreasonable to expect a sensor data set to contain in excess of 1000 data points, so the performance of AppendTo is not acceptable.

Continue reading

GoIOLink release candidate 1

Introduction

GoIOLink is the flagship component of a project I call VernierPiLink which seeks to provide a variety of Vernier-sensor-Raspberry-Pi integration resources.  It relies on VS&T’s Go!Link USB adapter to perform the physical connection between an analog Vernier sensor and the Raspberry Pi.  On the software side, I am using the Go! I/O software development kit also from VS&T and the Wolfram Language which comes free (for non-commercial use) on the Raspberry Pi.

Continue reading