Adafruit LIS3MDL Arduino Library
Public Member Functions | Public Attributes | List of all members
Adafruit_LIS3MDL Class Reference

#include <Adafruit_LIS3MDL.h>

Inheritance diagram for Adafruit_LIS3MDL:

Public Member Functions

 Adafruit_LIS3MDL (void)
 Instantiates a new LIS3MDL class.
 
bool begin_I2C (uint8_t i2c_addr=LIS3MDL_I2CADDR_DEFAULT, TwoWire *wire=&Wire)
 Sets up the hardware and initializes I2C. More...
 
bool begin_SPI (uint8_t cs_pin, SPIClass *theSPI=&SPI, uint32_t frequency=1000000)
 Sets up the hardware and initializes hardware SPI. More...
 
bool begin_SPI (int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, int8_t mosi_pin, uint32_t frequency=1000000)
 Sets up the hardware and initializes software SPI. More...
 
void reset (void)
 Performs a software reset.
 
void setPerformanceMode (lis3mdl_performancemode_t mode)
 Set the performance mode, LIS3MDL_LOWPOWERMODE, LIS3MDL_MEDIUMMODE, LIS3MDL_HIGHMODE or LIS3MDL_ULTRAHIGHMODE. More...
 
lis3mdl_performancemode_t getPerformanceMode (void)
 Get the performance mode. More...
 
void setOperationMode (lis3mdl_operationmode_t mode)
 Set the operation mode, LIS3MDL_CONTINUOUSMODE, LIS3MDL_SINGLEMODE or LIS3MDL_POWERDOWNMODE. More...
 
lis3mdl_operationmode_t getOperationMode (void)
 Get the operation mode. More...
 
void setDataRate (lis3mdl_dataRate_t dataRate)
 Sets the data rate for the LIS3MDL (controls power consumption) from 0.625 Hz to 80Hz. More...
 
lis3mdl_dataRate_t getDataRate (void)
 Gets the data rate for the LIS3MDL (controls power consumption) More...
 
void setRange (lis3mdl_range_t range)
 Set the resolution range: +-4 gauss, 8 gauss, 12 gauss, or 16 gauss. More...
 
lis3mdl_range_t getRange (void)
 Read the resolution range: +-4 gauss, 8 gauss, 12 gauss, or 16 gauss. More...
 
void setIntThreshold (uint16_t value)
 Set the interrupt threshold value. More...
 
uint16_t getIntThreshold (void)
 Get the interrupt threshold value. More...
 
void configInterrupt (bool enableX, bool enableY, bool enableZ, bool polarity, bool latch, bool enableInt)
 Configure INT_CFG. More...
 
void selfTest (bool flag)
 Enable or disable self-test. More...
 
void read ()
 Read the XYZ data from the magnetometer and store in the internal x, y and z (and x_g, y_g, z_g) member variables.
 
bool getEvent (sensors_event_t *event)
 Gets the most recent sensor event, Adafruit Unified Sensor format. More...
 
void getSensor (sensor_t *sensor)
 Gets the sensor_t device data, Adafruit Unified Sensor format. More...
 
int readMagneticField (float &x, float &y, float &z)
 Read magnetic data. More...
 
float magneticFieldSampleRate (void)
 Get the magnetic data rate. More...
 
int magneticFieldAvailable (void)
 Check for available data from magnetic. More...
 

Public Attributes

int16_t x
 The last read X mag in raw units.
 
int16_t y
 The last read Y mag in raw units.
 
int16_t z
 The last read Z mag in raw units.
 
float x_gauss
 The last read X mag in 'gauss'.
 
float y_gauss
 The last read Y mag in 'gauss'.
 
float z_gauss
 The last read Z mag in 'gauss'.
 
lis3mdl_range_t rangeBuffered = LIS3MDL_RANGE_4_GAUSS
 buffer for the magnetometer range
 

Detailed Description

Class for hardware interfacing with an LIS3MDL magnetometer

Member Function Documentation

◆ begin_I2C()

bool Adafruit_LIS3MDL::begin_I2C ( uint8_t  i2c_address = LIS3MDL_I2CADDR_DEFAULT,
TwoWire *  wire = &Wire 
)

Sets up the hardware and initializes I2C.

Parameters
i2c_addressThe I2C address to be used.
wireThe Wire object to be used for I2C connections.
Returns
True if initialization was successful, otherwise false.

◆ begin_SPI() [1/2]

boolean Adafruit_LIS3MDL::begin_SPI ( uint8_t  cs_pin,
SPIClass *  theSPI = &SPI,
uint32_t  frequency = 1000000 
)

Sets up the hardware and initializes hardware SPI.

Parameters
cs_pinThe arduino pin # connected to chip select
theSPIThe SPI object to be used for SPI connections.
frequencyThe SPI bus frequency
Returns
True if initialization was successful, otherwise false.

◆ begin_SPI() [2/2]

bool Adafruit_LIS3MDL::begin_SPI ( int8_t  cs_pin,
int8_t  sck_pin,
int8_t  miso_pin,
int8_t  mosi_pin,
uint32_t  frequency = 1000000 
)

Sets up the hardware and initializes software SPI.

