Fermion: BMM150 Triple Axis Magnetometer Sensor Breakout Wiki - DFRobot

Introduction

The BMM150 is a low-power and low noise 3-axis digital geomagnetic sensor that perfectly matches the requirements of compass applications. Based on Bosch’s proprietary FlipCore technology, the BMM150 provides absolute spatial orientation and motion vectors with high accuracy and dynamics. Featuring small size and lightweight, it is also especially suited for supporting drones in accurate heading. The BMM150 can also be used together with an inertial measurement unit consisting of a 3-axis accelerometer and a 3-axis gyroscope.

Features

Application

Specification

Board Overview

Board Overview

No. Silkscreen Function
1 VCC 3.3V Power Input
2 SCK Clock line
3 SDI SPI/I2C data line(input)
4 SDO SPI/I2C data line(output)
5 CS SPI chip-select, I2C Ground
6 PS Select communication protocol
7 DRDY Data Receiving/Transmitting ready status
8 INT Interrupt Pin

Note:

Connections for different communications

I2C Connection

Note: When using magDrdyInterrupt, connect pin DRDY to the related interrupt pin of mainboard instead of the pin INT.

Connection

Note: Pin PS should be connected to GND for SPI connection.

Mainboard Pin
Leonardo D3
micro:bit P0
ESP32/ESP8266/ARDUINO_SAM_ZERO(M0) D6
Raspberry Pi GPIO25
Only needs to be connected when interrupt is necessary

Tutorial for Using on M0

Connect the sensor with M0(or other mainboard) as the diagram shown below.

Connection M0

The default address is 0x13.

Requirements

Sample Code

