An access library for the MMA8452 accelerometer
Controlled by I2C
|
I2C based access library for the MMA8452 accelerometer using pigpio for I2C access
Copyright U. Raich Nov. 2018
This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2018
It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html.
More...
Functions | |
void | mma8452SetDebug (bool onOff) |
switching debug messages on or off More... | |
int | mma8452Setup (void) |
Setup the accelerometer on the I2C bus of the RPi Opens the connection to the pigoio daemon. More... | |
void | mma8452Close (void) |
Closes the program in an orderly fashion. Disconnects from the pigpiod daemon. | |
int | mma8452Init (void) |
Checks if the accelerometer's device WHO_AM_I register shows the right value of 0x2a. More... | |
int | mma8452ReadXYZ (int16_t *buf) |
Function to read raw X,Y,Z acceleration values. The mma8452 is put into active mode. More... | |
int | mma8452ReadXYZCounts (int16_t *buf) |
Function to read X,Y,Z axes values as integer counts. This calls mma8452ReadXYZ and transforms the result to right adjusted signed integer values. More... | |
int | mma8452ReadXYZ_G (float *buf) |
Function to read X,Y,Z axes values in units of g. This calls mma8452ReadXYZ and calculates the corresponding floating point values in units if g. More... | |
bool | mma8452GetFastRead () |
Checks if the mma8452 is in fast read mode. In fast read mode only the 8 most significant bits are read out. More... | |
int | mma8452SetFastRead (bool onOff) |
Sets or removes mma8452 fast read mode. In fast read mode only the 8 most significant bits are read out. More... | |
int | mma8452GetRange () |
Gets the dynamic range The mma8452 has 3 dynamic ranges: 2g, 4g, 8g full scale. More... | |
int | mma8452SetRange (int range) |
Sets the dynamic range The mma8452 has 3 dynamic ranges: 2g, 4g, 8g full scale. More... | |
char * | mma8452Range2String (int range) |
Converts the dynamic range code into a humanly readable text. More... | |
char * | mma8452DataRate2String (int dataRate) |
Converts the data rate code into a humanly readable text. More... | |
int | mma8452GetDataRate (void) |
Gets the data rate code. More... | |
int | mma8452SetDataRate (int dataRate) |
Sets the data rate code. More... | |
char * | mma8452DataErrorCode2String (int errorCode) |
Converts the error code into a humanly readable text. More... | |
int | mma8452GetMode (void) |
Gets the running mode. More... | |
char * | mma8452Mode2String (int mode) |
Converts the running mode code into a humanly readable string. More... | |
int | mma8452GetActiveStandby () |
Checks if the mma8452 is in standby or active mode. More... | |
int | mma8452SetActive () |
Sets the mma8452 to active mode. In this mode acceleration data are aquired. More... | |
int | mma8452SetStandby () |
Sets the mma8452 to standby mode. In this mode configuration registers can be programmed. More... | |
int | mma8452EnablePL (bool onOff) |
Enables or disables Portrait / Landscape mode. PL mode allows to find out if the device is horizontal or vertical and if is is upside down. More... | |
bool | mma8452IsPLEnabled () |
Checks if Portrait / Landscape mode is enabled. PL mode allows to find out if the device is horizontal or vertical and if is is upside down. More... | |
int | mma8452GetOrientation (void) |
Get a code for the orientation. More... | |
char * | mma8452Orientation2String (int orientation) |
Converts the orientation code into a humanly readable string. More... | |
I2C based access library for the MMA8452 accelerometer using pigpio for I2C access
Copyright U. Raich Nov. 2018
This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2018
It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html.
Reads out the mma8452 accelerometer using the libmm8542.so shared library. It Copyright U. Raich Nov. 2018 This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2018 It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html.
:
char* mma8452DataErrorCode2String | ( | int | errorCode | ) |
Converts the error code into a humanly readable text.
data | rate: error code |
dynamic_range_string | a string describing the error |
char* mma8452DataRate2String | ( | int | dataRate | ) |
Converts the data rate code into a humanly readable text.
data_rate | the data rate code |
dynamic_range_string | a string describing the dynamic range |
int mma8452EnablePL | ( | bool | onOff | ) |
Enables or disables Portrait / Landscape mode. PL mode allows to find out if the device is horizontal or vertical and if is is upside down.
int mma8452GetActiveStandby | ( | void | ) |
Checks if the mma8452 is in standby or active mode.
active_standby | MMA8452_ACTIVE if active, MMA8452_STANDBY if in standby mode or sleep |
int mma8452GetDataRate | ( | void | ) |
Gets the data rate code.
data_rate | code for the data rate |
bool mma8452GetFastRead | ( | void | ) |
Checks if the mma8452 is in fast read mode. In fast read mode only the 8 most significant bits are read out.
fast_mode | true if in fast mode, false otherwise |
int mma8452GetMode | ( | void | ) |
Gets the running mode.
running_mode | code for the running mode, which can be standby, wake or sleep |
int mma8452GetOrientation | ( | void | ) |
Get a code for the orientation.
orientation | code for the orientation, returns -1 of PL mode is not enabled |
int mma8452GetRange | ( | void | ) |
Gets the dynamic range The mma8452 has 3 dynamic ranges: 2g, 4g, 8g full scale.
range | a code for the dynamic range: MMA8452_FULL_SCALE_2G, MMA8452_FULL_SCALE_4G, MMA8452_FULL_SCALE_8G |
int mma8452Init | ( | void | ) |
Checks if the accelerometer's device WHO_AM_I register shows the right value of 0x2a.
error_code | MMA8452_SUCCESS if the identification was found MMA8452_NOT_FOUND otherwise |
bool mma8452IsPLEnabled | ( | void | ) |
Checks if Portrait / Landscape mode is enabled. PL mode allows to find out if the device is horizontal or vertical and if is is upside down.
char* mma8452Mode2String | ( | int | mode | ) |
Converts the running mode code into a humanly readable string.
char* mma8452Orientation2String | ( | int | orientation | ) |
Converts the orientation code into a humanly readable string.
char* mma8452Range2String | ( | int | range | ) |
Converts the dynamic range code into a humanly readable text.
data | rate: the dynamic range code |
dynamic_range_string | a string describing the dynamic range |
int mma8452ReadXYZ | ( | int16_t * | buf | ) |
Function to read raw X,Y,Z acceleration values. The mma8452 is put into active mode.
pointer | to a buffer of 3 int16_t values buf[0] = X, buf[1] = Y, buf[2] = z The acceleration values are signed 12 bit, left adjusted values |
an | error_code: MMA8452_SUCCESS if successful |
int mma8452ReadXYZ_G | ( | float * | buf | ) |
Function to read X,Y,Z axes values in units of g. This calls mma8452ReadXYZ and calculates the corresponding floating point values in units if g.
fbuf | pointer to a buffer of 3 float values buf[0] = X, buf[1] = Y, buf[2] = z The acceleration values are signed 12 bit, left adjusted values |
error_code | MMA8452_SUCCESS if successful |
int mma8452ReadXYZCounts | ( | int16_t * | buf | ) |
Function to read X,Y,Z axes values as integer counts. This calls mma8452ReadXYZ and transforms the result to right adjusted signed integer values.
buf | pointer to a buffer of 3 int16_t values buf[0] = X, buf[1] = Y, buf[2] = z The acceleration values are signed 12 bit, left adjusted values |
error_code | MMA8452_SUCCESS if successful |
int mma8452SetActive | ( | ) |
Sets the mma8452 to active mode. In this mode acceleration data are aquired.
error_code | MMA8452_SUCCESS if successful an error code otherwise |
int mma8452SetDataRate | ( | int | dataRate | ) |
Sets the data rate code.
void mma8452SetDebug | ( | bool | onOff | ) |
switching debug messages on or off
onOff | to switch debug mode on or off |
int mma8452SetFastRead | ( | bool | onOff | ) |
Sets or removes mma8452 fast read mode. In fast read mode only the 8 most significant bits are read out.
int mma8452SetRange | ( | int | range | ) |
Sets the dynamic range The mma8452 has 3 dynamic ranges: 2g, 4g, 8g full scale.
range | code for the dynamic range |
error_code | MMA8452_SUCCESS if successful, a negative error code otherwise |
int mma8452SetStandby | ( | ) |
Sets the mma8452 to standby mode. In this mode configuration registers can be programmed.
MMA8452_SUCCESS | if successful an error code otherwise |
int mma8452Setup | ( | void | ) |
Setup the accelerometer on the I2C bus of the RPi Opens the connection to the pigoio daemon.
error_code | MMA8452_SUCCESS if successful, MMA8452_PIGPIO_INIT_FAILURE otherwise |
char* mm8452DataRangeString[] |
char* mm8452ErrorString[] |
char* mma8452ModeString[] |
char* mma8452OrientationString[] |
char* mma8452RangeString[] |