Adafruit LIS2MDL Magnetometer Library
Adafruit_LIS2MDL.h
Go to the documentation of this file.
1 
19 #ifndef LIS2MDL_MAG_H
20 #define LIS2MDL_MAG_H
21 
22 #include <Adafruit_BusIO_Register.h>
23 
24 #include <Adafruit_I2CDevice.h>
25 #include <Adafruit_SPIDevice.h>
26 #include <Adafruit_Sensor.h>
27 #include <Wire.h>
28 
29 /*=========================================================================
30  I2C ADDRESS/BITS
31  -----------------------------------------------------------------------*/
32 #define _ADDRESS_MAG 0x1E
33 #define _CHIP_ID 0x40
34 #define LIS2MDL_MAG_LSB 1.5
35 #define LIS2MDL_MILLIGAUSS_TO_MICROTESLA \
36  0.1
37 /*=========================================================================*/
38 
42 typedef enum {
43  LIS2MDL_OFFSET_X_REG_L = 0x45,
44  LIS2MDL_OFFSET_X_REG_H = 0x46,
45  LIS2MDL_OFFSET_Y_REG_L = 0x47,
46  LIS2MDL_OFFSET_Y_REG_H = 0x48,
47  LIS2MDL_OFFSET_Z_REG_L = 0x49,
48  LIS2MDL_OFFSET_Z_REG_H = 0x4A,
49  LIS2MDL_WHO_AM_I = 0x4F,
50  LIS2MDL_CFG_REG_A = 0x60,
51  LIS2MDL_CFG_REG_B = 0x61,
52  LIS2MDL_CFG_REG_C = 0x62,
53  LIS2MDL_INT_CRTL_REG = 0x63,
54  LIS2MDL_INT_SOURCE_REG = 0x64,
55  LIS2MDL_INT_THS_L_REG = 0x65,
56  LIS2MDL_STATUS_REG = 0x67,
57  LIS2MDL_OUTX_L_REG = 0x68,
58  LIS2MDL_OUTX_H_REG = 0x69,
59  LIS2MDL_OUTY_L_REG = 0x6A,
60  LIS2MDL_OUTY_H_REG = 0x6B,
61  LIS2MDL_OUTZ_L_REG = 0x6C,
62  LIS2MDL_OUTZ_H_REG = 0x6D,
64 /*=========================================================================*/
65 
69 typedef enum {
75 /*=========================================================================*/
76 
77 /**************************************************************************/
81 /**************************************************************************/
82 typedef struct lis2mdl_data {
83  int16_t x;
84  int16_t y;
85  int16_t z;
87 /*=========================================================================*/
88 
89 /**************************************************************************/
93 /**************************************************************************/
94 class Adafruit_LIS2MDL : public Adafruit_Sensor {
95 public:
96  Adafruit_LIS2MDL(int32_t sensorID = -1);
97 
98  bool begin(uint8_t i2c_addr = _ADDRESS_MAG, TwoWire *wire = &Wire);
99  bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI);
100  bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin,
101  int8_t mosi_pin);
102 
103  lis2mdl_rate_t getDataRate();
104  void setDataRate(lis2mdl_rate_t rate);
105  bool getEvent(sensors_event_t *);
106  void getSensor(sensor_t *);
107  void reset(void);
108 
109  void enableInterrupts(bool);
110  void interruptsActiveHigh(bool);
112 
113 private:
114  bool _init(void);
115 
116  int32_t _sensorID;
117  Adafruit_BusIO_Register *config_a;
118 
119  void read(void);
120 
121  Adafruit_I2CDevice *i2c_dev = NULL;
122  Adafruit_SPIDevice *spi_dev = NULL;
123 };
124 
125 #endif
10 Hz
Definition: Adafruit_LIS2MDL.h:70
lis2mdl_register_t
LIS2MDL I2C register address bits.
Definition: Adafruit_LIS2MDL.h:42
lis2mdl_data_t raw
struct instance to hold raw data
Definition: Adafruit_LIS2MDL.h:111
a data thing
Definition: Adafruit_LIS2MDL.h:82
int16_t y
y-axis raw data
Definition: Adafruit_LIS2MDL.h:84
int16_t z
z-axis raw data
Definition: Adafruit_LIS2MDL.h:85
struct lis2mdl_data lis2mdl_data_t
a data thing
int16_t x
x-axis raw data
Definition: Adafruit_LIS2MDL.h:83
100 Hz
Definition: Adafruit_LIS2MDL.h:73
Unified sensor driver for the magnetometer.
Definition: Adafruit_LIS2MDL.h:94
50 Hz
Definition: Adafruit_LIS2MDL.h:72
lis2mdl_rate_t
Magnetometer update rate settings.
Definition: Adafruit_LIS2MDL.h:69
20 Hz
Definition: Adafruit_LIS2MDL.h:71
#define _ADDRESS_MAG
Default address.
Definition: Adafruit_LIS2MDL.h:32