Main API Function List

  /**
   * @fn softReset
   * @brief Soft reset, restore to suspended mode after soft reset and then enter sleep mode, soft reset can't be implemented under suspend mode
   */
  void softReset(void);

  /**
   * @fn setOperationMode
   * @brief Set sensor operation mode
   * @param opMode mode
   * @n BMM150_POWERMODE_NORMAL      normal mode  Get geomagnetic data normally
   * @n BMM150_POWERMODE_FORCED      forced mode  Single measurement, the sensor restores to sleep mode when the measurement is done.
   * @n BMM150_POWERMODE_SLEEP       sleep mode   Users can visit all the registers, but can’t measure geomagnetic data
   * @n BMM150_POWERMODE_SUSPEND     suspend mode At the time the sensor cpu doesn’t work and can’t implement any operation. Users can only visit the content of the control register BMM150_REG_POWER_CONTROL
   */
  void setOperationMode(uint8_t opMode);

  /**
   * @fn getOperationMode
   * @brief Get sensor operation mode
   * @return result Return sensor operation mode as a character string
   */
  String getOperationMode(void);

  /**
   * @fn setPresetMode
   * @brief Set preset mode, make it easier for users to configure sensor to get geomagnetic data 
   * @param presetMode
   * @n BMM150_PRESETMODE_LOWPOWER       Low power mode, get a fraction of data and take the mean value.
   * @n BMM150_PRESETMODE_REGULAR        Regular mode, get a number of data and take the mean value.
   * @n BMM150_PRESETMODE_ENHANCED       Enhanced mode, get a plenty of data and take the mean value.
   * @n BMM150_PRESETMODE_HIGHACCURACY   High accuracy mode, get a huge number of data and take the mean value.
   */
  void setPresetMode(uint8_t presetMode);

  /**
   * @fn setRate
   * @brief Set the rate of obtaining geomagnetic data, the higher, the faster (without delay function)
   * @param rate
   * @n BMM150_DATA_RATE_02HZ
   * @n BMM150_DATA_RATE_06HZ
   * @n BMM150_DATA_RATE_08HZ
   * @n BMM150_DATA_RATE_10HZ  (default rate)
   * @n BMM150_DATA_RATE_15HZ
   * @n BMM150_DATA_RATE_20HZ
   * @n BMM150_DATA_RATE_25HZ
   * @n BMM150_DATA_RATE_30HZ
   */
  void setRate(uint8_t rate);

  /**
   * @fn getRate
   * @brief Get the config data rate, unit: HZ
   * @return rate
   */
  uint8_t getRate(void);

  /**
   * @fn getGeomagneticData
   * @brief Get the geomagnetic data of 3 axis (x, y, z)
   * @return Geomagnetic data structure, unit: (uT)
   */
  sBmm150MagData_t getGeomagneticData(void);

  /**
   * @fn getCompassDegree
   * @brief Get compass degree
   * @return Compass degree (0° - 360°)
   * @n      0° = North, 90° = East, 180° = South, 270° = West.
   */
  float getCompassDegree(void);

  /**
   * @fn setDataReadyPin
   * @brief Enable or disable data ready interrupt pin
   * @n After enabling, the DRDY pin jump when there's data coming.
   * @n After disabling, the DRDY pin will not jump when there's data coming.
   * @n High polarity: active on high, the default is low level, which turns to high level when the interrupt is triggered.
   * @n Low polarity: active on low, default is high level, which turns to low level when the interrupt is triggered.
   * @param modes
   * @n     DRDY_ENABLE        Enable DRDY
   * @n     DRDY_DISABLE       Disable DRDY
   * @param polarity
   * @n     POLARITY_HIGH      High polarity
   * @n     POLARITY_LOW       Low polarity
   */
  void setDataReadyPin(uint8_t modes, uint8_t polarity=POLARITY_HIGH);

  /**
   * @fn getDataReadyState
   * @brief Get the data ready status, determine whether the data is ready
   * @return status
   * @n true  Data ready
   * @n false Data is not ready
   */
  bool getDataReadyState(void);

  /**
   * @fn setMeasurementXYZ
   * @brief Enable the measurement at x-axis, y-axis and z-axis, default to be enabled. After disabling, the geomagnetic data at x, y, and z axis are wrong.
   * @param channelX
   * @n   MEASUREMENT_X_ENABLE        Enable the measurement at x-axis
   * @n   MEASUREMENT_X_DISABLE       Disable the measurement at x-axis
   * @param channelY
   * @n   MEASUREMENT_Y_ENABLE        Enable the measurement at y-axis
   * @n   MEASUREMENT_Y_DISABLE       Disable the measurement at y-axis
   * @param channelZ
   * @n   MEASUREMENT_Z_ENABLE        Enable the measurement at z-axis
   * @n   MEASUREMENT_Z_DISABLE       Disable the measurement at z-axis
   */
  void setMeasurementXYZ(uint8_t channelX = MEASUREMENT_X_ENABLE, uint8_t channelY = MEASUREMENT_Y_ENABLE, uint8_t channelZ = MEASUREMENT_Z_ENABLE);

  /**
   * @fn getMeasurementStateXYZ
   * @brief Get the enabling status at x-axis, y-axis and z-axis
   * @return result Return enabling status as a character string
   */
  String getMeasurementStateXYZ(void);

  /**
   * @fn setThresholdInterrupt(uint8_t modes, int8_t threshold, uint8_t polarity)
   * @brief Set threshold interrupt, an interrupt is triggered when the geomagnetic value of a channel is beyond/below the threshold
   * @n      High polarity: active on high level, the default is low level, which turns to high level when the interrupt is triggered.
   * @n      Low polarity: active on low level, the default is high level, which turns to low level when the interrupt is triggered.
   * @param modes
   * @n     LOW_THRESHOLD_INTERRUPT       Low threshold interrupt mode
   * @n     HIGH_THRESHOLD_INTERRUPT      High threshold interrupt mode
   * @param  threshold
   * @n     Threshold, default to expand 16 times, for example: under low threshold mode, if the threshold is set to be 1, actually the geomagnetic data below 16 will trigger an interrupt
   * @param polarity
   * @n     POLARITY_HIGH      High polarity
   * @n     POLARITY_LOW       Low polarity
   */
  void setThresholdInterrupt(uint8_t modes, int8_t threshold, uint8_t polarity);

  /**
   * @fn setThresholdInterrupt(uint8_t modes, uint8_t channelX, uint8_t channelY, uint8_t channelZ, int8_t threshold, uint8_t polarity)
   * @brief Set threshold interrupt, an interrupt is triggered when the geomagnetic value of a channel is beyond/below the threshold
   * @n   When an interrupt occurs, INT pin level will jump
   * @n   High polarity: active on high level, the default is low level, which turns to high level when the interrupt is triggered.
   * @n   Low polarity: active on low level, the default is high level, which turns to low level when the interrupt is triggered.
   * @param modes
   * @n   LOW_THRESHOLD_INTERRUPT   Low threshold interrupt mode
   * @n   HIGH_THRESHOLD_INTERRUPT  High threshold interrupt mode
   * @param channelX
   * @n   INTERRUPT_X_ENABLE        Enable high threshold interrupt at x-axis
   * @n   INTERRUPT_X_DISABLE       Disable high threshold interrupt at x-axis
   * @param channelY
   * @n   INTERRUPT_Y_ENABLE         Enable high threshold interrupt at y-axis
   * @n   INTERRUPT_Y_DISABLE        Disable high threshold interrupt at y-axis
   * @param channelZ
   * @n   INTERRUPT_Z_ENABLE         Enable high threshold interrupt at z-axis
   * @n   INTERRUPT_Z_DISABLE        Disable high threshold interrupt at z-axis
   * @param  threshold
   * @n   Threshold, default to expand 16 times, for example: if the threshold is set to be 1, actually the geomagnetic data below 16 will trigger an interrupt
   * @param polarity
   * @n     POLARITY_HIGH      High polarity
   * @n     POLARITY_LOW       Low polarity
   */
  void setThresholdInterrupt(uint8_t modes, uint8_t channelX, uint8_t channelY, uint8_t channelZ, int8_t threshold, uint8_t polarity);

  /**
   * @fn getThresholdData
   * @brief Get the data with threshold interrupt occurred
   * @return Returns the structure for storing geomagnetic data, the structure stores the data of 3 axis and interrupt status,
   * @n The interrupt is not triggered when the data at x-axis, y-axis and z-axis are NO_DATA
   * @n String state The storage state is binary data string
   * @n uint8_t value The storage state is binary raw value, the data format are as follows:
   * @n bit0 is 1 Indicate the interrupt occur at x-axis
   * @n bit1 is 1 Indicate the interrupt occur at y-axis
   * @n bit2 is 1 Indicate the interrupt occur at z-axis
   * @n ------------------------------------
   * @n | bit7 ~ bit3 | bit2 | bit1 | bit0 |
   * @n ------------------------------------
   * @n |  reserved   |  0   |  0   |  0   |
   * @n ------------------------------------
   */
  sBmm150ThresholdData_t getThresholdData(void);

  /**
   * @fn selfTest
   * @brief The sensor self test, the returned value indicate the self test result.
   * @param testMode:
   * @n    BMM150_SELF_TEST_NORMAL               Normal self test, test whether x-axis, y-axis and z-axis are connected or short-circuited
   * @n    BMM150_SELF_TEST_ADVANCED             Advanced self test, test the data accuracy at z-axis
   * @return result The returned character string is the self test result
   */
  String selfTest(uint8_t testMode);

