Show:

BO.io.MagnetometerHMC5883 Class

Creates an interface to an HMC5883 3-axis magnetometer. Use the magnetometer to obtain a compass heading or rotation in relation to a fixed point. See Breakout/examples/sensors/hmc5883.html for an example application.

Constructor

BO.io.MagnetometerHMC5883

(
  • board
  • address
  • numSamples
  • outputRate
)

Parameters:

  • board IOBoard

    The IOBoard instance

  • address Number

    The i2c address of the compass module

  • numSamples Number

    The number of samples averaged per measurement output. Options are: MagnetometerHMC5883.SAMPLES_1, MagnetometerHMC5883.SAMPLES_2, MagnetometerHMC5883.SAMPLES_4 MagnetometerHMC5883.SAMPLES_8 (default = MagnetometerHMC5883.SAMPLES_1)

  • outputRate Number

    The data output rate in Hz (default = MagnetometerHMC5883.HZ_30)

Methods

addEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

dispatchEvent

(
  • type
  • optionalParams
)

Parameters:

  • type Event

    The Event object.

  • optionalParams Object

    Optional parameters passed as an object. return {boolean} True if dispatch is successful, false if not.

getHeading

() private

getTiltCompensatedHeading

(
  • pitch
  • roll
)
Number private

Get a tilt-compensated heading. Pitch and roll values from an accelerometer must be passed to this method.

Note: this method is not working properly. Marking it private until resolved

Parameters:

  • pitch Number

    The pitch value (supplied by an accelerometer)

  • roll Number

    The roll value (supplied by an accelerometer)

Returns:

Number:

tilt-compensated heading direction

handleI2C

() private

Inherited from BO.I2CBase but overwritten in src/io/MagnetoMeterHMC5883.js:124

hasEventListener

(
  • type
)

Parameters:

  • type String

    The event type return {boolean} True is listener exists for this type, false if not.

removeEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

sendI2CRequest

(
  • command
  • data
)
protected

Send an i2c request command to the board

Parameters:

  • command Number
  • data Number

startReading

()

Start continuous reading of the sensor.

stopReading

()

Stop continuous reading of the sensor.

update

()

Inherited from BO.I2CBase but overwritten in src/io/MagnetoMeterHMC5883.js:243

Sends read request to magnetometer and updates magnetometer values.

Properties

address

Number

[read-only] The address of the i2c device.

heading

Number

[read-only] The heading in degrees.

I2CBase.I2C_REPLY

Unknown

MagnetometerHMC5883.DEVICE_ID

Unknown static

MagnetometerHMC5883.HZ_0_75

Unknown static

MagnetometerHMC5883.HZ_15

Unknown static

MagnetometerHMC5883.HZ_1_5

Unknown static

MagnetometerHMC5883.HZ_3

Unknown static

MagnetometerHMC5883.HZ_30

Unknown static

MagnetometerHMC5883.HZ_75

Unknown static

MagnetometerHMC5883.HZ_7_5

Unknown static

MagnetometerHMC5883.SAMPLES_1

Unknown static

MagnetometerHMC5883.SAMPLES_2

Unknown static

MagnetometerHMC5883.SAMPLES_4

Unknown static

MagnetometerHMC5883.SAMPLES_8

Unknown static

x

Number

[read-only] The x-axis measurement

y

Number

[read-only] The y-axis measurement

z

Number

[read-only] The z-axis measurement

Events

update

BO.io.MagnetometerEvent.UPDATE

The update event is dispatched when the compass heading is updated.

Event Payload: