Adafruit MSA301 Sensor Library
Adafruit_MSA301.h
Go to the documentation of this file.
1 
5 #ifndef ADAFRUIT_MSA301_H
6 #define ADAFRUIT_MSA301_H
7 
8 #include <Adafruit_BusIO_Register.h>
9 #include <Adafruit_I2CDevice.h>
10 #include <Adafruit_Sensor.h>
11 #include <Wire.h>
12 
13 /*=========================================================================
14 I2C ADDRESS/BITS
15 -----------------------------------------------------------------------*/
16 #define MSA301_I2CADDR_DEFAULT (0x26)
17 /*=========================================================================*/
18 
19 #define MSA301_REG_PARTID 0x01
20 #define MSA301_REG_OUT_X_L 0x02
21 #define MSA301_REG_OUT_X_H 0x03
22 #define MSA301_REG_OUT_Y_L 0x04
23 #define MSA301_REG_OUT_Y_H 0x05
24 #define MSA301_REG_OUT_Z_L 0x06
25 #define MSA301_REG_OUT_Z_H 0x07
26 #define MSA301_REG_MOTIONINT 0x09
27 #define MSA301_REG_DATAINT 0x0A
28 #define MSA301_REG_CLICKSTATUS \
29  0x0B
30 #define MSA301_REG_RESRANGE 0x0F
31 #define MSA301_REG_ODR 0x10
32 #define MSA301_REG_POWERMODE 0x11
33 #define MSA301_REG_INTSET0 0x16
34 #define MSA301_REG_INTSET1 0x17
35 #define MSA301_REG_INTMAP0 0x19
36 #define MSA301_REG_INTMAP1 0x1A
37 #define MSA301_REG_TAPDUR 0x2A
38 #define MSA301_REG_TAPTH 0x2B
39 
40 
41 typedef enum {
47 
49 typedef enum {
50  MSA301_AXIS_X = 0x0,
51  MSA301_AXIS_Y = 0x1,
52  MSA301_AXIS_Z = 0x2,
54 
56 typedef enum {
69 
71 typedef enum {
82 
84 typedef enum {
89 
91 typedef enum {
97 
99 typedef enum {
109 
111 typedef enum {
112  MSA301_INT_ORIENT = 0b100000,
118 
120 class Adafruit_MSA301 : public Adafruit_Sensor {
121 public:
122  Adafruit_MSA301(void);
123  bool begin(uint8_t i2c_addr = MSA301_I2CADDR_DEFAULT, TwoWire *wire = &Wire);
124 
125  void setDataRate(msa301_dataRate_t dataRate);
127  void enableAxes(bool x, bool y, bool z);
128 
129  void setPowerMode(msa301_powermode_t mode);
131  void setBandwidth(msa301_bandwidth_t bandwidth);
133  void setRange(msa301_range_t range);
134  msa301_range_t getRange(void);
135  void setResolution(msa301_resolution_t resolution);
137 
138  void read();
139  bool getEvent(sensors_event_t *event);
140  void getSensor(sensor_t *sensor);
141 
142  void enableInterrupts(bool singletap = false, bool doubletap = false,
143  bool activeX = false, bool activeY = false,
144  bool activeZ = false, bool newData = false,
145  bool freefall = false, bool orient = false);
146  void mapInterruptPin(bool singletap = false, bool doubletap = false,
147  bool activity = false, bool newData = false,
148  bool freefall = false, bool orient = false);
149 
150  uint8_t getClick(void);
151  uint8_t getMotionInterruptStatus(void);
152  uint8_t getDataInterruptStatus(void);
153 
154  void setClick(bool tap_quiet, bool tap_shock,
155  msa301_tapduration_t tapduration, uint8_t tapthresh);
156 
157  /*
158 
159  uint8_t getOrientation(void);
160 
161  */
162 
163  int16_t x,
164  y,
165  z;
166  float x_g,
167  y_g,
168  z_g;
169 
170 private:
171  Adafruit_I2CDevice *i2c_dev;
172 
173  int32_t _sensorID;
174 };
175 
176 #endif
msa301_powermode_t getPowerMode(void)
Get the power mode.
Definition: Adafruit_MSA301.cpp:169
msa301_powermode_t
Definition: Adafruit_MSA301.h:84
3.9 Hz
Definition: Adafruit_MSA301.h:59
uint8_t getClick(void)
Gets the most recent click detect status register value.
Definition: Adafruit_MSA301.cpp:343
float z_g
The last read X acceleration in &#39;g&#39;.
Definition: Adafruit_MSA301.h:166
150 millis
Definition: Adafruit_MSA301.h:102
New data interrupt.
Definition: Adafruit_MSA301.h:116
500 Hz
Definition: Adafruit_MSA301.h:66
int16_t x
The last read X acceleration in raw units.
Definition: Adafruit_MSA301.h:163
125 Hz
Definition: Adafruit_MSA301.h:64
Single tap interrupt.
Definition: Adafruit_MSA301.h:113
1000 Hz
Definition: Adafruit_MSA301.h:67
void enableInterrupts(bool singletap=false, bool doubletap=false, bool activeX=false, bool activeY=false, bool activeZ=false, bool newData=false, bool freefall=false, bool orient=false)
Set which interrupts are enabled.
Definition: Adafruit_MSA301.cpp:363
Adafruit_MSA301(void)
Instantiates a new MSA301 class.
Definition: Adafruit_MSA301.cpp:39
void read()
Read the XYZ data from the accelerometer and store in the internal x, y and z (and x_g...
Definition: Adafruit_MSA301.cpp:268
15.63 Hz
Definition: Adafruit_MSA301.h:75
100 millis
Definition: Adafruit_MSA301.h:101
bool getEvent(sensors_event_t *event)
Gets the most recent sensor event, Adafruit Unified Sensor format.
Definition: Adafruit_MSA301.cpp:453
1 Hz
Definition: Adafruit_MSA301.h:57
31.25 Hz
Definition: Adafruit_MSA301.h:62
msa301_dataRate_t getDataRate(void)
Gets the data rate for the MSA301 (controls power consumption)
Definition: Adafruit_MSA301.cpp:118
62.5 Hz
Definition: Adafruit_MSA301.h:63
375 millis
Definition: Adafruit_MSA301.h:105
void setRange(msa301_range_t range)
Set the resolution range: +-2g, 4g, 8g, or 16g.
Definition: Adafruit_MSA301.cpp:211
+/- 8g
Definition: Adafruit_MSA301.h:44
msa301_tapduration_t
Definition: Adafruit_MSA301.h:99
12-bit resolution
Definition: Adafruit_MSA301.h:93
8-bit resolution
Definition: Adafruit_MSA301.h:95
msa301_bandwidth_t
Definition: Adafruit_MSA301.h:71
void getSensor(sensor_t *sensor)
Gets the sensor_t device data, Adafruit Unified Sensor format.
Definition: Adafruit_MSA301.cpp:478
15.63 Hz
Definition: Adafruit_MSA301.h:61
bool begin(uint8_t i2c_addr=MSA301_I2CADDR_DEFAULT, TwoWire *wire=&Wire)
Sets up the hardware and initializes I2C.
Definition: Adafruit_MSA301.cpp:49
125 Hz
Definition: Adafruit_MSA301.h:78
500 millis
Definition: Adafruit_MSA301.h:106
void setClick(bool tap_quiet, bool tap_shock, msa301_tapduration_t tapduration, uint8_t tapthresh)
Set the click detection register thresholds.
Definition: Adafruit_MSA301.cpp:314
void setBandwidth(msa301_bandwidth_t bandwidth)
Set the bandwidth, ranges from 1.95Hz to 500Hz.
Definition: Adafruit_MSA301.cpp:183
msa301_resolution_t getResolution(void)
Read the resolution - 8, 10, 12, or 14bits.
Definition: Adafruit_MSA301.cpp:253
Z axis bit.
Definition: Adafruit_MSA301.h:52
3.9 Hz
Definition: Adafruit_MSA301.h:73
Suspend (sleep) mode.
Definition: Adafruit_MSA301.h:87
Y axis bit.
Definition: Adafruit_MSA301.h:51
1.95 Hz
Definition: Adafruit_MSA301.h:72
Low power (slow speed) mode.
Definition: Adafruit_MSA301.h:86
7.81 Hz
Definition: Adafruit_MSA301.h:60
50 millis
Definition: Adafruit_MSA301.h:100
250 millis
Definition: Adafruit_MSA301.h:104
float y_g
The last read Y acceleration in &#39;g&#39;.
Definition: Adafruit_MSA301.h:166
void setPowerMode(msa301_powermode_t mode)
Set the power mode, MSA301_NORMALMODE, MSA301_LOWPOWERMODE or MSA301_SUSPENDMODE. ...
Definition: Adafruit_MSA301.cpp:153
void setDataRate(msa301_dataRate_t dataRate)
Sets the data rate for the MSA301 (controls power consumption) from 1 Hz to 1000Hz.
Definition: Adafruit_MSA301.cpp:104
+/- 2g (default value)
Definition: Adafruit_MSA301.h:42
7.81 Hz
Definition: Adafruit_MSA301.h:74
X axis bit.
Definition: Adafruit_MSA301.h:50
Definition: Adafruit_MSA301.h:120
void setResolution(msa301_resolution_t resolution)
Set the resolution - 8, 10, 12, or 14bits.
Definition: Adafruit_MSA301.cpp:239
msa301_bandwidth_t getBandwidth(void)
Get the bandwidth.
Definition: Adafruit_MSA301.cpp:197
int16_t y
The last read Y acceleration in raw units.
Definition: Adafruit_MSA301.h:163
1.95 Hz
Definition: Adafruit_MSA301.h:58
31.25 Hz
Definition: Adafruit_MSA301.h:76
msa301_dataRate_t
Definition: Adafruit_MSA301.h:56
Double tap interrupt.
Definition: Adafruit_MSA301.h:114
Normal (high speed) mode.
Definition: Adafruit_MSA301.h:85
200 millis
Definition: Adafruit_MSA301.h:103
void enableAxes(bool x, bool y, bool z)
What axes of the accelerometer we want enabled for reading.
Definition: Adafruit_MSA301.cpp:134
msa301_range_t
Definition: Adafruit_MSA301.h:41
msa301_axis_t
Definition: Adafruit_MSA301.h:49
void mapInterruptPin(bool singletap=false, bool doubletap=false, bool activity=false, bool newData=false, bool freefall=false, bool orient=false)
Set which interrupts are mapped to the INT pin.
Definition: Adafruit_MSA301.cpp:397
msa301_interrupt_t
Definition: Adafruit_MSA301.h:111
10-bit resolution
Definition: Adafruit_MSA301.h:94
Orientation change interrupt.
Definition: Adafruit_MSA301.h:112
250 Hz
Definition: Adafruit_MSA301.h:65
int16_t z
The last read Z acceleration in raw units.
Definition: Adafruit_MSA301.h:163
500 Hz
Definition: Adafruit_MSA301.h:80
+/- 4g
Definition: Adafruit_MSA301.h:43
62.5 Hz
Definition: Adafruit_MSA301.h:77
msa301_range_t getRange(void)
Read the resolution range: +-2g, 4g, 8g, or 16g.
Definition: Adafruit_MSA301.cpp:225
msa301_resolution_t
Definition: Adafruit_MSA301.h:91
+/- 16g
Definition: Adafruit_MSA301.h:45
Active motion interrupt.
Definition: Adafruit_MSA301.h:115
uint8_t getMotionInterruptStatus(void)
Gets the most recent motion interrupt status register value.
Definition: Adafruit_MSA301.cpp:423
250 Hz
Definition: Adafruit_MSA301.h:79
float x_g
The last read X acceleration in &#39;g&#39;.
Definition: Adafruit_MSA301.h:166
uint8_t getDataInterruptStatus(void)
Gets the most recent data interrupt status register value.
Definition: Adafruit_MSA301.cpp:438
50 millis700 millis
Definition: Adafruit_MSA301.h:107
#define MSA301_I2CADDR_DEFAULT
Fixed I2C address.
Definition: Adafruit_MSA301.h:16
14-bit resolution
Definition: Adafruit_MSA301.h:92