Arduino Function: NaxisMotion.readAccelRange

Description

This function is used to return the accelerometer range

Syntax

uint8_t readAccelRange(void)

Returns

 uint8_t range: Range of the accelerometer ACCEL_RANGE_2G 0X00 ACCEL_RANGE_4G 0X01 ACCEL_RANGE_8G 0X02 ACCEL_RANGE_16G 0X03

Examples

//Contains the bridge code between the API and the Arduino Environment
#include "NAxisMotion.h"
#include <Wire.h>

//Object that for the sensor
NAxisMotion mySensor;

//To store the last streamed time stamp
unsigned long lastStreamTime = 0;

//To stream at 25Hz without using additional timers (time period(ms) =1000/frequency(Hz))
const int streamPeriod = 40;

//Flag to update the sensor data. Default is true to perform the first read before the first stream
bool updateSensorData = true;

void setup() { //This code is executed once
//Peripheral Initialization
//Initialize the Serial Port to view information on the Serial Monitor
Serial.begin(115200);

//Initialize I2C communication to the let the library communicate with the sensor.
//The I2C Address can be changed here inside this function in the library
I2C.begin();

/* Sensor Initialization */
//Can be configured to other operation modes as desired
mySensor.initSensor();

//The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions
mySensor.setOperationMode(OPERATION_MODE_NDOF);

//Setting to MANUAL requires lesser reads to the sensor
mySensor.setUpdateMode(MANUAL);

mySensor.updateAccelConfig();
updateSensorData = true;
Serial.println();
Serial.println("Default accelerometer configuration settings...");
Serial.print("Range: ");
Serial.println(mySensor.readAccelRange());
Serial.print("Bandwidth: ");
Serial.println(mySensor.readAccelBandwidth());
Serial.print("Power Mode: ");
Serial.println(mySensor.readAccelPowerMode());
Serial.println("Streaming in ..."); //Countdown
Serial.print("3...");
delay(1000); //Wait for a second
Serial.print("2...");
delay(1000); //Wait for a second
Serial.println("1...");
delay(1000); //Wait for a second
}

void loop() { //This code is looped forever
if (updateSensorData) { //Keep the updating of data as a separate task
//Update the Accelerometer data
mySensor.updateAccel();
//Update the Linear Acceleration data
mySensor.updateLinearAccel();
//Update the Gravity Acceleration data
mySensor.updateGravAccel();
//Update the Calibration Status
mySensor.updateCalibStatus();
updateSensorData = false;
}
if ((millis() - lastStreamTime) >= streamPeriod) {
lastStreamTime = millis();

Serial.print("Time: ");
Serial.print(lastStreamTime);
Serial.print("ms ");

Serial.print(" aX: ");
Serial.print(mySensor.readAccelX());
//Accelerometer X-Axis data
Serial.print("m/s2 ");

Serial.print(" aY: ");
Serial.print(mySensor.readAccelY());
//Accelerometer Y-Axis data
Serial.print("m/s2 ");

Serial.print(" aZ: ");
Serial.print(mySensor.readAccelZ());
//Accelerometer Z-Axis data
Serial.print("m/s2 ");

Serial.print(" lX: ");
Serial.print(mySensor.readLinearAccelX());
//Linear Acceleration X-Axis data
Serial.print("m/s2 ");

Serial.print(" lY: ");
Serial.print(mySensor.readLinearAccelY());
//Linear Acceleration Y-Axis data
Serial.print("m/s2 ");

Serial.print(" lZ: ");
Serial.print(mySensor.readLinearAccelZ());
//Linear Acceleration Z-Axis data
Serial.print("m/s2 ");

Serial.print(" gX: ");
Serial.print(mySensor.readGravAccelX());
//Gravity Acceleration X-Axis data
Serial.print("m/s2 ");

Serial.print(" gY: ");
Serial.print(mySensor.readGravAccelY());
//Gravity Acceleration Y-Axis data
Serial.print("m/s2 ");

Serial.print(" gZ: ");
Serial.print(mySensor.readGravAccelZ());
//Gravity Acceleration Z-Axis data
Serial.print("m/s2 ");

Serial.print(" C: ");
Serial.print(mySensor.readAccelCalibStatus());
//Accelerometer Calibration Status (0 - 3)
Serial.println();

updateSensorData = true;
}
}


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc