public class HMC5883L extends I2C implements SensorModule, LiveWindowSendable
The Honeywell HMC5883L magnetoresistive sensor circuit is a trio of sensors and application specific support circuits to measure magnetic fields. With power supply applied, the sensor converts any incident magnetic field in the sensitive axis directions to a differential voltage output. The magnetoresistive sensors are made of a nickel-iron (Permalloy) thin-film and patterned as a resistive strip element. In the presence of a magnetic field, a change in the bridge resistive elements causes a corresponding change in voltage across the bridge outputs.
These resistive elements are aligned together to have a common sensitive axis (indicated by arrows in the pinout diagram) that will provide positive voltage change with magnetic fields increasing in the sensitive direction. Because the output is only proportional to the magnetic field component along its axis, additional sensor bridges are placed at orthogonal directions to permit accurate measurement of magnetic field in any orientation.
To check the HMC5883L for proper operation, a self test feature in incorporated in which the sensor is internally excited with a nominal magnetic field (in either positive or negative bias configuration). This field is then measured and reported. This function is enabled and the polarity is set by bits MS[n] in the configuration register A. An internal current source generates DC current (about 10 mA) from the VDD supply. This DC current is applied to the offset straps of the magnetoresistive sensor, which creates an artificial magnetic field bias on the sensor. The difference of this measurement and the measurement of the ambient field will be put in the data output register for each of the three axes. By using this built-in function, the manufacturer can quickly verify the sensor’s full functionality after the assembly without additional test setup. The self test results can also be used to estimate/compensate the sensor’s sensitivity drift due to temperature.
| Modifier and Type | Class and Description |
|---|---|
static class |
HMC5883L.Averaging
Select number of samples averaged (1 to 8) per measurement output.
|
static class |
HMC5883L.Axis
Enum representation of each of the three Axes.
|
static class |
HMC5883L.Gain
Gain Configuration Bits
These bits configure the gain for the device.
|
static class |
HMC5883L.MeasurementMode
Measurement Configuration Bits.
|
static class |
HMC5883L.OperatingMode
Mode Select Bits.
|
static class |
HMC5883L.OutputRate
Data Output Rate Bits
These bits set the rate at which data is written to
all three data output registers.
|
Interface.InterfaceType| Modifier and Type | Field and Description |
|---|---|
static byte |
HMC_I2C_ADDR
Device I2C Address
|
static byte |
HMC_LOCK_BIT
Data output register lock
|
static byte |
HMC_READY_BIT
Ready Bit
|
static byte |
HMC_REG_CFG_A
Configuration Register A
|
static byte |
HMC_REG_CFG_B
Configuration Register B
|
static byte |
HMC_REG_CFG_MODE
Mode Register
|
static byte |
HMC_REG_IDA
Identification Register A
|
static byte |
HMC_REG_IDB
Identification Register B
|
static byte |
HMC_REG_IDC
Identification Register C
|
static byte |
HMC_REG_STATUS
Status Register
|
static byte |
HMC_REG_X_LSB
Data Output X LSB Register
|
static byte |
HMC_REG_X_MSB
Data Output X MSB Register
|
static byte |
HMC_REG_Y_LSB
Data Output Y LSB Register
|
static byte |
HMC_REG_Y_MSB
Data Output Y MSB Register
|
static byte |
HMC_REG_Z_LSB
Data Output Z LSB Register
|
static byte |
HMC_REG_Z_MSB
Data Output Z MSB Register
|
static byte |
HMC_SCALE
Axes scale value
|
private HMC5883L.Averaging |
m_averaging |
private HMC5883L.Gain |
m_gain |
private boolean |
m_highSpeed |
private HMC5883L.MeasurementMode |
m_mMode |
private HMC5883L.OperatingMode |
m_oMode |
private HMC5883L.OutputRate |
m_rate |
private ITable |
m_table |
m_ifaceType, MAX_ANALOG_IN_CHANNELS, MAX_ANALOG_OUT_CHANNELS, MAX_DIGITAL_CHANNELS, MAX_PWM_CHANNELS, MAX_RELAY_CHANNELS| Constructor and Description |
|---|
HMC5883L(I2C.Port port)
Create a new HMC5883L compass on I2C Port.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disableModule()
Disable the module
|
void |
enableModule()
Enable the module
|
double[] |
getAllMagnitudes()
Get all magnitude values.
|
HMC5883L.Gain |
getGain()
Get the
HMC5883L.Gain used for measurements. |
double |
getHeadingXDeg()
Get the heading around the X axis in degrees.
|
double |
getHeadingXRad()
Get the heading around the X axis in radians.
|
double |
getHeadingYDeg()
Get the heading around the Y axis in degrees.
|
double |
getHeadingYRad()
Get the heading around the Y axis in radians.
|
double |
getHeadingZDeg()
Get the heading around the Z axis in degrees.
|
double |
getHeadingZRad()
Get the heading around the Z axis in radians.
|
boolean |
getLock()
Data output register lock bit status.
|
double |
getMagnitude(HMC5883L.Axis axis)
Get magnitude for givien
HMC5883L.Axis |
HMC5883L.MeasurementMode |
getMeasurementMode()
Get the
HMC5883L.MeasurementMode being used. |
boolean |
getModuleEnabled() |
HMC5883L.OperatingMode |
getOperatingMode()
Get the
HMC5883L.OperatingMode being run. |
HMC5883L.OutputRate |
getOutputRate()
Get the
HMC5883L.OutputRate being used. |
boolean |
getReady()
Get the status of the Ready Bit.
|
HMC5883L.Averaging |
getSamplesPerAverage()
Get the
HMC5883L.Averaging mode being used. |
java.lang.String |
getSmartDashboardType() |
ITable |
getTable() |
boolean |
getUsingHighSpeed()
Get whether or not we are using High Speed I2C mode (3400kHz)
|
double |
getXMagnitude()
Get magnitude for the X Axis.
|
double |
getYMagnitude()
Get magnitude for the Y Axis.
|
double |
getZMagnitude()
Get magnitude for the Z Axis.
|
void |
initTable(ITable subtable) |
private double |
magnitudeFromBytes(byte first,
byte second)
Turn two bytes into a magnitude
|
void |
setGain(HMC5883L.Gain gain)
Set the
HMC5883L.Gain to use for measurement. |
void |
setMeasurementMode(HMC5883L.MeasurementMode mode)
Set the
HMC5883L.MeasurementMode to use |
void |
setOperatingMode(HMC5883L.OperatingMode mode)
Set the
HMC5883L.OperatingMode to run in. |
void |
setOutputRate(HMC5883L.OutputRate rate)
Set the
HMC5883L.OutputRate to used. |
void |
setSamplesPerAverage(HMC5883L.Averaging avg)
Set the
HMC5883L.Averaging mode to use. |
void |
setUsingHighSpeed(boolean highSpeed)
Set whether or not to use High Speed I2C mode (3400kHz)
|
void |
startLiveWindowMode() |
void |
stopLiveWindowMode() |
void |
updateTable() |
private void |
writeModeRegister()
Write the Mode configuration register
|
private void |
writeRegisterA()
Write the A configuration register
|
private void |
writeRegisterB()
Write the B configuration register
|
broadcast, checkAddress, free, read, readBit, readBit, readBits, readByte, readBytes, readOnly, readWord, readWords, transaction, verifySensor, write, writeBit, writeBit, writeBits, writeBulk, writeByte, writeBytes, writeWord, writeWordsallocateMXPPin, checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPWMChannel, checkRelayChannel, freeMXPPin, getInterfaceTypepublic static final byte HMC_I2C_ADDR
public static final byte HMC_SCALE
public static final byte HMC_LOCK_BIT
public static final byte HMC_READY_BIT
public static final byte HMC_REG_CFG_A
public static final byte HMC_REG_CFG_B
public static final byte HMC_REG_CFG_MODE
public static final byte HMC_REG_X_MSB
public static final byte HMC_REG_X_LSB
public static final byte HMC_REG_Z_MSB
public static final byte HMC_REG_Z_LSB
public static final byte HMC_REG_Y_MSB
public static final byte HMC_REG_Y_LSB
public static final byte HMC_REG_STATUS
public static final byte HMC_REG_IDA
public static final byte HMC_REG_IDB
public static final byte HMC_REG_IDC
private HMC5883L.MeasurementMode m_mMode
private HMC5883L.OutputRate m_rate
private HMC5883L.Averaging m_averaging
private HMC5883L.Gain m_gain
private HMC5883L.OperatingMode m_oMode
private boolean m_highSpeed
private ITable m_table
public HMC5883L(I2C.Port port)
port - public double getHeadingXRad()
public double getHeadingXDeg()
public double getXMagnitude()
public double getHeadingYRad()
public double getHeadingYDeg()
public double getYMagnitude()
public double getHeadingZRad()
public double getHeadingZDeg()
public double getZMagnitude()
public double getMagnitude(HMC5883L.Axis axis)
HMC5883L.Axisaxis - the HMC5883L.Axis to getHMC5883L.Axispublic double[] getAllMagnitudes()
public boolean getLock()
This bit is set when:
When this bit is set, the six data output registers are locked and any new data will not be placed in these register until one of these conditions are met:
public boolean getReady()
private double magnitudeFromBytes(byte first,
byte second)
first - the MSB bytesecond - the LSB byteprivate void writeRegisterA()
private void writeRegisterB()
private void writeModeRegister()
public void setMeasurementMode(HMC5883L.MeasurementMode mode)
HMC5883L.MeasurementMode to usemode - the HMC5883L.MeasurementMode to useHMC5883L.MeasurementModepublic HMC5883L.MeasurementMode getMeasurementMode()
HMC5883L.MeasurementMode being used.HMC5883L.MeasurementMode being used.HMC5883L.MeasurementModepublic void setOutputRate(HMC5883L.OutputRate rate)
HMC5883L.OutputRate to used.rate - the HMC5883L.OutputRate to used.HMC5883L.OutputRatepublic HMC5883L.OutputRate getOutputRate()
HMC5883L.OutputRate being used.HMC5883L.OutputRate being used.HMC5883L.OutputRatepublic void setSamplesPerAverage(HMC5883L.Averaging avg)
HMC5883L.Averaging mode to use.avg - the HMC5883L.Averaging mode to use.HMC5883L.Averagingpublic HMC5883L.Averaging getSamplesPerAverage()
HMC5883L.Averaging mode being used.HMC5883L.Averaging mode being used.HMC5883L.Averagingpublic void setGain(HMC5883L.Gain gain)
HMC5883L.Gain to use for measurement.gain - the HMC5883L.Gain to use.HMC5883L.Gainpublic HMC5883L.Gain getGain()
HMC5883L.Gain used for measurements.HMC5883L.Gain used for measurements.HMC5883L.Gainpublic void setOperatingMode(HMC5883L.OperatingMode mode)
HMC5883L.OperatingMode to run in.mode - the HMC5883L.OperatingMode to run in.HMC5883L.OperatingModepublic HMC5883L.OperatingMode getOperatingMode()
HMC5883L.OperatingMode being run.HMC5883L.OperatingMode being run.HMC5883L.OperatingModepublic void setUsingHighSpeed(boolean highSpeed)
highSpeed - use high speed or notpublic boolean getUsingHighSpeed()
public void updateTable()
updateTable in interface UpdatingSendablepublic java.lang.String getSmartDashboardType()
getSmartDashboardType in interface Sendablepublic void startLiveWindowMode()
startLiveWindowMode in interface LiveWindowSendablepublic void stopLiveWindowMode()
stopLiveWindowMode in interface LiveWindowSendablepublic void enableModule()
enableModule in interface Modulepublic void disableModule()
disableModule in interface Modulepublic boolean getModuleEnabled()
getModuleEnabled in interface Module