Adafruit FXOS8700 Accelerometer Magnetometer Library
Adafruit_FXOS8700.h
Go to the documentation of this file.
1 
21 #ifndef __FXOS8700_H__
22 #define __FXOS8700_H__
23 
24 #include <Adafruit_BusIO_Register.h>
25 #include <Adafruit_I2CDevice.h>
26 #include <Adafruit_Sensor.h>
27 #include <Arduino.h>
28 
29 /*=========================================================================
30  I2C ADDRESS/BITS AND SETTINGS
31  -----------------------------------------------------------------------*/
33 // #define FXOS8700_ADDRESS (0x1F) // 0011111
35 #define FXOS8700_ID (0xC7) // 1100 0111
36 /*=========================================================================*/
37 
38 /*=========================================================================
39  REGISTERS
40  -----------------------------------------------------------------------*/
44 typedef enum {
54  0x0D,
57  0x2A,
59  0x2B,
61  0x2C,
63  0x2D,
65  0x2E,
74  0x5B,
76  0x5C,
78  0x5D,
80 /*=========================================================================*/
81 
82 /*=========================================================================
83  OPTIONAL SENSOR MODE SETTINGS
84  -----------------------------------------------------------------------*/
89 typedef enum {
90  STANDBY = 0x00,
91  WAKE = 0x01,
92  SLEEP = 0x02
94 
100 typedef enum {
102  MAG_ONLY_MODE = 0b01,
103  HYBRID_MODE = 0b11
105 /*=========================================================================*/
106 
107 /*=========================================================================
108  OPTIONAL SPEED SETTINGS
109  -----------------------------------------------------------------------*/
114 typedef enum {
126 } fxos8700ODR_t;
127 
133  ODR_800HZ,
134  ODR_400HZ,
135  ODR_200HZ,
136  ODR_100HZ,
137  ODR_50HZ,
138  ODR_12_5HZ,
139  ODR_6_25HZ,
140  ODR_1_5625HZ,
141 };
142 
148  ODR_400HZ,
149  ODR_200HZ,
150  ODR_100HZ,
151  ODR_50HZ,
152  ODR_25HZ,
153  ODR_6_25HZ,
154  ODR_3_125HZ,
155  ODR_0_7813HZ,
156 };
157 
163 const uint16_t ODR_drBits[] = {
164  0x00,
165  0x08,
166  0x10,
167  0x18,
168  0x20,
169  0x28,
170  0x30,
171  0x38,
172 };
173 /*=========================================================================*/
174 
175 /*=========================================================================
176  OPTIONAL RANGE SETTINGS
177  -----------------------------------------------------------------------*/
181 typedef enum {
182  ACCEL_RANGE_2G = 0x00,
183  ACCEL_RANGE_4G = 0x01,
186 /*=========================================================================*/
187 
188 /*=========================================================================
189  OPTIONAL MAGNETOMETER OVERSAMPLING SETTINGS
190  -----------------------------------------------------------------------*/
194 typedef enum {
204 /*=========================================================================*/
205 
206 /*=========================================================================
207  RAW 3DOF SENSOR DATA TYPE
208  -----------------------------------------------------------------------*/
212 typedef struct {
213  int16_t x;
214  int16_t y;
215  int16_t z;
217 /*=========================================================================*/
218 
219 class Adafruit_FXOS8700;
220 
222 class Adafruit_FXOS8700_Accelerometer : public Adafruit_Sensor {
223 public:
228  _theFXOS8700 = parent;
229  }
230  bool getEvent(sensors_event_t *);
231  void getSensor(sensor_t *);
232 
233 private:
234  int _sensorID = 8701;
235  Adafruit_FXOS8700 *_theFXOS8700 = NULL;
236 };
237 
239 class Adafruit_FXOS8700_Magnetometer : public Adafruit_Sensor {
240 public:
245  _theFXOS8700 = parent;
246  }
247  bool getEvent(sensors_event_t *);
248  void getSensor(sensor_t *);
249 
250 private:
251  int _sensorID = 8702;
252  Adafruit_FXOS8700 *_theFXOS8700 = NULL;
253 };
254 
255 /**************************************************************************/
259 /**************************************************************************/
260 class Adafruit_FXOS8700 : public Adafruit_Sensor {
261 public:
262  Adafruit_FXOS8700(int32_t accelSensorID = -1, int32_t magSensorID = -1);
264  bool begin(uint8_t addr = 0x1F, TwoWire *wire = &Wire);
265 
266  bool getEvent(sensors_event_t *accel);
267  void getSensor(sensor_t *singleSensorEvent);
268  bool getEvent(sensors_event_t *accel, sensors_event_t *mag);
269  void getSensor(sensor_t *accel, sensor_t *mag);
270  void standby(boolean standby);
271 
276 
277  Adafruit_Sensor *getMagnetometerSensor(void);
278  Adafruit_Sensor *getAccelerometerSensor(void);
279 
281  NULL;
282  Adafruit_FXOS8700_Magnetometer *mag_sensor = NULL;
283 
284  void setSensorMode(fxos8700SensorMode_t mode);
285  fxos8700SensorMode_t getSensorMode();
286 
287  void setAccelRange(fxos8700AccelRange_t range);
288  fxos8700AccelRange_t getAccelRange();
289 
290  void setOutputDataRate(fxos8700ODR_t rate);
291  fxos8700ODR_t getOutputDataRate();
292 
293  void setMagOversamplingRatio(fxos8700MagOSR_t ratio);
294  fxos8700MagOSR_t getMagOversamplingRatio();
295 
296 protected:
297  Adafruit_I2CDevice *i2c_dev = NULL;
298 
299 private:
300  bool initialize();
303  fxos8700ODR_t _rate = ODR_100HZ;
304  fxos8700MagOSR_t _ratio = MAG_OSR_7;
305  int32_t _accelSensorID;
306  int32_t _magSensorID;
307 };
308 
309 #endif
Definition: Adafruit_FXOS8700.h:198
Adafruit_FXOS8700_Magnetometer(Adafruit_FXOS8700 *parent)
Create an Adafruit_Sensor compatible object for the magnetometer sensor.
Definition: Adafruit_FXOS8700.h:244
fxos8700SensorMode_t
Definition: Adafruit_FXOS8700.h:100
Definition: Adafruit_FXOS8700.h:183
Definition: Adafruit_FXOS8700.h:60
Definition: Adafruit_FXOS8700.h:56
Definition: Adafruit_FXOS8700.h:92
int16_t x
Definition: Adafruit_FXOS8700.h:213
Definition: Adafruit_FXOS8700.h:52
Definition: Adafruit_FXOS8700.h:118
void getSensor(sensor_t *)
Gets the sensor_t data for the FXOS8700&#39;s accelerometer.
Definition: Adafruit_FXOS8700.cpp:598
fxos8700Registers_t
Definition: Adafruit_FXOS8700.h:44
Definition: Adafruit_FXOS8700.h:64
const fxos8700ODR_t ACCEL_MAG_ONLY_AVAILABLE_ODRs[]
Definition: Adafruit_FXOS8700.h:132
const uint16_t ODR_drBits[]
Definition: Adafruit_FXOS8700.h:163
Definition: Adafruit_FXOS8700.h:123
Definition: Adafruit_FXOS8700.h:103
Definition: Adafruit_FXOS8700.h:101
Definition: Adafruit_FXOS8700.h:195
Definition: Adafruit_FXOS8700.h:77
Definition: Adafruit_FXOS8700.h:200
Definition: Adafruit_FXOS8700.h:124
Definition: Adafruit_FXOS8700.h:45
Definition: Adafruit_FXOS8700.h:75
Definition: Adafruit_FXOS8700.h:184
fxos8700RawData_t mag_raw
Definition: Adafruit_FXOS8700.h:275
Definition: Adafruit_FXOS8700.h:202
Definition: Adafruit_FXOS8700.h:48
Raw (integer) values from a 3dof sensor.
Definition: Adafruit_FXOS8700.h:212
Definition: Adafruit_FXOS8700.h:69
int16_t z
Definition: Adafruit_FXOS8700.h:215
Definition: Adafruit_FXOS8700.h:222
Definition: Adafruit_FXOS8700.h:117
Definition: Adafruit_FXOS8700.h:182
Definition: Adafruit_FXOS8700.h:125
Definition: Adafruit_FXOS8700.h:119
Definition: Adafruit_FXOS8700.h:51
Definition: Adafruit_FXOS8700.h:121
Definition: Adafruit_FXOS8700.h:47
fxos8700SystemStatus_t
Definition: Adafruit_FXOS8700.h:89
Definition: Adafruit_FXOS8700.h:50
Definition: Adafruit_FXOS8700.h:115
Definition: Adafruit_FXOS8700.h:122
Definition: Adafruit_FXOS8700.h:120
const fxos8700ODR_t HYBRID_AVAILABLE_ODRs[]
Definition: Adafruit_FXOS8700.h:147
Definition: Adafruit_FXOS8700.h:62
int16_t y
Definition: Adafruit_FXOS8700.h:214
Definition: Adafruit_FXOS8700.h:72
Definition: Adafruit_FXOS8700.h:73
Unified sensor driver for the Adafruit FXOS8700 breakout.
Definition: Adafruit_FXOS8700.h:260
Definition: Adafruit_FXOS8700.h:201
Definition: Adafruit_FXOS8700.h:102
Definition: Adafruit_FXOS8700.h:58
Adafruit_FXOS8700_Accelerometer(Adafruit_FXOS8700 *parent)
Create an Adafruit_Sensor compatible object for the accelerometer sensor.
Definition: Adafruit_FXOS8700.h:227
Definition: Adafruit_FXOS8700.h:91
Definition: Adafruit_FXOS8700.h:46
fxos8700RawData_t accel_raw
Definition: Adafruit_FXOS8700.h:273
Definition: Adafruit_FXOS8700.h:239
fxos8700ODR_t
Definition: Adafruit_FXOS8700.h:114
Definition: Adafruit_FXOS8700.h:196
Definition: Adafruit_FXOS8700.h:199
Definition: Adafruit_FXOS8700.h:116
Definition: Adafruit_FXOS8700.h:70
Definition: Adafruit_FXOS8700.h:197
Definition: Adafruit_FXOS8700.h:53
fxos8700MagOSR_t
Definition: Adafruit_FXOS8700.h:194
Definition: Adafruit_FXOS8700.h:55
Definition: Adafruit_FXOS8700.h:67
Definition: Adafruit_FXOS8700.h:90
Definition: Adafruit_FXOS8700.h:71
Definition: Adafruit_FXOS8700.h:66
fxos8700AccelRange_t
Definition: Adafruit_FXOS8700.h:181
Definition: Adafruit_FXOS8700.h:49
bool getEvent(sensors_event_t *)
Gets the accelerometer as a standard sensor event.
Definition: Adafruit_FXOS8700.cpp:621
Definition: Adafruit_FXOS8700.h:68