Arduino 101 CurieIMU Tap detection

With this tutorial you learn how to detect double taps made on the board in a limited time interval and on any of the three axes.

With this tutorial you learn how to detect double taps made on the board in a limited time interval and on any of the three axes. This tutorial sets the accelerometer range for stronger taps and sets a window of a quarter of second to consider two taps as a double tap event.

Hardware Required

The Circuit

genuino101fzz

image developed using Fritzing. No additional hardware is needed to use this tutorial.

Software Essentials

Libraries

CurieIMU.h is the library that gives access to all the parameters, features and readings of the IMU chip of the 101 board. This unit contains a three axes accelerometer and a three axes gyroscope. This library is part of the 101 board core and it is loaded together with the core files for Arduino 101. In this tutorial we use the Tap detection feature of the IMU through the dedicated functions of this library.

Functions

None

Code

This sketch has the setup block that contains all the code necessary to set up the double tap detection event. The interrupt is enabled and when asserted is serviced by the callback function. This function reads all the possiple combinations of axes and direction to print on Serial port the axis and direction of the double tap. The main loop is empty.

1/*
2
3 * Copyright (c) 2016 Intel Corporation. All rights reserved.
4
5 * See the bottom of this file for the license terms.
6
7 */
8
9/*
10
11 This sketch example demonstrates how the BMI160 accelerometer on the
12
13 Intel(R) Curie(TM) module can be used to detect tap events
14
15*/
16
17#include "CurieIMU.h"
18
19void setup() {
20
21 Serial.begin(9600); // initialize Serial communication
22
23 while(!Serial) ; // wait for serial port to connect.
24
25 // Initialise the IMU
26
27 CurieIMU.begin();
28
29 CurieIMU.attachInterrupt(eventCallback);
30
31 // Increase Accelerometer range to allow detection of stronger taps (< 4g)
32
33 CurieIMU.setAccelerometerRange(4);
34
35 // Reduce threshold to allow detection of weaker taps (>= 750mg)
36
37 CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 750); // (750mg)
38
39 // Enable Double-Tap detection
40
41 CurieIMU.interrupts(CURIE_IMU_TAP);
42
43 Serial.println("IMU initialization complete, waiting for events...");
44}
45
46void loop() {
47
48 // nothing happens in the loop because all the action happens
49
50 // in the callback function.
51}
52
53static void eventCallback()
54{
55
56 if (CurieIMU.getInterruptStatus(CURIE_IMU_TAP)) {
57
58 if (CurieIMU.tapDetected(X_AXIS, NEGATIVE))
59
60 Serial.println("Tap detected on negative X-axis");
61
62 if (CurieIMU.tapDetected(X_AXIS, POSITIVE))
63
64 Serial.println("Tap detected on positive X-axis");
65
66 if (CurieIMU.tapDetected(Y_AXIS, NEGATIVE))
67
68 Serial.println("Tap detected on negative Y-axis");
69
70 if (CurieIMU.tapDetected(Y_AXIS, POSITIVE))
71
72 Serial.println("Tap detected on positive Y-axis");
73
74 if (CurieIMU.tapDetected(Z_AXIS, NEGATIVE))
75
76 Serial.println("Tap detected on negative Z-axis");
77
78 if (CurieIMU.tapDetected(Z_AXIS, POSITIVE))
79
80 Serial.println("Tap detected on positive Z-axis");
81
82 }
83}
84
85/*
86
87 Copyright (c) 2016 Intel Corporation. All rights reserved.
88
89 This library is free software; you can redistribute it and/or
90
91 modify it under the terms of the GNU Lesser General Public
92
93 License as published by the Free Software Foundation; either
94
95 version 2.1 of the License, or (at your option) any later version.
96
97 This library is distributed in the hope that it will be useful,
98
99 but WITHOUT ANY WARRANTY; without even the implied warranty of
100
101 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
102
103 Lesser General Public License for more details.
104
105 You should have received a copy of the GNU Lesser General Public
106
107 License along with this library; if not, write to the Free Software
108
109 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
110
111*/

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.