Simple Arduino data-collection

Simple Arduino data collection

At this year’s “Arduinos in the Physics Lab” workshop at the AAPT meeting, one of the participants asked for a simple way of using the Arduino as a tethered A/D converter for data collection direct to a computer. This is my quick & dirty demonstration solution.

Here’s the code for the Arduino. It waits for a single byte ‘N’ to arrive on the serial port, then once that byte arrives it sends out N data pairs formatted as tab-separated millis() and analogRead() values. The readings are separated by roughly 10 milliseconds. This version of the code only reports the values of analog pin 0 (A0), but it can be easily modified to return other (or more) ports.

Simple Arduino data collection

For the computer end, I used Python: here’s the code. This was done on a Macintosh, with Pylab installed so I can use matplotlib to handle the plotting nicely. On Linux or Windows the port will be described differently, and if the program fails for you on the line ‘import pylab as pl’ then … well, install pylab on your system. It’s a great wrapper package for scipy, numpy, and matplotlib. The program expects two arguments: the number of points to collect and the filename where points should be saved.

Read more: Simple Arduino data-collection

Leave a Comment

Your email address will not be published. Required fields are marked *