Arduino datalogging accelerometer with µ-SD storage

Arduino Arduino Pro mini

Eric Ayars

Overview

The Arduino Pro Mini is a microcontroller board based on the Atmel ATmega168 (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, an on-board resonator, a reset button, and holes for mounting pin headers. A six pin header can be connected to an FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.

Arduino datalogging accelerometer with µ-SD storage

The Arduino Pro Mini is intended for semi-permanent installation in objects or exhibitions. The board comes without pre-mounted headers, allowing the use of various types of connectors or direct soldering of wires. The pin layout is compatible with the Arduino Mini.

There are two version of the Pro Mini. One runs at 3.3V and 8 MHz, the other at 5V and 16 MHz.

Arduino Pro mini Schematic Diagram

Arduino Pro mini Schematic Diagram
Click to enlarge

Arduino datalogging accelerometer with µ-SD storage. Schematic

Arduino datalogging accelerometer with µ-SD storage. Schematic

The code is highly configurable: it can save raw A/D values or converted values, it allows software-defined gain, it can collect for a set time or until user input, and of course the collection interval is user-defined. It also includes a "DEBUG" mode, in which it tells the serial line everything that's happening. It can collect multiple data files (up to 100) per card, and will tell you about any errors it encounters.

All this in a small enough program to fit on an ATMega168! The data collection rate is not as high as I'd like on this 8MHz chip, and the sync() calls to the µSD card cause missed data intervals when the sample period is below 100ms, but for slower data-collection situations it works great. (Does anyone make a 32MHz 3.3V Arduino? That would be nice, here...)

User-selected values:
The following definitions can be set before sending the code to the Arduino, and change the datalogger's behavior.

  • LOG_INTERVAL is the time in milliseconds between samples.
  • GAIN is the user-selectable range on the MMA7260 accelerometer, and should be set to one of {1, 2, 4, 6}. The range for 1 is actually 1.5, if you care about that... The default value (if you set something wrong) is 6.
  • DEBUG should be set to 0 for optimal data-collection speed. If set to 1, the Arduino sends verbose messages to the serial port about  everything it is doing.
  • CONVERT_VALUES should be set to 1 to have the Arduino convert raw A/D integers into float SI values of acceleration. Set it to 0 if you would prefer the data file to contain raw A/D values.
  • TIME_OR_BUTTON changes the stop condition for data collection. If set to 1, the Arduino stops after the number of milliseconds set by COLLECTION_MILLIS. If set to 0, it stops on a second button press.
  • COLLECTION_MILLIS applies only if TIME_OR_BUTTON is set to 1, and is the number of milliseconds to collect data.

Now to go do some physics with it

Source Code (Arduino)

hacks.ayars.org