18 #ifndef ADAFRUIT_MLX90393_H 19 #define ADAFRUIT_MLX90393_H 22 #include <Adafruit_I2CDevice.h> 23 #include <Adafruit_SPIDevice.h> 24 #include <Adafruit_Sensor.h> 26 #define MLX90393_DEFAULT_ADDR (0x0C) 28 #define MLX90393_AXIS_ALL (0x0E) 29 #define MLX90393_CONF1 (0x00) 30 #define MLX90393_CONF2 (0x01) 31 #define MLX90393_CONF3 (0x02) 32 #define MLX90393_CONF4 (0x03) 33 #define MLX90393_GAIN_SHIFT (4) 34 #define MLX90393_HALL_CONF (0x0C) 35 #define MLX90393_STATUS_OK (0x00) 36 #define MLX90393_STATUS_SMMODE (0x08) 37 #define MLX90393_STATUS_RESET (0x01) 38 #define MLX90393_STATUS_ERROR (0xFF) 39 #define MLX90393_STATUS_MASK (0xFC) 43 MLX90393_REG_SB = (0x10),
44 MLX90393_REG_SW = (0x20),
45 MLX90393_REG_SM = (0x30),
46 MLX90393_REG_RM = (0x40),
47 MLX90393_REG_RR = (0x50),
48 MLX90393_REG_WR = (0x60),
49 MLX90393_REG_EX = (0x80),
50 MLX90393_REG_HR = (0xD0),
51 MLX90393_REG_HS = (0x70),
52 MLX90393_REG_RT = (0xF0),
53 MLX90393_REG_NOP = (0x00),
57 typedef enum mlx90393_gain {
58 MLX90393_GAIN_5X = (0x00),
69 typedef enum mlx90393_resolution {
74 } mlx90393_resolution_t;
77 typedef enum mlx90393_axis {
84 typedef enum mlx90393_filter {
96 typedef enum mlx90393_oversampling {
101 } mlx90393_oversampling_t;
105 const float mlx90393_lsb_lookup[2][8][4][2] = {
110 {{0.751, 1.210}, {1.502, 2.420}, {3.004, 4.840}, {6.009, 9.680}},
112 {{0.601, 0.968}, {1.202, 1.936}, {2.403, 3.872}, {4.840, 7.744}},
114 {{0.451, 0.726}, {0.901, 1.452}, {1.803, 2.904}, {3.605, 5.808}},
116 {{0.376, 0.605}, {0.751, 1.210}, {1.502, 2.420}, {3.004, 4.840}},
118 {{0.300, 0.484}, {0.601, 0.968}, {1.202, 1.936}, {2.403, 3.872}},
120 {{0.250, 0.403}, {0.501, 0.807}, {1.001, 1.613}, {2.003, 3.227}},
122 {{0.200, 0.323}, {0.401, 0.645}, {0.801, 1.291}, {1.602, 2.581}},
124 {{0.150, 0.242}, {0.300, 0.484}, {0.601, 0.968}, {1.202, 1.936}},
130 {{0.787, 1.267}, {1.573, 2.534}, {3.146, 5.068}, {6.292, 10.137}},
132 {{0.629, 1.014}, {1.258, 2.027}, {2.517, 4.055}, {5.034, 8.109}},
134 {{0.472, 0.760}, {0.944, 1.521}, {1.888, 3.041}, {3.775, 6.082}},
136 {{0.393, 0.634}, {0.787, 1.267}, {1.573, 2.534}, {3.146, 5.068}},
138 {{0.315, 0.507}, {0.629, 1.014}, {1.258, 2.027}, {2.517, 4.055}},
140 {{0.262, 0.422}, {0.524, 0.845}, {1.049, 1.689}, {2.097, 3.379}},
142 {{0.210, 0.338}, {0.419, 0.676}, {0.839, 1.352}, {1.678, 2.703}},
144 {{0.157, 0.253}, {0.315, 0.507}, {0.629, 1.014}, {1.258, 2.027}},
149 const float mlx90393_tconv[8][4] = {
151 {1.27, 1.84, 3.00, 5.30},
153 {1.46, 2.23, 3.76, 6.84},
155 {1.84, 3.00, 5.30, 9.91},
157 {2.61, 4.53, 8.37, 16.05},
159 {4.15, 7.60, 14.52, 28.34},
161 {7.22, 13.75, 26.80, 52.92},
163 {13.36, 26.04, 51.38, 102.07},
165 {25.65, 50.61, 100.53, 200.37},
174 bool begin_I2C(uint8_t i2c_addr = MLX90393_DEFAULT_ADDR,
175 TwoWire *wire = &Wire);
176 bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI);
184 bool setGain(
enum mlx90393_gain gain);
185 enum mlx90393_gain
getGain(
void);
187 bool setResolution(
enum mlx90393_axis,
enum mlx90393_resolution resolution);
190 bool setFilter(
enum mlx90393_filter filter);
197 bool readData(
float *x,
float *y,
float *z);
199 bool getEvent(sensors_event_t *event);
203 Adafruit_I2CDevice *i2c_dev = NULL;
204 Adafruit_SPIDevice *spi_dev = NULL;
206 bool readRegister(uint8_t reg, uint16_t *data);
207 bool writeRegister(uint8_t reg, uint16_t data);
209 uint8_t transceive(uint8_t *txbuf, uint8_t txlen, uint8_t *rxbuf = NULL,
210 uint8_t rxlen = 0, uint8_t interdelay = 10);
212 enum mlx90393_gain _gain;
213 enum mlx90393_resolution _res_x, _res_y, _res_z;
214 enum mlx90393_filter _dig_filt;
215 enum mlx90393_oversampling _osr;
217 int32_t _sensorID = 90393;
enum mlx90393_oversampling getOversampling(void)
Definition: Adafruit_MLX90393.cpp:265
bool setTrigInt(bool state)
Definition: Adafruit_MLX90393.cpp:276
bool readData(float *x, float *y, float *z)
Definition: Adafruit_MLX90393.cpp:362
bool setResolution(enum mlx90393_axis, enum mlx90393_resolution resolution)
Definition: Adafruit_MLX90393.cpp:174
bool reset(void)
Definition: Adafruit_MLX90393.cpp:124
enum mlx90393_filter getFilter(void)
Definition: Adafruit_MLX90393.cpp:241
enum mlx90393_gain getGain(void)
Definition: Adafruit_MLX90393.cpp:158
bool readMeasurement(float *x, float *y, float *z)
Definition: Adafruit_MLX90393.cpp:317
enum mlx90393_resolution getResolution(enum mlx90393_axis)
Definition: Adafruit_MLX90393.cpp:207
void getSensor(sensor_t *sensor)
Gets the sensor_t device data, Adafruit Unified Sensor format.
Definition: Adafruit_MLX90393.cpp:477
bool exitMode(void)
Definition: Adafruit_MLX90393.cpp:113
Definition: Adafruit_MLX90393.h:171
bool begin_I2C(uint8_t i2c_addr=MLX90393_DEFAULT_ADDR, TwoWire *wire=&Wire)
Sets up the hardware and initializes I2C.
Definition: Adafruit_MLX90393.cpp:33
bool getEvent(sensors_event_t *event)
Gets the most recent sensor event, Adafruit Unified Sensor format.
Definition: Adafruit_MLX90393.cpp:409
bool setOversampling(enum mlx90393_oversampling oversampling)
Definition: Adafruit_MLX90393.cpp:248
bool startSingleMeasurement(void)
Definition: Adafruit_MLX90393.cpp:297
bool setFilter(enum mlx90393_filter filter)
Definition: Adafruit_MLX90393.cpp:225
bool setGain(enum mlx90393_gain gain)
Definition: Adafruit_MLX90393.cpp:139
bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI=&SPI)
Sets up the hardware and initializes hardware SPI.
Definition: Adafruit_MLX90393.cpp:56
Adafruit_MLX90393()
Definition: Adafruit_MLX90393.cpp:23