Skip to content
Harald Blab edited this page Sep 11, 2020 · 2 revisions

Intro

This library maybe used to control a QMC588L based compass board using I2C. It runs on the microcontroller.

For implementation I used a GY-271 compass modul. It has an I2C address of 0x0D.

Connection

Arduino Nano

Connect your board (left) to the Arduino Nano (right)

  • VCC -> 3.3V
  • GND -> GND
  • SDA -> A4
  • SCL -> A5

Arduino Uno

Connect your board (left) to the Arduino Uno (right)

  • VCC -> 3.3V
  • GND -> GND
  • SDA -> A4
  • SCL -> A5

API

The API allows you to create a controller and retrive data from it.

Constructor

The following statement creates an instance of your compass.

QMC5883L compass;

setup()

In the setup() method call begin() to initialze the compass device.

void begin()

Call begin() to initialze the device.

  • Intializes the device.
  • Mode: continuation mode.
  • Sampling rate: 128
  • Measure range: 2G

compass.begin();

All values are predefined and cant't be changed.

void begin(TwoWire *wire)

Call begin() to initialze the device on another I2C bus.

  • Intializes the device.
  • Mode: continuation mode.
  • Sampling rate: 128
  • Measure range: 2G

compass.begin(&Wire2);

All values are predefined and cant't be changed.

loop()

The following methods are call in the loop() method.

void readData()

Call readData() to read a new triple of values.

compass.readData();

The values read are stored in the instance.

int x,y,z; // triple axis data

You can access them with

  • compass.x
  • compass.y
  • compass.z

init heading()

Call heading() the get the heading to north current x,y, z value of the device.

int heading = compass.heading();

This method uses the last read values. So call readData() first to get valid values. Heading is a degree value relative to +x axis.

  • North -> 0
  • East -> 90
  • South -> 180
  • West -> 360

uint16_t temperature()

Use the temperature() method to get the temperature of the sensor.

ATTENTION: This is experimental!

uint16_t t = compass.temperature();

The value is returned in 100 per LSB.

Examples

Examples help you to get familiar with the controller.

QMC5883L_heading.ino

Reads the values and calculates the heading of the compass.

Resources

Datasheet: Datasheet