Initialization
Before getting information from the accelerometer, it has to be initialized, setting its registers with the appropriate values.
Initializing the accelerometer
The ON()
function initializes the communication with the accelerometer via I2C bus and sets up the registers.
It makes no tests and checks nothing from the communication, therefore returns nothing and modifies no flags.
Full-scale value can be selected when initializing the accelerometer, options are:
FS_2G
→ ±2G (default)
FS_4G
→ ±4G
FS_8G
→ ±8G
Example of use:
Rebooting the accelerometer
The boot()
function reboots the accelerometer, taking for granted the accelerometer is on and forcing the sensor to reboot by writing to the control register 2.
It makes no tests and checks nothing from the communication, therefore returns nothing and modifies no flags.
Example of use:
Closing the accelerometer
The OFF()
function sets the accelerometer module to the Power Down mode taking for granted the accelerometer is on and powering down the sensor.
It closes I2C bus as well.
It makes no tests and checks nothing from the communication, therefore returns nothing and modifies no flags.
Example of use:
Getting status
The getStatus()
function gets the accelerometer status.
It returns a byte containing the status of the accelerometer reading from the proper register. In the case there is a communication error the ACC_ERROR_READING
flag will will be set.
Example of use:
Getting correct working
The check()
function gets if the accelerometer is present and is working properly. It reads a dummy register that should always answer 0x32, otherwise an error occurred.
This function can be used for determining if the accelerometer is on the board and checking if it is still working properly.
Since it calls readRegister()
, it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING
in case there was an error communicating to the register.
Example of use:
Available information:
On correct working, 'status' should be equal to 0x32.
Last updated