Adafruit MSA301 Sensor Library
Public Member Functions | Public Attributes | List of all members
Adafruit_MSA301 Class Reference

#include <Adafruit_MSA301.h>

Inheritance diagram for Adafruit_MSA301:
Adafruit_MSA311

Public Member Functions

 Adafruit_MSA301 (void)
 Instantiates a new MSA301 class.
 
bool begin (uint8_t i2c_addr=MSA301_I2CADDR_DEFAULT, TwoWire *wire=&Wire)
 Sets up the hardware and initializes I2C. More...
 
void setDataRate (msa301_dataRate_t dataRate)
 Sets the data rate for the MSA301 (controls power consumption) from 1 Hz to 1000Hz. More...
 
msa301_dataRate_t getDataRate (void)
 Gets the data rate for the MSA301 (controls power consumption) More...
 
void enableAxes (bool x, bool y, bool z)
 What axes of the accelerometer we want enabled for reading. More...
 
void setPowerMode (msa301_powermode_t mode)
 Set the power mode, MSA301_NORMALMODE, MSA301_LOWPOWERMODE or MSA301_SUSPENDMODE. More...
 
msa301_powermode_t getPowerMode (void)
 Get the power mode. More...
 
void setBandwidth (msa301_bandwidth_t bandwidth)
 Set the bandwidth, ranges from 1.95Hz to 500Hz. More...
 
msa301_bandwidth_t getBandwidth (void)
 Get the bandwidth. More...
 
void setRange (msa301_range_t range)
 Set the resolution range: +-2g, 4g, 8g, or 16g. More...
 
msa301_range_t getRange (void)
 Read the resolution range: +-2g, 4g, 8g, or 16g. More...
 
void setResolution (msa301_resolution_t resolution)
 Set the resolution - 8, 10, 12, or 14bits. More...
 
msa301_resolution_t getResolution (void)
 Read the resolution - 8, 10, 12, or 14bits. More...
 
void read ()
 Read the XYZ data from the accelerometer and store in the internal x, y and z (and x_g, y_g, z_g) member variables.
 
bool getEvent (sensors_event_t *event)
 Gets the most recent sensor event, Adafruit Unified Sensor format. More...
 
void getSensor (sensor_t *sensor)
 Gets the sensor_t device data, Adafruit Unified Sensor format. More...
 
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. More...
 
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. More...
 
uint8_t getClick (void)
 Gets the most recent click detect status register value. More...
 
uint8_t getMotionInterruptStatus (void)
 Gets the most recent motion interrupt status register value. More...
 
uint8_t getDataInterruptStatus (void)
 Gets the most recent data interrupt status register value. More...
 
void setClick (bool tap_quiet, bool tap_shock, msa301_tapduration_t tapduration, uint8_t tapthresh)
 Set the click detection register thresholds. More...
 

Public Attributes

int16_t x
 The last read X acceleration in raw units.
 
int16_t y
 The last read Y acceleration in raw units.
 
int16_t z
 The last read Z acceleration in raw units.
 
float x_g
 The last read X acceleration in 'g'.
 
float y_g
 The last read Y acceleration in 'g'.
 
float z_g
 The last read X acceleration in 'g'.
 

Detailed Description

Class for hardware interfacing with an MSA301 accelerometer

Member Function Documentation

◆ begin()

bool Adafruit_MSA301::begin ( uint8_t  i2c_address = MSA301_I2CADDR_DEFAULT,
TwoWire *  wire = &Wire 
)

Sets up the hardware and initializes I2C.

Parameters
i2c_addressThe I2C address to be used.
wireThe Wire object to be used for I2C connections.
Returns
True if initialization was successful, otherwise false.

◆ setDataRate()

void Adafruit_MSA301::setDataRate ( msa301_dataRate_t  dataRate)

Sets the data rate for the MSA301 (controls power consumption) from 1 Hz to 1000Hz.

Parameters
dataRateEnumerated msa301_dataRate_t

◆ getDataRate()

msa301_dataRate_t Adafruit_MSA301::getDataRate ( void  )

Gets the data rate for the MSA301 (controls power consumption)

Returns
Enumerated msa301_dataRate_t from 1 Hz to 1000Hz

◆ enableAxes()

void Adafruit_MSA301::enableAxes ( bool  enableX,
bool  enableY,
bool  enableZ 
)

What axes of the accelerometer we want enabled for reading.

Parameters
enableXTrue to enable X axis
enableYTrue to enable Y axis
enableZTrue to enable Z axis

◆ setPowerMode()

