Example Code for Raspberry Pi-get geomagnetic data and compass angle

Last revision 2026/01/21

Get the geomagnetic data of the 3 axes and the compass angle on Raspberry Pi.

Hardware Preparation

Software Preparation

Wiring Diagram

Connect the module with Raspberry Pi as shown below. Default address: 0x13.

Connection Raspberry Pi

Other Preparation Work

  1. Enable Raspberry Pi I2C (follow steps in previous example).
  2. Install dependencies (follow steps in previous example).
  3. Download the library (follow steps in previous example).
  4. Navigate to the sample code directory:
    • cd DFRobot_BMM150/python/raspberrypi/examples/get_geomagnetic_data

Sample Code

Open the terminal and enter the following commands to run the sample code:

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

Result

Sample 2

Was this article helpful?

TOP