0% found this document useful (0 votes)
415 views7 pages

hmc5883l Compass Tutorial

This document provides instructions for using the HMC5883L digital compass sensor with a Raspberry Pi. It explains that the sensor measures magnetic field strength to determine orientation relative to true north. The tutorial covers connecting the sensor hardware, installing required software packages and libraries, and provides a sample Python program to continuously read compass readings and calculate heading. The program output displays magnetic field measurements and calculated heading relative to the magnetic declination entered.

Uploaded by

api-248437787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
415 views7 pages

hmc5883l Compass Tutorial

This document provides instructions for using the HMC5883L digital compass sensor with a Raspberry Pi. It explains that the sensor measures magnetic field strength to determine orientation relative to true north. The tutorial covers connecting the sensor hardware, installing required software packages and libraries, and provides a sample Python program to continuously read compass readings and calculate heading. The program output displays magnetic field measurements and calculated heading relative to the magnetic declination entered.

Uploaded by

api-248437787
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

HMC5883L Compass: Raspberry Pi Tutorial

1. THE SENSOR
1.1. The HMC5883L Compass is a type of sensor called a magnetometer. This
sensor measures the magnetic field strength (in microTesla) of the Earth and
provides its component values (x, y, z). It outputs those three measurements and
calculates your orientation with respect to true north.
1.2. Limitation: The sensor must be calibrated in order to provide useful information.

2. HARDWARE CONNECTIONS
3. SUPPORTING PROGRAMS
3.1. The packages youll need are: I2C tools, python smbus
First, I2C automatic loading must be enabled through the Pis
configuration tool. Enter the configuration tool in the terminal by entering
sudo raspi-config. Then choose option 8, then option A7.
When youre returned to the terminal, run an update and upgrade before
downloading the packages. This is done by entering the following two
commands:
sudo apt-get update
sudo apt-get upgrade
Next download the packages with the following two commands:
sudo apt-get install i2c-tools
sudo apt-get install python-smbus
3.2. Libraries: Quick2Wire Python API, sensor library
The libraries can also be downloaded straight from your terminal.
Open the terminal and navigate to your projects directory.
Download libraries by entering git clone [library url] like this:

4. TUTORIAL WITH SAMPLE PROGRAM


4.1. You can find a detailed tutorial with more information at the following page:
Interfacing Digital Compass (HMC5883L) with Raspberry Pi 2 using
Python3

5. SAMPLE PROGRAM
5.1. Line 1: Imports sensor functions from I2C library.
5.2. Line 2: Selects I2C port.
5.3. Line 3: Specifies that sensor should continuously make readings.
5.4. Line 4: Passes the magnetic declination of your location as the argument. The
magnetic declination is the angle between magnetic north and true north at your
location.
5.5. Line 5: Prints the magnetic field strength measurements and calculated compass
heading.

6. SAMPLE PROGRAM OUTPUT


6.1. The program ran successfully, but I had to run the program in root user mode
and while in this mode I could not make screenshots. So this is the sample output
from the tutorial page linked in 4.1 and shown in 5. It outputs, in mT, the
magnetic field strength x-/y-/z-components, the declination that was entered in
Line 4 of the code, and heading (angle from north = 0).
Note: All images and screenshots are my own except the sample program output image in 6.1.

You might also like