Posts with «robotics» label

Data Acquisition

One of the science-teacher blogs that I read has recently discussed using an Arduino for data acquisition: The DAQ-ness Monster « Science Learnification.

I’ve not played with the Arduino much that way, but I do have a 3-axis accelerometer, the ADXL335 from Analog Devices, on a breakout board from Adafruit Industries.  This accelerometer has analog readout, so I connected the three X, Y, and Z pins to analog pins 0,1, and 2 of the Arduino, and powered the breakout board from the Arduino 3.3 volt supply.  I also sent the 3.3 volt input to the AREF pin of the Arduino so that the I could use “ratiometric” measurements.  The ADXL335 is designed so that 0g acceleration is mid-scale, so using the same voltage for powering the chip and for the Arduino AREF input means that 512 is 0g and the scaling is approximately 1g for each difference of 100.  It turns out that the calibration is not perfect (no surprise there), so you can improve the measurements by tweaking the offset and scaling for each axis separately.  I did this manually for my code, and the results are only good to about 1%.

I should be able to do better if I write a calibration program on my laptop that gathers results from the Arduino and tries to optimize the magnitudes of the reported acceleration vectors to be one.  If the accelerometer is held steady in several different orientations, this should auto-calibrate.

I wrote a little program that measured the X, Y, and Z values 1000 times, averaged them, and sent the average over the USB line to my laptop.  I’ve put the code on-line at https://gist.github.com/1054649  Each of the measurements takes about 3.3 msec (about 1msec per DAC reading)

Limitations of the Arduino as a data-acquisition device:

  • Only 6 analog inputs
  • Only 10-bit resolution
  • All 6 channels on same scale, and input must be between 0 and a single reference voltage (3.3v for the setup I used).
  • No faster than about 1msec/sample (so don’t try to collect audio or video data)

UPDATE 8 October 2011.  I’ve just found out how to put code into the blog itself, so here it is:

// Accelerometer (ADXL335) test
// Kevin Karplus
// 29 June 2011

void setup()
{
  analogReference(EXTERNAL);   // essential if you are going to connect to AREF
  Serial.begin(115200);
  Serial.println("setup");
}

// I used wires to connect the breakout board to 
// three analong inputs, 3.3v, and ground.
// I also connected the AREF input of the Arduino to 3.3v

const int Xpin=2;
const int Ypin=1;
const int Zpin=0;

const int num_to_sum=1000;
const float xscale = 0.0098/num_to_sum;
const float yscale = 0.0097/num_to_sum;
const float zscale = 0.0099/num_to_sum;

const int zero_x = 500;
const int zero_y = 506;
const int zero_z = 511;

long xsum,ysum,zsum;

void loop()
{
  unsigned long startTime=millis();
  xsum = ysum = zsum = 0;
  for (int i=num_to_sum; i>0; i--)
  {    
     xsum += analogRead(Xpin) -zero_x;
     ysum += analogRead(Ypin) -zero_y;
     zsum += analogRead(Zpin) -zero_z;
  }
  Serial.print(millis()-startTime);
  float x=xscale*xsum;
  float y=yscale*ysum;
  float z=zscale*zsum;
  Serial.print(" X=");
  Serial.print(x);
  Serial.print(" Y=");
  Serial.print(y);
  Serial.print(" Z=");
  Serial.print(z);
  
  Serial.print(" total=");
  Serial.println(sqrt(x*x+y*y+z*z));
}


Filed under: Accelerometer, Data acquisition, Robotics, Software Tagged: accelerometer, Arduino, data acquisition, robotics

Arduino Hole Dimensions Drawing

Arduinos are great, but if you’ve ever tried to mount one on a baseplate or inside an enclosure, you know it can be a pain. While there are some great enclosures specifically designed for an Arduino, if you just have a regular box that you want to use, you have to measure and mark out the holes yourself. If all you have is a ruler and a pencil, this isn’t the easiest thing to do.

In the process of working on a robot project, I needed to draw up an Arduino hole pattern and outline in CAD as part of the design. I figured others could use a similar drawing — after some polishing up, I had this Arduino hole dimension drawing (PDF).

You can use it as a reference to the dimensions or as a drilling guide. It is drawn at a scale of 1:1, so you can print it out, lay the drawing down on your mounting surface, and use a pre-drill punch directly on the paper. I’d recommend you use the punch rather than just drilling through the paper, to avoid a “walking” drill bit. If you don’t have a proper punch, you can just use a sharpened nail (we’re not fancy here).

In order to get it to print 1:1, you have to turn off print scaling in Adobe Acrobat. Somewhere in the Acrobat print dialog there’s going to be a “Page Scaling” option. Set it to “None”. There’s a 1-inch scale mark next to the title block in case you want to verify that it worked.

The drawing has dimensions for both the regular Arduino and the Arduino MEGA, and the hole pattern is good for all Arduinos going back to the NG (though the diameter of the holes might be different). The new UNO boards added a fourth mounting hole, which is indicated. It should also work with most “full-size” Arduino clones, such as the EMSL Diavolino and the Seeed Studios Seeeduino, as well as the Netduino boards.

This post is cross-posted from the Adafruit Blog. Big thanks to Adafruit for hosting the PDF.