source: trunk/Arduino/GSM/libraries/LSM303/README.textile@ 18403

Last change on this file since 18403 was 17969, checked in by dneise, 10 years ago
adding libraries folder, with LSM303 lib, this takes precedence over any locally installed LSM303 library, e.g. in HOME/arduino-1.0.6/libraries.
File size: 12.5 KB
Line 
1h1. Arduino library for Pololu LSM303 boards
2
3Version: 2.0.0
4Release Date: 2013-11-27
5"www.pololu.com":http://www.pololu.com/
6
7h2. Summary
8
9This is a library for the "Arduino":http://pololu.com/catalog/product/2191 that interfaces with LSM303D, LSM303DLHC, LSM303DLM, and LSM303DLH 3D compass and accelerometer ICs on Pololu boards. It makes it simple to read the raw accelerometer and magnetometer data from these boards:
10
11* "LSM303D 3D compass and accelerometer carrier":http://www.pololu.com/catalog/product/2127
12* "LSM303DLHC 3D compass and accelerometer carrier":http://www.pololu.com/catalog/product/2124
13* "LSM303DLM 3D compass and accelerometer carrier":http://www.pololu.com/catalog/product/1273
14* "MinIMU-9 v2 (L3GD20 and LSM303DLHC carrier)":http://www.pololu.com/catalog/product/1268
15* "AltIMU-10 (L3GD20, LSM303DLHC, and LSM331AP carrier)":http://www.pololu.com/catalog/product/1269
16* "LSM303DLH 3D compass and accelerometer carrier":http://www.pololu.com/catalog/product/1250 (discontinued)
17* "MinIMU-9 (L3G4200D and LSM303DLM carrier)":http://www.pololu.com/catalog/product/1265 (discontinued)
18* "MinIMU-9 (L3G4200D and LSM303DLH carrier)":http://www.pololu.com/catalog/product/1264 (discontinued)
19
20The library also includes a function for computing the tilt-compensated heading for those looking to use the LSM303 as a tilt-compensated compass.
21
22h2. Getting Started
23
24h3. Software
25
26Download the archive from "GitHub":https://github.com/pololu/LSM303, decompress it, and move the "LSM303" folder into the "libraries" subdirectory inside your Arduino sketchbook directory. You can view your sketchbook location by selecting File->Preferences in the Arduino environment; if there is not already a "libraries" folder in that location, you should create it yourself. After installing the library, restart the Arduino environment so it can find the LSM303 library and its examples.
27
28h3. Hardware
29
30Make the following connections with wires between the Arduino and the LSM303 board:
31
32h4. Arduino Uno R3, Leonardo, Mega 2560
33
34pre. Arduino LSM303 board
35-------------------------
36 5V -> VIN
37 GND -> GND
38 SDA -> SDA
39 SCL -> SCL
40
41h4. Arduino Micro
42
43pre. Arduino LSM303 board
44-------------------------
45 5V -> VIN
46 GND -> GND
47 2 -> SDA
48 3 -> SCL
49
50h4. Arduino Uno (up to R2), Duemilanove, etc.
51
52pre. Arduino LSM303 board
53-------------------------
54 5V -> VIN
55 GND -> GND
56 A4 -> SDA
57 A5 -> SCL
58
59h2. Example Programs
60
61Open an example code sketch by selecting File->Examples->LSM303->example_name
62
63h3. Serial
64
65This program continuously reads the accelerometer and magnetometer, communicating the readings over the serial interface. You can display the readings with the Arduino Serial Monitor.
66
67Example output:
68
69pre. A: 192 -1040 -17168 M: -512 27 144
70A: 288 -1040 -17232 M: -511 26 143
71A: 16 -1104 -17216 M: -511 27 144
72
73See the comments in this sketch for some notes on how to convert the raw sensor values to units of g and gauss.
74
75h3. Calibrate
76
77This program is similar to the Serial example, but instead of printing the most recent readings, it prints a running minimum and maximum of the readings from each magnetometer axis. These values can be used to calibrate the @heading()@ functions and the Heading example after moving the LSM303 through every possible orientation.
78
79h3. Heading
80
81This program uses readings from the accelerometer and magnetometer to calculate a tilt-compensated compass heading (in degrees relative to a default vector), which is communicated serially and can be displayed with the Arduino Serial Monitor. The default vector is chosen to point along the surface of the PCB, in the direction of the top of the text on the silkscreen. (This is the +X axis on the Pololu LSM303D carrier and the -Y axis on
82the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH carriers.) See the comments if you want to use a different reference vector.
83
84For the most accurate results, you should replace the values of @m_min@ and @m_max@ assigned in the @setup()@ function with your own values obtained from the Calibrate example.
85
86h2. Other Library Applications
87
88These programs make use of the LSM303 library but are not included with in the library archive or repository.
89
90- "MinIMU-9 + Arduino AHRS":https://github.com/pololu/minimu-9-ahrs-arduino := This sketch allows an Arduino connected to a MinIMU-9 or AltIMU-10 to function as an attitude and heading reference system, calculating estimated roll, pitch, and yaw angles from sensor readings that can be visualized with a 3D test program on a PC. It is based on the work of Jordi Munoz, William Premerlani, Jose Julio, and Doug Weibel.
91- "Pololu_Open_IMU":https://github.com/mikeshub/Pololu_Open_IMU/tree/master/Pololu_Open_IMU by mikeshub := This is an alternative AHRS implementation that uses the "Madgwick algorithm":http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/.
92- "ascii_graph":https://gist.github.com/drewtm/9081341 by drewtm := This sketch outputs a text-based graph of LSM303 accelerometer and L3G gyro data, providing a quick way to check whether the sensors are working as expected.
93
94h2. Library Reference
95
96- @vector<int16_t> a@ := The last values read from the accelerometer.
97- @vector<int16_t> m@ := The last values read from the magnetometer.
98- @vector<int16_t> m_min@ := Lower bounds (minimum values) for the magnetometer readings on each axis; set this appropriately to calibrate @heading()@.
99- @vector<int16_t> m_max@ := Upper bounds (maximum values) for the magnetometer readings on each axis; set this appropriately to calibrate @heading()@.
100- @byte last_status@ := The status of the last I2C transmission. See the "@Wire.endTransmission()@ documentation":http://arduino.cc/en/Reference/WireEndTransmission for return values.
101
102- @LSM303(void)@ := Constructor; initializes @m_min@ and @m_max@ with placeholder values.
103- @bool init(deviceType device, sa0State sa0)@ := Initializes the library with the device being used (@device_DLH@, @device_DLM@, @device_DLHC@, @device_D@, or @device_auto@) and the state of the SA0 pin (@sa0_low@, @sa0_high@, or @sa0_auto@), which determines the least significant bit(s) of the accelerometer address on some devices. Constants for these arguments are defined in LSM303.h. Both of these arguments are optional; if they are not specified, the library will try to automatically detect the device and accelerometer address[1]. A boolean is returned indicating whether an LSM303 device was successfully detected.
104*Note:* Automatic detection of the device type currently does not work with the Arduino Due because of issues with its Wire library. To work around this, specify the device and SA0 state manually (e.g. @init(LSM303::device_LSM303DLM, LSM303::sa0_high)@).
105- @byte getDeviceType(void)@ := Returns the device type detected by @init()@.
106- @void enableDefault(void)@ := Turns on the accelerometer and magnetometer and enables a consistent set of default settings.
107This function will set the accelerometer's full scale to be +/-2 g, which means that a reading of 16384 corresponds to approximately 1 g. The magnetometer's full scale is set to +/-4 gauss for the LSM303D or +/-1.3 gauss on all other devices. See the comments in LSM303.cpp for a full explanation of these settings.
108- @void writeReg(regAddr reg, byte value)@ := Writes an accelerometer or magnetometer register with the given value. Register addresses are defined by the regAddr enumeration type in LSM303.h.
109Example use: @compass.writeReg(LSM303::CTRL_REG1_A, 0x57);@
110- @void readReg(regAddr reg)@ := Reads an accelerometer or magnetometer register and returns the value read.[2]
111- @void writeAccReg(regAddr reg, byte value)@ := Writes an accelerometer register with the given value.
112- @byte readAccReg(regAddr reg)@ := Reads an accelerometer register and returns the value read.
113- @void writeMagReg(regAddr reg, byte value)@ := Writes a magnetometer register with the given value.
114- @byte readMagReg(regAddr reg)@ := Reads a magnetometer register and returns the value read. If the magnetometer data registers are read using register address constants without a specific device prefix (e.g. @OUT_Y_H_M@), this function will automatically use the correct register addresses depending on the device type.
115- @void readAcc(void)@ := Takes a reading from the accelerometer and stores the values in the vector @a@. Conversion of the readings to units of g depends on the accelerometer's selected gain (full scale setting).
116Note that in the LSM303DLHC, LSM303DLM, and LSM303DLH, the acceleration data registers actually contain a left-aligned 12-bit number, so the lowest 4 bits are always 0, and the values in @a@ should be shifted right by 4 bits (divided by 16) to be consistent with the conversion factors specified in the datasheets.
117- @void readMag(void)@ := Takes a reading from the magnetometer and stores the values in the vector @m@. Conversion of the readings to units of gauss depends on the magnetometer's selected gain (full scale setting).
118- @void read(void)@ := Takes a reading from both the accelerometer and magnetometer and stores the values in the vectors @a@ and @m@.
119- @void setTimeout(unsigned int timeout)@ := Sets a timeout period for @readAcc()@ and @readMag()@, in milliseconds, after which they will abort if no data is received. A value of 0 disables the timeout.
120- @unsigned int getTimeout(void)@ := Returns the current timeout period setting.
121- @bool timeoutOccurred(void)@ := Returns a boolean indicating whether a call to @readAcc()@ or @readMag()@ has timed out since the last call to @timeoutOccurred()@.
122- @float heading(void)@ := Returns the tilt-compensated heading of a default vector in degrees (the angular difference in the horizontal plane between the default vector and north). The default vector is chosen to point along the surface of the PCB, in the direction of the top of the text on the silkscreen. This is the +X axis on the Pololu LSM303D carrier and the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH carriers.
123- @float heading(vector from)@ := Returns the tilt-compensated heading of the given vector in degrees (the angular difference in the horizontal plane between @from@ and north).
124
125fn1. The automatic detection might fail if you do not use the Pololu boards' default accelerometer address, so you should specify your particular device if you change the state of the SA0 pin.
126
127fn2. This function will not work for reading TEMP_OUT_H_M and TEMP_OUT_L_M on the LSM303DLHC. To read those two registers, use @readMagReg()@ instead.
128
129h2. Version History
130
131* 2.0.0 (2013-11-27): Major rewrite. List of significant changes:
132** Added support for LSM303D.
133** Lowest 4 bits of accelerometer readings are no longer dropped before being stored in @a@; this makes the values returned by the library more consistent between the LSM303D and older sensors.
134** @enableDefault()@ behavior changed to be more consistent across devices.
135** @heading()@ now returns a float instead of an int.
136** Library constants converted to enums.
137** Added @writeReg()@ and @readReg()@, which should be usable in place of @writeAccReg()@, @readAccReg()@, @writeMagReg()@, and @readMagReg()@ in most situations.
138** @timeoutOccurred()@ now reports whether a timeout occurred since it was last called instead of only on the most recent @readAcc()@ or @readMag()@ call.
139** Magnetometer gain functions removed; unfortunately, they would have been hard to update to support the LSM303D.
140* 1.4.4 (2013-07-22): Corrected comments explaining @heading()@ function.
141* 1.4.3 (2013-03-15): Enable high resolution mode for LSM303DLHC accelerometer in @enableDefault()@.
142* 1.4.2 (2012-10-31): Cast sensor readings to 16-bit ints for better portability.
143* 1.4.1 (2012-07-06): Added @getDeviceType()@ function for programs that need to autodetect devices and distinguish between them.
144* 1.4.0 (2012-05-24): Added magnetometer gain functions and reading timeout feature; thanks to Joshua Hogendorn and Eric Brundick for these contributions. Added keywords.txt and changed file extensions of examples to .ino.
145* 1.3.0 (2011-12-12): Arduino 1.0 compatibility.
146* 1.2.0 (2011-11-15): Original release. (numbered to avoid confusion with our earlier "LSM303DLH library":https://github.com/pololu/LSM303DLH)
147** Besides the name change, the main difference in this library is that you need to call the @init()@ function before using any of the other library functions, typically from within the Arduino @setup()@ function. While the older library only works with the Pololu boards' default accelerometer slave address of 0011000b, this library allows you to specify the slave address with the @init()@ function.
Note: See TracBrowser for help on using the repository browser.