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:

{
// Initializes the accelerometer with a full-scale value of ±2G
ACC.ON();
// Initializes the accelerometer with a full-scale value of ±2G
ACC.ON( FS_2G );
// Initializes the accelerometer with a full-scale value of ±4G
ACC.ON( FS_4G );
// Initializes the accelerometer with a full-scale value of ±8G
ACC.ON( FS_8G );
}

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:

{
ACC.boot();
}

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:

{
ACC.OFF();
}

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:

{
uint8_t status;
status = ACC.getStatus();
}

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:

{
uint8_t status;
status = ACC.check();
}

Available information:

On correct working, 'status' should be equal to 0x32.

Last updated