Hardware Reference
In-Depth Information
Determining Attitude Using an Accelerometer
Compass heading is an excellent way
to determine orientation if you're level
with the earth. And if you've ever used an
analog compass, you know how important
it is to keep the compass level in order to
get an accurate reading. In navigational
terms, your tilt relative to the earth is
called your attitude , and there are two
major aspects to it: roll and pitch. Roll
refers to how you're tilted side-to-side.
Pitch refers to how you're tilted front-to-
back.
MATERIALS
» 1 solderless breadboard or prototyping shield
» 1 Arduino module
» 1 Analog Devices ADXL320 accelerometer
You can also use the accelerometer on your
LSM303DLH digital compass. An alternate sketch
to do so is shown below.
» 6 male header pins
You can use the ADXL335 accelerometer module (the
Adafruit version is shown in Figure 8-13) (or another
analog accelerometer), or the accelerometer in the
LSM303DLH compass module from the previous project.
Accelerometers come with various interfaces. The one
on the compass module shares an I2C interface with the
magnetometer. Others use a pulse-width interface. Many
simply have analog outputs for each axis, like the ADXL
accelerometers shown below. Accelerometers also come
in a variety of resolutions. For many human activities,
around 3-6g, or six times the acceleration due to gravity
(9.8 meters per second, per second) will do. Most com-
mercial products using accelerometers, like the Nintendo
Wii or the majority of mobile phones, use an accelerom-
eter in this range. The ADXL335 is a 3g accelerometer.
Other activities require a much higher range. For example,
a boxer's fist can decelerate at up to 100g when he hits!
Pitch and roll are only two of six navigational terms used
to refer to movement. Pitch, roll, and yaw refer to angular
motion around the X, Y, and Z axes. These are called
rotations . Surge , sway , and heave refer to linear motion
along those same axes. These are called translations .
Figure 8-14 illustrates these six motions.
Measuring roll and pitch is relatively easy to do using an
accelerometer. You used one of these already in Chapter
5, in the balance board ping-pong client. Accelerometers
measure changing acceleration. At the center of an accel-
erometer is a tiny mass that's free to swing in one, two, or
three dimensions. As the accelerometer tilts relative to the
earth, the gravitational force exerted on the mass changes.
Because force equals mass times acceleration, and
because the mass of the accelerometer is constant, the
change is read as a changing acceleration. In this project,
you'll use an accelerometer to control the pitch and roll of
a disk onscreen in Processing. The numeric values from
the sensor are written on the disk as it tilts.
If you're using the accelerometer on the LSM303DLH
compass for this project, use the circuit as shown back
in Figure 8-12, but without the LED and pushbutton. The
first sketch below will work with any two- or three-axis
analog accelerometer, and the second will work with the
compass module's accelerometer. Both will communicate
with the Processing sketch that follows them.
X
Search WWH ::




Custom Search