Arduino Function: NaxisMotion.enableSlowNoMotion

Description

This function is used to enable the slow or no motion interrupt based on the accelerometer.

Syntax

void enableSlowNoMotion(uint8_t threshold, uint8_t duration, bool motion);

Parameters

uint8_t threshold: The threshold that triggers the no motion interrupt

  • The threshold should be entered as an integer. The corresponding value of the threshold depends on the range that has been set on the accelerometer. Below is a table showing the value of 1LSB in corresponding units.


Resolution:

  • ACCEL_RANGE_2G, 1LSB = 3.91mg = ~0.03835m/s2
  • ACCEL_RANGE_4G, 1LSB = 7.81mg = ~0.07661m/s2
  • ACCEL_RANGE_8G, 1LSB = 15.6mg = ~0.15303m/s2
  • ACCEL_RANGE_16G, 1LSB = 31.3mg = ~0.30705m/s2


Maximum:

  • ACCEL_RANGE_2G, 1LSB = 996mg = ~9.77076m/s2,
  • ACCEL_RANGE_4G, 1LSB = 1.99g = ~19.5219m/s2
  • ACCEL_RANGE_8G, 1LSB = 3.98g = ~39.0438m/s2
  • ACCEL_RANGE_16G, 1LSB = 7.97g = ~97.1857m/s2


uint8_t duration: The duration for which the desired threshold should be surpassed. The time difference between the successive acceleration signals depends on the selected bandwidth and equates to 1/(2*bandwidth). In order to suppress false triggers, the interrupt is only generated (cleared). If a certain number N of consecutive slope data points is larger (smaller) than the slope 'threshold'. This number is set by the 'duration'. It is N = duration + 1.

Resolution:

  • ACCEL_BW_7_81HZ, 1LSB = 64ms
  • ACCEL_BW_15_63HZ, 1LSB = 32ms
  • ACCEL_BW_31_25HZ, 1LSB = 16ms
  • ACCEL_BW_62_5HZ, 1LSB = 8ms
  • ACCEL_BW_125HZ, 1LSB = 4ms
  • ACCEL_BW_250HZ, 1LSB = 2ms
  • ACCEL_BW_500HZ, 1LSB = 1ms
  • ACCEL_BW_1000HZ, 1LSB = 0.5ms


bool motion: To trigger either a Slow motion or a No motion interrupt

  • NO_MOTION 1 Enables the no motion interrupt
  • SLOW_MOTION 0 Enables the slow motion interrupt

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);

attachInterrupt(INT_PIN, motionISR, RISING); //Attach the interrupt to the Interrupt Service Routine for a Rising Edge. Change the interrupt pin depending on the board

//Setup the initial interrupt to trigger at No Motion
mySensor.resetInterrupt();
mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION);
anyMotion = false;
mySensor.accelInterrupts(ENABLE, ENABLE, ENABLE); //Accelerometer interrupts can be triggered from all 3 axes

Serial.println("This is a game to test how steady you can move an object with one hand. \nKeep the device on a table and mark 2 points.");
Serial.println("Move the Device from one place to another without triggering the Any Motion Interrupt.\n\n");
delay(1000); //Delay for the player(s) to read
Serial.println("Move the device around and then place it at one position.\nChange the threshold and duration to increase the difficulty level.");
Serial.println("Have fun!\n\n");
}

void loop() { //This code is looped forever
if (intDetected) {
if (anyMotion) {
Serial.println("You moved!! Try again. Keep the Device at one place.\n");
intDetected = false;
mySensor.resetInterrupt(); //Reset the interrupt line
mySensor.disableAnyMotion(); //Disable the Any motion interrupt
mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); //Enable the No motion interrupt (can also use the Slow motion instead)
anyMotion = false;
} else {
Serial.println("Device is not moving. You may start again.\n\n\n");
intDetected = false;
mySensor.resetInterrupt(); //Reset the interrupt line
mySensor.disableSlowNoMotion(); //Disable the Slow or No motion interrupt
mySensor.enableAnyMotion(threshold, duration); //Enable the Any motion interrupt
anyMotion = true;
}
}
}

//Interrupt Service Routine when the sensor triggers an Interrupt
void motionISR() {
intDetected = true;
}


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