Parameters
cs_pinThe arduino pin # connected to chip select
sck_pinThe arduino pin # connected to SPI clock
miso_pinThe arduino pin # connected to SPI MISO
mosi_pinThe arduino pin # connected to SPI MOSI
frequencyThe SPI bus frequency
Returns
True if initialization was successful, otherwise false.

◆ setPerformanceMode()

void Adafruit_LIS3MDL::setPerformanceMode ( lis3mdl_performancemode_t  mode)

Set the performance mode, LIS3MDL_LOWPOWERMODE, LIS3MDL_MEDIUMMODE, LIS3MDL_HIGHMODE or LIS3MDL_ULTRAHIGHMODE.

Parameters
modeEnumerated lis3mdl_performancemode_t

◆ getPerformanceMode()

lis3mdl_performancemode_t Adafruit_LIS3MDL::getPerformanceMode ( void  )

Get the performance mode.

Returns
Enumerated lis3mdl_performancemode_t, LIS3MDL_LOWPOWERMODE, LIS3MDL_MEDIUMMODE, LIS3MDL_HIGHMODE or LIS3MDL_ULTRAHIGHMODE

◆ setOperationMode()

void Adafruit_LIS3MDL::setOperationMode ( lis3mdl_operationmode_t  mode)

Set the operation mode, LIS3MDL_CONTINUOUSMODE, LIS3MDL_SINGLEMODE or LIS3MDL_POWERDOWNMODE.

Parameters
modeEnumerated lis3mdl_operationmode_t

◆ getOperationMode()

lis3mdl_operationmode_t Adafruit_LIS3MDL::getOperationMode ( void  )

Get the operation mode.

Returns
Enumerated lis3mdl_operationmode_t, LIS3MDL_CONTINUOUSMODE, LIS3MDL_SINGLEMODE or LIS3MDL_POWERDOWNMODE

◆ setDataRate()

void Adafruit_LIS3MDL::setDataRate ( lis3mdl_dataRate_t  dataRate)

Sets the data rate for the LIS3MDL (controls power consumption) from 0.625 Hz to 80Hz.

Parameters
dataRateEnumerated lis3mdl_dataRate_t

◆ getDataRate()

lis3mdl_dataRate_t Adafruit_LIS3MDL::getDataRate ( void  )

Gets the data rate for the LIS3MDL (controls power consumption)

Returns
Enumerated lis3mdl_dataRate_t from 0.625 Hz to 80Hz

◆ setRange()

void Adafruit_LIS3MDL::setRange ( lis3mdl_range_t  range)

Set the resolution range: +-4 gauss, 8 gauss, 12 gauss, or 16 gauss.

Parameters
rangeEnumerated lis3mdl_range_t

◆ getRange()

lis3mdl_range_t Adafruit_LIS3MDL::getRange ( void  )

Read the resolution range: +-4 gauss, 8 gauss, 12 gauss, or 16 gauss.

Returns
Enumerated lis3mdl_range_t

◆ setIntThreshold()

void Adafruit_LIS3MDL::setIntThreshold ( uint16_t  value)

Set the interrupt threshold value.

Parameters
value16-bit unsigned raw value

◆ getIntThreshold()

uint16_t Adafruit_LIS3MDL::getIntThreshold ( void  )

Get the interrupt threshold value.

Returns
16-bit unsigned raw value

◆ configInterrupt()

void Adafruit_LIS3MDL::configInterrupt ( bool  enableX,
bool  enableY,
bool  enableZ,
bool  polarity,
bool  latch,
bool  enableInt 
)

Configure INT_CFG.

Parameters
enableXEnable interrupt generation on X-axis
enableYEnable interrupt generation on Y-axis
enableZEnable interrupt generation on Z-axis
polaritySets the polarity of the INT output logic
latchIf true (latched) the INT pin remains in the same state until INT_SRC is read.
enableIntInterrupt enable on INT pin

◆ selfTest()

void Adafruit_LIS3MDL::selfTest ( bool  flag)

Enable or disable self-test.

Parameters
flagIf true, enable self-test

◆ getEvent()

bool Adafruit_LIS3MDL::getEvent ( sensors_event_t *  event)

Gets the most recent sensor event, Adafruit Unified Sensor format.

Parameters
eventPointer to an Adafruit Unified sensor_event_t object that we'll fill in
Returns
True on successful read

◆ getSensor()

void Adafruit_LIS3MDL::getSensor ( sensor_t *  sensor)

Gets the sensor_t device data, Adafruit Unified Sensor format.

Parameters
sensorPointer to an Adafruit Unified sensor_t object that we'll fill in

◆ readMagneticField()

int Adafruit_LIS3MDL::readMagneticField ( float &  x,
float &  y,
float &  z 
)

Read magnetic data.

Parameters
xreference to x axis
yreference to y axis
zreference to z axis
Returns
1 if success, 0 if not

◆ magneticFieldSampleRate()

float Adafruit_LIS3MDL::magneticFieldSampleRate ( void  )

Get the magnetic data rate.

Returns
The data rate in float

◆ magneticFieldAvailable()

int Adafruit_LIS3MDL::magneticFieldAvailable ( void  )

Check for available data from magnetic.

Returns
1 if available, 0 if not

The documentation for this class was generated from the following files: