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
- Raspberry Pi 4 Model B-2GB (or similar) x 1
- BMM150 Triple Axis Magnetometer Sensor x1
- Dupont Wires
Software Preparation
- BMM150 Sensor Python Library
- RASPBIAN Official OS
Wiring Diagram
Connect the module with Raspberry Pi as shown below. Default address: 0x13.

Other Preparation Work
- Enable Raspberry Pi I2C (follow steps in previous example).
- Install dependencies (follow steps in previous example).
- Download the library (follow steps in previous example).
- 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

Was this article helpful?
