API for the AK8975 magnetometer.
More...
- ID: ak8975
- Name: AK8975 3-axis Magnetometer
- Other Names: AK9875
- Category: compass
- Manufacturer: seeed
- Connection: i2c
This is a 3-axis magnetometer, which can be used alone, or coupled with another device (such as the mcu9150 9-axis motion sensor).
while (shouldRun)
{
float x, y, z;
cout << "Magnetometer: ";
cout << "MX = " << x << " MY = " << y << " MZ = " << z << endl;
cout << endl;
usleep(500000);
}
|
enum | AK8975_REG_T {
REG_WIA = 0x00,
REG_INFO = 0x01,
REG_ST1 = 0x02,
REG_HXL = 0x03,
REG_HXH = 0x04,
REG_HYL = 0x05,
REG_HYH = 0x06,
REG_HZL = 0x07,
REG_HZH = 0x08,
REG_ST2 = 0x09,
REG_CNTL = 0x0a,
REG_ASTC = 0x0c,
REG_ASAX = 0x10,
REG_ASAY = 0x11,
REG_ASAZ = 0x12
} |
|
enum | ST1_BITS_T { ST1_DRDY = 0x01
} |
|
enum | ST2_BITS_T { ST2_DERR = 0x04,
ST2_HOFL = 0x08
} |
|
enum | CNTL_MODES_T { CNTL_PWRDWN = 0x00,
CNTL_MEASURE = 0x01,
CNTL_SELFTEST = 0x08,
CNTL_FUSE_ACCESS = 0x0f
} |
|
enum | ASTC_BITS_T { ASTC_SELF = 0x40
} |
|
|
float | m_xCoeff |
|
float | m_yCoeff |
|
float | m_zCoeff |
|
float | m_xData |
|
float | m_yData |
|
float | m_zData |
|
CNTL register, operating mode values
ASTC (self test control) bits
AK8975 |
( |
int |
bus = AK8975_I2C_BUS , |
|
|
uint8_t |
address = AK8975_DEFAULT_I2C_ADDR |
|
) |
| |
ak8975 constructor
- Parameters
-
bus | i2c bus to use |
address | the address for this device |
set up initial values and start operation
- Parameters
-
dsr | the data sampling rate: one of the DSR_BITS_T values |
- Returns
- true if successful
put the chip into a specific mode
- Parameters
-
mode | one of the CNTL_MODES_T values |
- Returns
- true if successful
check to see if the ST1_DRDY bit is set, indicating the device can accept commands
- Returns
- true if device is ready, false otherwise
bool waitforDeviceReady |
( |
| ) |
|
check to see if device is ready and sleep/retry if not. Returns once device indicates it's ready.
- Returns
- true if device is ready, false if retries exhausted
bool update |
( |
bool |
selfTest = false | ) |
|
take a measurement
- Parameters
-
selfTest | true if we are running a self test, false (default) otherwise. |
- Returns
- true if successful, false otherwise
do a self test sequence. When self test is executed, the device activates internal calibrated magnets, and measures them, updating the measurement registers. Once complete, the data can be read as usual (getMagnetometer()) and the returned values compared against the following limits to determine correctness:
-100 < X < +100; -100 < Y < +100; -1000 < Z < -300
- Returns
- true if successful, false otherwise
void getMagnetometer |
( |
float * |
x, |
|
|
float * |
y, |
|
|
float * |
z |
|
) |
| |
return the compensated values for the x, y, and z axes. The unit of measurement is in micro-teslas (uT).
- Parameters
-
x | pointer to returned X axis value |
y | pointer to returned Y axis value |
z | pointer to returned Z axis value |
float adjustValue |
( |
float |
value, |
|
|
float |
adj |
|
) |
| |
|
protected |
compute a compensated magnetometer axis value, based on the raw axis value and a per-device, per-axis adjustment coefficient that was read and stored at init() time.
- Parameters
-
value | the raw axis value to compensate |
adj | the adjustment coefficient |
- Returns
- true if successful
The documentation for this class was generated from the following files:
- /iotdk/jenkins/workspace/upm-doc-stable/src/mpu9150/ak8975.h
- /iotdk/jenkins/workspace/upm-doc-stable/src/mpu9150/ak8975.cxx