Adafruit ADXL343 Library
Adafruit_ADXL343.h
Go to the documentation of this file.
1 /**************************************************************************/
17 /**************************************************************************/
18 #ifndef _ADAFRUIT_SENSOR_ADXL343_H
19 #define _ADAFRUIT_SENSOR_ADXL343_H
20 
21 #if ARDUINO >= 100
22 #include "Arduino.h"
23 #else
24 #include "WProgram.h"
25 #endif
26 
27 #include <Adafruit_BusIO_Register.h>
28 #include <Adafruit_I2CDevice.h>
29 #include <Adafruit_SPIDevice.h>
30 #include <Adafruit_Sensor.h>
31 #include <Wire.h>
32 
33 /*=========================================================================
34  I2C ADDRESS/BITS
35  -----------------------------------------------------------------------*/
36 #define ADXL343_ADDRESS (0x53)
37 /*=========================================================================*/
38 
39 /*=========================================================================
40  REGISTERS
41  -----------------------------------------------------------------------*/
42 #define ADXL3XX_REG_DEVID (0x00)
43 #define ADXL3XX_REG_THRESH_TAP (0x1D)
44 #define ADXL3XX_REG_OFSX (0x1E)
45 #define ADXL3XX_REG_OFSY (0x1F)
46 #define ADXL3XX_REG_OFSZ (0x20)
47 #define ADXL3XX_REG_DUR (0x21)
48 #define ADXL3XX_REG_LATENT (0x22)
49 #define ADXL3XX_REG_WINDOW (0x23)
50 #define ADXL3XX_REG_THRESH_ACT (0x24)
51 #define ADXL3XX_REG_THRESH_INACT (0x25)
52 #define ADXL3XX_REG_TIME_INACT (0x26)
53 #define ADXL3XX_REG_ACT_INACT_CTL \
54  (0x27)
55 #define ADXL3XX_REG_THRESH_FF (0x28)
56 #define ADXL3XX_REG_TIME_FF (0x29)
57 #define ADXL3XX_REG_TAP_AXES (0x2A)
58 #define ADXL3XX_REG_ACT_TAP_STATUS (0x2B)
59 #define ADXL3XX_REG_BW_RATE (0x2C)
60 #define ADXL3XX_REG_POWER_CTL (0x2D)
61 #define ADXL3XX_REG_INT_ENABLE (0x2E)
62 #define ADXL3XX_REG_INT_MAP (0x2F)
63 #define ADXL3XX_REG_INT_SOURCE (0x30)
64 #define ADXL3XX_REG_DATA_FORMAT (0x31)
65 #define ADXL3XX_REG_DATAX0 (0x32)
66 #define ADXL3XX_REG_DATAX1 (0x33)
67 #define ADXL3XX_REG_DATAY0 (0x34)
68 #define ADXL3XX_REG_DATAY1 (0x35)
69 #define ADXL3XX_REG_DATAZ0 (0x36)
70 #define ADXL3XX_REG_DATAZ1 (0x37)
71 #define ADXL3XX_REG_FIFO_CTL (0x38)
72 #define ADXL3XX_REG_FIFO_STATUS (0x39)
73 /*=========================================================================*/
74 
75 /*=========================================================================
76  REGISTERS
77  -----------------------------------------------------------------------*/
78 #define ADXL343_MG2G_MULTIPLIER (0.004)
79 /*=========================================================================*/
80 
82 typedef enum {
117 
119 typedef enum {
130 
132 union int_config {
133  uint8_t value;
134  struct {
135  uint8_t overrun : 1;
136  uint8_t watermark : 1;
137  uint8_t freefall : 1;
138  uint8_t inactivity : 1;
139  uint8_t activity : 1;
140  uint8_t double_tap : 1;
141  uint8_t single_tap : 1;
142  uint8_t data_ready : 1;
143  } bits;
144 };
145 
147 typedef enum {
148  ADXL343_INT1 = 0,
149  ADXL343_INT2 = 1,
150  ADXL3XX_INT1 = 0,
151  ADXL3XX_INT2 = 1,
153 
157 class Adafruit_ADXL343 : public Adafruit_Sensor {
158 public:
159  Adafruit_ADXL343(int32_t sensorID);
160  Adafruit_ADXL343(int32_t sensorID, TwoWire *wireBus);
161  Adafruit_ADXL343(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t cs,
162  int32_t sensorID = -1);
163  Adafruit_ADXL343(uint8_t cs, SPIClass *theSPI, int32_t sensorID = -1);
164 
165  bool begin(uint8_t i2caddr = ADXL343_ADDRESS);
166  void setRange(adxl34x_range_t range);
167  adxl34x_range_t getRange(void);
168  void setDataRate(adxl3xx_dataRate_t dataRate);
169  adxl3xx_dataRate_t getDataRate(void);
170  bool getEvent(sensors_event_t *);
171  void getSensor(sensor_t *);
172 
173  uint8_t getDeviceID(void);
174  void writeRegister(uint8_t reg, uint8_t value);
175  uint8_t readRegister(uint8_t reg);
176  int16_t read16(uint8_t reg);
177 
178  bool enableInterrupts(int_config cfg);
179  bool mapInterrupts(int_config cfg);
180  uint8_t checkInterrupts(void);
181 
182  void getTrimOffsets(int8_t *x, int8_t *y, int8_t *z);
183  void setTrimOffsets(int8_t x, int8_t y, int8_t z);
184 
185  int16_t getX(void);
186  int16_t getY(void);
187  int16_t getZ(void);
188  bool getXYZ(int16_t &x, int16_t &y, int16_t &z);
189 
190 protected:
191  Adafruit_SPIDevice *spi_dev = NULL;
192  Adafruit_I2CDevice *i2c_dev = NULL;
193 
194  TwoWire *_wire = NULL;
195  SPIClass *_spi = NULL;
196  int32_t _sensorID;
198  uint8_t _clk,
199  _do,
200  _di,
201  _cs;
202 };
203 
204 #endif
uint8_t value
Definition: Adafruit_ADXL343.h:133
uint8_t single_tap
Definition: Adafruit_ADXL343.h:141
Definition: Adafruit_ADXL343.h:126
Definition: Adafruit_ADXL343.h:132
uint8_t inactivity
Definition: Adafruit_ADXL343.h:138
Definition: Adafruit_ADXL343.h:107
Definition: Adafruit_ADXL343.h:110
Definition: Adafruit_ADXL343.h:90
#define ADXL343_ADDRESS
Definition: Adafruit_ADXL343.h:36
Definition: Adafruit_ADXL343.h:93
uint8_t data_ready
Definition: Adafruit_ADXL343.h:142
adxl34x_range_t _range
cache of range
Definition: Adafruit_ADXL343.h:197
Definition: Adafruit_ADXL343.h:128
Definition: Adafruit_ADXL343.h:106
Definition: Adafruit_ADXL343.h:112
uint8_t freefall
Definition: Adafruit_ADXL343.h:137
adxl34x_range_t
Definition: Adafruit_ADXL343.h:119
Definition: Adafruit_ADXL343.h:123
Definition: Adafruit_ADXL343.h:125
Definition: Adafruit_ADXL343.h:115
Definition: Adafruit_ADXL343.h:94
uint8_t watermark
Definition: Adafruit_ADXL343.h:136
uint8_t double_tap
Definition: Adafruit_ADXL343.h:140
Definition: Adafruit_ADXL343.h:97
Definition: Adafruit_ADXL343.h:109
Definition: Adafruit_ADXL343.h:114
Definition: Adafruit_ADXL343.h:88
Definition: Adafruit_ADXL343.h:102
struct int_config::@0 bits
Definition: Adafruit_ADXL343.h:85
adxl3xx_dataRate_t
Definition: Adafruit_ADXL343.h:82
Definition: Adafruit_ADXL343.h:83
Definition: Adafruit_ADXL343.h:103
Definition: Adafruit_ADXL343.h:113
Definition: Adafruit_ADXL343.h:86
adxl3xx_int_pin
Definition: Adafruit_ADXL343.h:147
uint8_t _do
SPI software data out.
Definition: Adafruit_ADXL343.h:198
Definition: Adafruit_ADXL343.h:111
Definition: Adafruit_ADXL343.h:87
Definition: Adafruit_ADXL343.h:98
Definition: Adafruit_ADXL343.h:104
Definition: Adafruit_ADXL343.h:95
uint8_t activity
Definition: Adafruit_ADXL343.h:139
Definition: Adafruit_ADXL343.h:157
uint8_t overrun
Definition: Adafruit_ADXL343.h:135
Definition: Adafruit_ADXL343.h:120
Definition: Adafruit_ADXL343.h:89
Definition: Adafruit_ADXL343.h:105
Definition: Adafruit_ADXL343.h:96
Definition: Adafruit_ADXL343.h:84
Definition: Adafruit_ADXL343.h:121
Definition: Adafruit_ADXL343.h:100
Definition: Adafruit_ADXL343.h:92
Definition: Adafruit_ADXL343.h:122
Definition: Adafruit_ADXL343.h:101
Definition: Adafruit_ADXL343.h:108
int32_t _sensorID
User-set sensor identifier.
Definition: Adafruit_ADXL343.h:196
Definition: Adafruit_ADXL343.h:91
Definition: Adafruit_ADXL343.h:127