Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otQMC5883 Class Reference
[QMC5883 - Three-axis magnetic sensor., QMC5883 - Three-axis magnetic sensor.]

Library for the management of the QMC5883 magnetometer. More...

#include <otQMC5883.h>


Public Types

enum  OP_MODE {
  OPM_STANDBY = 0x00, OPM_CONTINUOUS = 0x01, OPM_DATARATE_10HZ = ((0x00) << 2), OPM_DATARATE_50HZ = ((0x01) << 2),
  OPM_DATARATE_100HZ = ((0x2) << 2), OPM_DATARATE_200HZ = ((0x3) << 2), OPM_SCALE_2G = ((0x00) << 4), OPM_SCALE_8G = ((0x01) << 4),
  OPM_OVER_SMP_512 = ((0x00) << 4), OPM_OVER_SMP_256 = ((0x01) << 4), OPM_OVER_SMP_128 = ((0x02) << 4), OPM_OVER_SMP_64 = ((0x03) << 4)
}

Public Member Functions

 otQMC5883 ()
void init (int filterDepth=16, int filterAverage=2, U8 timerId=TIMER0)
void setMode (U8 mode, U8 odr, U8 rng, U8 osr)
void read ()
void calibrate (U32 timeCheck=10, bool dbg=false)
void setMagneticDeclination (int degrees, U8 minutes)
void reset ()
void setCalibration (int x_min, int x_max, int y_min, int y_max, int z_min, int z_max)
float getCalibrationScale (U8 index)
void setCalibrationScales (float x_scale=1.0f, float y_scale=1.0f, float z_scale=1.0f)
void setCalibrationOffsets (float x_offset=0.0f, float y_offset=0.0f, float z_offset=0.0f)
float getCalibrationOffset (U8 index)
int getX ()
double gaussX ()
int getY ()
double gaussY ()
int getZ ()
double gaussZ ()
int getAzimuth ()
void getDirection (char *myArray, int azimuth)
U8 getBearing (int azimuth)
void clearCalibration ()
int temperature ()


Detailed Description


Member Enumeration Documentation

enum otQMC5883::OP_MODE
 

Enumeration values:
OPM_STANDBY  Mode Control.
OPM_CONTINUOUS  Mode Control.
OPM_DATARATE_10HZ  Output Data Rate 10Hz.
OPM_DATARATE_50HZ  Output Data Rate 50Hz.
OPM_DATARATE_100HZ  Output Data Rate 100Hz.
OPM_DATARATE_200HZ  Output Data Rate 200Hz.
OPM_SCALE_2G  Full scale 2 Gauss.
OPM_SCALE_8G  Full scale 8 Gauss.
OPM_OVER_SMP_512  Over sample ratio 512.
OPM_OVER_SMP_256  Over sample ratio 256.
OPM_OVER_SMP_128  Over sample ratio 128.
OPM_OVER_SMP_64  Over sample ratio 64.


Constructor & Destructor Documentation

otQMC5883.otQMC5883 (   ) 
 

Create the class


Member Function Documentation

void otQMC5883.calibrate (  U32  timeCheck = 10,
bool  dbg = false
) 
 

Automatic calibration. This will provide calibration settings for your QMC5883L chip.
When prompted, move the magnetometer in all directions until the calibration is complete.

Parameters:
timeCheck Test duration in seconds
dbg True to show debug informations

void otQMC5883.clearCalibration (   ) 
 

Remove any calibration data

double otQMC5883.gaussX (   ) 
 

Read the X axis as Gauss

Returns:
X axis

double otQMC5883.gaussY (   ) 
 

Read the Y axis as Gauss

Returns:
Y axis

double otQMC5883.gaussZ (   ) 
 

Read the Z axis as Gauss

Returns:
Z axis

int otQMC5883.getAzimuth (   ) 
 

Calculate the azimuth (in degrees) Correct the value with magnetic declination if defined.

Returns:
Currently pointing

U8 otQMC5883.getBearing (  int  azimuth  ) 
 

Divide the 360 degree circle into 16 equal parts and then return the a value of 0-15 based on where the azimuth is currently pointing.

Parameters:
azimuth Currently pointing
Returns:
Direction of bearing

float otQMC5883.getCalibrationOffset (  U8  index  ) 
 

Set the calibrations offset of each axys

Parameters:
index 0 = X, 1 = Y, 2 = Z
Returns:
Calibration scale of selected axys

float otQMC5883.getCalibrationScale (  U8  index  ) 
 

Get calibration scale of each axys

Parameters:
index 0 = X, 1 = Y, 2 = Z
Returns:
Calibration scale of selected axys

void otQMC5883.getDirection (  char *  myArray,
int  azimuth
) 
 

This will take the location of the azimuth as calculated in getBearing() and then produce an array of chars as a text representation of the direction.

Parameters:
myArray Reference back
azimuth Currently pointing

int otQMC5883.getX (   ) 
 

Read the X axis

Returns:
X axis

int otQMC5883.getY (   ) 
 

Read the Y axis

Returns:
Y axis

int otQMC5883.getZ (   ) 
 

Read the Z axis

Returns:
Z axis

void otQMC5883.init (  int  filterDepth = 16,
int  filterAverage = 2,
U8  timerId = TIMER0
) 
 

Must be the first command after creating the otQMC5883 object.

Parameters:
filterDepth Depth of history filter
filterAverage Average of center filter
timerId Used timer for all timings

void otQMC5883.read (   ) 
 

Read the XYZ axis and save the values in an array.

void otQMC5883.reset (   ) 
 

Reset device

void otQMC5883.setCalibration (  int  x_min,
int  x_max,
int  y_min,
int  y_max,
int  z_min,
int  z_max
) 
 

Set calibration values for more accurate readings See: TheNitek [https://github.com/TheNitek]

Parameters:
x_min X minimum value
x_max X maximum value
y_min Y minimum value
y_max Y maximum value
z_min Z minimum value
z_max Z maximum value

void otQMC5883.setCalibrationOffsets (  float  x_offset = 0.0f,
float  y_offset = 0.0f,
float  z_offset = 0.0f
) 
 

Set the calibrations offset of each axys

Parameters:
x_offset X offset
y_offset Y offset
z_offset Z offset

void otQMC5883.setCalibrationScales (  float  x_scale = 1.0f,
float  y_scale = 1.0f,
float  z_scale = 1.0f
) 
 

Set the calibrations scale of each axys

Parameters:
x_scale X scale
y_scale Y scale
z_scale Z scale

void otQMC5883.setMagneticDeclination (  int  degrees,
U8  minutes
) 
 

Define the magnetic declination for accurate degrees. see: https://www.magnetic-declination.com/ Example: Pisa in Italy as +3degree and 7' use: setMagneticDeclination(3, 7);

Parameters:
degrees Degree of magnetic declination
minutes Minute of magnetic declination

void otQMC5883.setMode (  U8  mode,
U8  odr,
U8  rng,
U8  osr
) 
 

Set the chip mode. /see OP_MODE

Parameters:
mode Operation mode
odr Output Data Rate
rng Full scale
osr Over sample ratio

int otQMC5883.temperature (   ) 
 

Return temperature sensor output is in 2’s complement.
Temperature sensor gain is factory-calibrated, but its offset has not been compensated, only relative temperature value is accurate.

Returns:
The temperature sensor, coefficient is about 100 LSB/Celsius


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0