Hardware Reference
In-Depth Information
Determining Orientation
People have an innate ability to determine their orientation relative to the world around
them, but objects don't. So, orientation sensors are typically used for refining the
position of objects rather than of people. In this section, you'll see two types of orientation
sensors:
a digital compass for determining heading relative to Earth's magnetic field, and an
accelerometer for determining orientation relative to Earth's gravitational field. Using
these two sensors, you can determine which way is north and which way is up.
Project 20
Determining Heading Using a Digital Compass
You can calculate heading using a
compass if you are in a space that doesn't
have a lot of magnetic interference. There
are many digital compasses on the market.
These acquire a heading by measuring
the change in Earth's magnetic field along
two axes, just as an analog compass does.
Like analog compasses, they are subject
to interference from other magnetic fields,
including those generated by strong elec-
trical induction.
This example uses a digital compass from ST Microelec-
tronics, model LSM303DLH. Both Spark Fun and Pololu
carry breakout boards for this compass. The Pololu
version was used for this example because it has built-in
voltage level shifters and works better at 5V. It measures
magnetic field strength along three axes, and it has a
three-axis accelerometer built in as well to help compen-
sate for tilt. It reports the results via synchronous serial
data sent over an I2C connection via the Wire library.
Figure 8-12 shows the compass connected to an Arduino.
The compass requires calibration, so this project features a
pushbutton to toggle between calibration mode and normal
mode, and an LED to indicate when you're calibrating.
The compass operates on 5V. Its pins are as follows:
MATERIALS
1. 1V8: 1.8V output. You won't use this pin.
2. 3V: 3-volt output. You won't use this pin.
3. Vin: 5-volt input. Connect to the microcontroller's 5V.
4. GND: ground. Connect to the microcontroller's ground.
5. SCL: Serial clock. Connect to microcontroller's SCL pin
(analog pin 5).
6. SDA: Serial data. Connect to microcontroller's SDA pin
(analog pin 4).
7. DRDY: Data ready indicator: outputs 1.8V when the
compass is ready to be read. You won't use this pin.
8. INT1: interrupt 1. You won't use this pin.
9. INT2: interrupt 2. You won't use this pin.
» 1 solderless breadboard or prototyping shield
» 1 Arduino module
» 1 digital compass, ST Microelectronics model
LSM303DLH
» 1 LED tactile pushbutton This example uses an
LED tactile button from Spark Fun, which has a
built-in LED, but you can use any pushbutton and
LED
» 1 220-ohm resistor
» 1 10-kilohm resistor
» 13 male header pins
Search WWH ::




Custom Search