Sample Code 1 - get configuration status(getAllState.ino)

GetAllState

Result

Result 1

Sample Code 2 - get geomagnetic data, compass angle(getGeomagneticData.ino)

Sample 2

Result

Result 2

Sample Code 3 - prepare interrupt function(magDrdyInterrupt.ino)

Sample 3

Result

Result 4

Sample Code 4 - threshold interrupt function(thresholdInterrupt.ino)

Sample 4

Result

Result 4

Tutorial for Using on Raspberry Pi

Requirements

Connection Diagram

Connection Raspberry Pi

Installing Driver

  1. Enable Raspberry Pi I2C(skip this step if it is already enabled). Open the terminal and enter the following command.
 sudo raspi-config

Use the up/down keys to select "5 Interface Options". Press enter, select "P5 I2C". Press enter to comfirm "YES". Restart your Raspberry Pi.

  1. Install Python dependency lirary and git(skip this step if already installed). Raspberry Pi needs to be connected with internet. Open the terminal and enter the following commands in order.
sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus git
  1. Download BMM150 library. Open the terminal and enter the following commands in order.
cd Desktop
git clone https://github.com/DFRobot/DFRobot_BMM150

Sample Code

Sample Code 1 - get configuration status(get_all_state.py)

  cd DFRobot_BMM150/python/raspberrypi/examples
cd get_all_state
python get_all_state.py

Result

Sample 1

Sample Code 2 - get geomagnetic data, compass angle(get_geomagnetic_data.py)

  cd DFRobot_BMM150/python/raspberrypi/examples 
 cd get_geomagnetic_data
 python get_geomagnetic_data.py

Result

Sample 2

Sample Code 3 - prepare interrupt function(data_ready_interrupt.py)

  cd DFRobot_BMM150/python/raspberrypi/examples
  cd data_ready_interrupt
  python data_ready_interrupt.py.py

Result

Sample 3

Sample Code 4 - threshold interrupt function(threshold_interrupt.py)

  cd DFRobot_BMM150/python/raspberrypi/examples
  cd threshold_interrupt
  python threshold_interrupt.py

Result

Sample 4

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Fermion: BMM150 Triple Axis Magnetometer Sensor(Breakout) from DFRobot Store or DFRobot Distributor.

Turn to the Top