void Adafruit_MSA301::setPowerMode ( msa301_powermode_t  mode)

Set the power mode, MSA301_NORMALMODE, MSA301_LOWPOWERMODE or MSA301_SUSPENDMODE.

Parameters
modeEnumerated msa301_powermode_t

◆ getPowerMode()

msa301_powermode_t Adafruit_MSA301::getPowerMode ( void  )

Get the power mode.

Returns
Enumerated msa301_powermode_t, MSA301_NORMALMODE, MSA301_LOWPOWERMODE or MSA301_SUSPENDMODE

◆ setBandwidth()

void Adafruit_MSA301::setBandwidth ( msa301_bandwidth_t  bandwidth)

Set the bandwidth, ranges from 1.95Hz to 500Hz.

Parameters
bandwidthEnumerated msa301_range_t

◆ getBandwidth()

msa301_bandwidth_t Adafruit_MSA301::getBandwidth ( void  )

Get the bandwidth.

Returns
Enumerated msa301_bandwidth_t, ranges from 1.95Hz to 500Hz

◆ setRange()

void Adafruit_MSA301::setRange ( msa301_range_t  range)

Set the resolution range: +-2g, 4g, 8g, or 16g.

Parameters
rangeEnumerated msa301_range_t

◆ getRange()

msa301_range_t Adafruit_MSA301::getRange ( void  )

Read the resolution range: +-2g, 4g, 8g, or 16g.

Returns
Enumerated msa301_range_t

◆ setResolution()

void Adafruit_MSA301::setResolution ( msa301_resolution_t  resolution)

Set the resolution - 8, 10, 12, or 14bits.

Parameters
resolutionEnumerated msa301_resolution_t

◆ getResolution()

msa301_resolution_t Adafruit_MSA301::getResolution ( void  )

Read the resolution - 8, 10, 12, or 14bits.

Returns
Enumerated msa301_resolution_t

◆ getEvent()

bool Adafruit_MSA301::getEvent ( sensors_event_t *  event)

Gets the most recent sensor event, Adafruit Unified Sensor format.

Parameters
eventPointer to an Adafruit Unified sensor_event_t object that we'll fill in
Returns
True on successful read

◆ getSensor()

void Adafruit_MSA301::getSensor ( sensor_t *  sensor)

Gets the sensor_t device data, Adafruit Unified Sensor format.

Parameters
sensorPointer to an Adafruit Unified sensor_t object that we'll fill in

◆ enableInterrupts()

void Adafruit_MSA301::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.

Parameters
singletapWhether to trigger INT on single tap interrupt
doubletapWhether to trigger INT on double tap interrupt
activeXWhether to trigger INT on X axis activity interrupt
activeYWhether to trigger INT on Y axis activity interrupt
activeZWhether to trigger INT on Z axis activity interrupt
newDataWhether to trigger INT on new data available interrupt
freefallWhether to trigger INT on freefall interrupt
orientWhether to trigger INT on orientation interrupt

◆ mapInterruptPin()

void Adafruit_MSA301::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.

Parameters
singletapWhether to trigger INT on single tap interrupt
doubletapWhether to trigger INT on double tap interrupt
activityWhether to trigger INT on activity interrupt
newDataWhether to trigger INT on new data available interrupt
freefallWhether to trigger INT on freefall interrupt
orientWhether to trigger INT on orientation interrupt

◆ getClick()

uint8_t Adafruit_MSA301::getClick ( void  )

Gets the most recent click detect status register value.

Returns
8 bits of interrupt status, check datasheet for what CLICKSTATUS bits are

◆ getMotionInterruptStatus()

uint8_t Adafruit_MSA301::getMotionInterruptStatus ( void  )

Gets the most recent motion interrupt status register value.

Returns
8 bits of interrupt status, check datasheet for what MOTION bits are

◆ getDataInterruptStatus()

uint8_t Adafruit_MSA301::getDataInterruptStatus ( void  )

Gets the most recent data interrupt status register value.

Returns
8 bits of interrupt status, check datasheet for what DATAINT bits are

◆ setClick()

void Adafruit_MSA301::setClick ( bool  tap_quiet,
bool  tap_shock,
msa301_tapduration_t  tapduration,
uint8_t  tapthresh 
)

Set the click detection register thresholds.

Parameters
tap_quietTAP_QUIET flag (check datasheet for details)
tap_shockTAP_SHOCK flag (check datasheet for details)
tapdurationHow long to listen for a second tap (check datasheet for details)
tapthreshHow strong the tap signal has to be (check datasheet for details)

The documentation for this class was generated from the following files: