In the last tutorial we learnt how to install the MMA7455 library, in this part we will have a look at the various functions available in the library.
MMA7455Init
This function must be called once at the start of the program. It initializes various things before we can take reading from the sensor.
uint8_t MMA7455Init(uint8_t range)
Parameters
- range
-
Range of operation required. Can be one of the following :-
- MMA7455_RANGE_8G
- MMA7455_RANGE_2G
- MMA7455_RANGE_4G
Please read this article for more information on range of accelerometers.
Returns
- 0 on failure
- 1 on success
Example
Following example tries to initialize the MMA7455 accelerometer in 2G range and if it fails shows an error message on LCD and halts.
//Initialize the MMA7455 accelerometer
uint8_t res; //result of operation
res=MMA7455Init(MMA7455_RANGE_2G);
if(res==0)
{
//Error!
LCDWriteFStringXY(0,0,PSTR("MMA7455 Chip "));
LCDWriteFStringXY(0,1,PSTR("NOT Found ! "));
//Halt!
while(1){}
}
MMA7455SetMode
This function is generally used to bring out the MMA7455 module from standby mode. At power up the module is in standby mode.
uint8_t MMA7455SetMode(uint8_t mode)
Parameters
- mode
-
The required mode in which you want the module to go.
- MMA7455_MODE_STANDBY
- MMA7455_MODE_MEASURE
- MMA7455_MODE_LEVEL
- MMA7455_MODE_PULSE
Set the module to MMA7455_MODE_MEASURE for normal acceleration measurement.
This function is automatically called by the function MMA7455Init() so you do not need to call it explicitly. But can be used to put device in standby mode for power saving.
Returns
- 0 on failure
- 1 on success
MMA7455IsDataReady
You should call this function before reading the acceleration value to find out if the conversion of acceleration to digital form is completed or not. If the function returns 1 then you are sure the data is ready to be read.
uint8_t MMA7455IsDataReady()
Parameters
- none
Returns
- 0 if no data is available to be read
- 1 if acceleration data is available to be read
MMA7455GetX
Returns the acceleration sensed along X axis. The value has a range from -128 to 127. Conversion of this value to actual SI units for acceleration requires knowledge about the sensitivity and range of accelerometers.
int16_t MMA7455GetX()
Parameters
- none
Returns
Returns the acceleration sensed along X axis
MMA7455GetY
Returns the acceleration sensed along Y axis. The value has a range from -128 to 127. Conversion of this value to actual SI units for acceleration requires knowledge about the sensitivity and range of accelerometers.
int16_t MMA7455GetY()
Parameters
- none
Returns
Returns the acceleration sensed along Y axis
MMA7455GetZ
Returns the acceleration sensed along Z axis. The value has a range from -128 to 127. Conversion of this value to actual SI units for acceleration requires knowledge about the sensitivity and range of accelerometers.
int16_t MMA7455GetZ()
Parameters
- none
Returns
Returns the acceleration sensed along Z axis
We cordially thanks the following peoples who shared this page on various social networks and insprided us to develop more quality contents!