-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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.
Connect your board (left) to the Arduino Nano (right)
- VCC -> 3.3V
- GND -> GND
- SDA -> A4
- SCL -> A5
Connect your board (left) to the Arduino Uno (right)
- VCC -> 3.3V
- GND -> GND
- SDA -> A4
- SCL -> A5
The API allows you to create a controller and retrive data from it.
The following statement creates an instance of your compass.
QMC5883L compass;
In the setup() method call begin() to initialze the compass device.
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.
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.
The following methods are call in the loop() method.
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
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
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 help you to get familiar with the controller.
Reads the values and calculates the heading of the compass.
Datasheet: Datasheet