Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit 793b734

Browse files
DHJeffchiararuggeri
authored andcommitted
Added Primo Core sensor functions and examples (#50)
* Added Primo Core sensor functions and examples * Modified argument by reference
1 parent 4a2d74a commit 793b734

File tree

11 files changed

+960
-73
lines changed

11 files changed

+960
-73
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
DoubleTap.ino
3+
4+
Written by Jeff Wu ([email protected])
5+
6+
This example for the Arduino Primo Core shows how to use
7+
CoreSensors library.
8+
The example is to show how to detect the double tap
9+
event with the Primo Core. Trying to double tap the
10+
Primo Core, when the event is triggered, the USER LED
11+
will blink twice.
12+
You can check data using serial or BLE *nRF Toolbox*
13+
uart application. When a device with NFC is near to the
14+
Primo Core with NFC antenna, it will try to open the
15+
Nordic's *nRF Toolbox* or look for the app in the store.
16+
17+
This example code is in the public domain.
18+
19+
*/
20+
21+
#include <CoreSensors.h>
22+
#include <BLEPeripheral.h>
23+
#include <BLESerial.h>
24+
#include <NFC.h>
25+
26+
// interrupt pin
27+
#define INT1 21
28+
29+
// create ble serial instance
30+
BLESerial bleSerial = BLESerial();
31+
32+
// specify the package name for windows and android phone and insert the EOL character at the end '\0'
33+
static const char android_package_name[] = {'n', 'o', '.', 'n', 'o', 'r', 'd', 'i', 'c', 's',
34+
'e', 'm', 'i', '.', 'a', 'n', 'd', 'r', 'o', 'i',
35+
'd', '.', 'n', 'r', 'f', 't', 'o', 'o', 'l', 'b',
36+
'o', 'x','\0'};
37+
38+
static const char windows_application_id[] = {'{', 'e', '1', '2', 'd', '2', 'd', 'a', '7', '-',
39+
'4', '8', '8', '5', '-', '4', '0', '0', 'f', '-',
40+
'b', 'c', 'd', '4', '-', '6', 'c', 'b', 'd', '5',
41+
'b', '8', 'c', 'f', '6', '2', 'c', '}', '\0'};
42+
43+
int double_tap = 0;
44+
45+
void setup() {
46+
// initialize digital pin LED_BUILTIN as an output.
47+
pinMode(LED_BUILTIN, OUTPUT);
48+
// start serial port at 115200 bps
49+
Serial.begin(115200);
50+
// custom services and characteristics can be added as well
51+
bleSerial.setLocalName("Arduino Primo Core");
52+
// start ble serial
53+
bleSerial.begin();
54+
// set the Android packge name as first and the Windows application id as second
55+
NFC.setAPPmessage(android_package_name, windows_application_id);
56+
// start the NFC module
57+
NFC.start();
58+
// start the core sensors
59+
coresensors.begin();
60+
// enable double tap detection
61+
coresensors.enableDoubleTapDetection();
62+
// set up interrupt pin to sensor
63+
attachInterrupt(INT1, DoubleTap, RISING);
64+
}
65+
66+
void loop() {
67+
// check interrupt flag
68+
if (double_tap) {
69+
double_tap = 0;
70+
uint8_t status = 0;
71+
// get double tap detection status
72+
coresensors.getStatusDoubleTapDetection(status);
73+
if (status)
74+
{
75+
digitalWrite(LED_BUILTIN, HIGH);
76+
delay(100);
77+
digitalWrite(LED_BUILTIN, LOW);
78+
delay(100);
79+
digitalWrite(LED_BUILTIN, HIGH);
80+
delay(100);
81+
digitalWrite(LED_BUILTIN, LOW);
82+
83+
Serial.println("Double Tap Detected!");
84+
bleSerial.println("Double Tap Detected!");
85+
}
86+
}
87+
}
88+
89+
// interrupt service routine
90+
void DoubleTap()
91+
{
92+
double_tap = 1;
93+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
FreeFall.ino
3+
4+
Written by Jeff Wu ([email protected])
5+
6+
This example for the Arduino Primo Core shows how to use
7+
CoreSensors library.
8+
The example is to show how to detect the free fall
9+
event with the Primo Core. Trying to leave falling the
10+
Primo Core, when the event is triggered, the USER LED
11+
will blink once.
12+
You can check data using serial or BLE *nRF Toolbox*
13+
uart application. When a device with NFC is near to the
14+
Primo Core with NFC antenna, it will try to open the
15+
Nordic's *nRF Toolbox* or look for the app in the store.
16+
17+
This example code is in the public domain.
18+
19+
*/
20+
21+
#include <CoreSensors.h>
22+
#include <BLEPeripheral.h>
23+
#include <BLESerial.h>
24+
#include <NFC.h>
25+
26+
// interrupt pin
27+
#define INT1 21
28+
29+
// create ble serial instance
30+
BLESerial bleSerial = BLESerial();
31+
32+
// specify the package name for windows and android phone and insert the EOL character at the end '\0'
33+
static const char android_package_name[] = {'n', 'o', '.', 'n', 'o', 'r', 'd', 'i', 'c', 's',
34+
'e', 'm', 'i', '.', 'a', 'n', 'd', 'r', 'o', 'i',
35+
'd', '.', 'n', 'r', 'f', 't', 'o', 'o', 'l', 'b',
36+
'o', 'x','\0'};
37+
38+
static const char windows_application_id[] = {'{', 'e', '1', '2', 'd', '2', 'd', 'a', '7', '-',
39+
'4', '8', '8', '5', '-', '4', '0', '0', 'f', '-',
40+
'b', 'c', 'd', '4', '-', '6', 'c', 'b', 'd', '5',
41+
'b', '8', 'c', 'f', '6', '2', 'c', '}', '\0'};
42+
43+
int free_fall = 0;
44+
45+
void setup() {
46+
// initialize digital pin LED_BUILTIN as an output.
47+
pinMode(LED_BUILTIN, OUTPUT);
48+
// start serial port at 115200 bps
49+
Serial.begin(115200);
50+
// custom services and characteristics can be added as well
51+
bleSerial.setLocalName("Arduino Primo Core");
52+
// start ble serial
53+
bleSerial.begin();
54+
// set the Android packge name as first and the Windows application id as second
55+
NFC.setAPPmessage(android_package_name, windows_application_id);
56+
// start the NFC module
57+
NFC.start();
58+
// start the core sensors
59+
coresensors.begin();
60+
// enable free fall detection
61+
coresensors.enableFreeFallDetection();
62+
// set up interrupt pin to sensor
63+
attachInterrupt(INT1, FreeFall, RISING);
64+
}
65+
66+
void loop() {
67+
// check interrupt flag
68+
if (free_fall) {
69+
free_fall = 0;
70+
uint8_t status = 0;
71+
// get free fall detection status
72+
coresensors.getStatusFreeFallDetection(status);
73+
if (status)
74+
{
75+
digitalWrite(LED_BUILTIN, HIGH);
76+
delay(100);
77+
digitalWrite(LED_BUILTIN, LOW);
78+
79+
Serial.println("Free Fall Detected!");
80+
bleSerial.println("Free Fall Detected!");
81+
}
82+
}
83+
}
84+
85+
// interrupt service routine
86+
void FreeFall()
87+
{
88+
free_fall = 1;
89+
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
DoubleTap.ino
3+
4+
Written by Jeff Wu ([email protected])
5+
6+
This example for the Arduino Primo Core shows how to use
7+
CoreSensors library.
8+
The example is to show how to find out the 6D orientation
9+
with the Primo Core. Trying to rotate the Primo Core to
10+
change the 6D orientation, when the orientation event is
11+
triggered, the USER LED will blink once.
12+
You can check data using serial or BLE *nRF Toolbox*
13+
uart application. When a device with NFC is near to the
14+
Primo Core with NFC antenna, it will try to open the
15+
Nordic's *nRF Toolbox* or look for the app in the store.
16+
17+
This example code is in the public domain.
18+
19+
*/
20+
21+
#include <CoreSensors.h>
22+
#include <BLEPeripheral.h>
23+
#include <BLESerial.h>
24+
#include <NFC.h>
25+
26+
// interrupt pin
27+
#define INT1 21
28+
29+
// create ble serial instance
30+
BLESerial bleSerial = BLESerial();
31+
32+
// specify the package name for windows and android phone and insert the EOL character at the end '\0'
33+
static const char android_package_name[] = {'n', 'o', '.', 'n', 'o', 'r', 'd', 'i', 'c', 's',
34+
'e', 'm', 'i', '.', 'a', 'n', 'd', 'r', 'o', 'i',
35+
'd', '.', 'n', 'r', 'f', 't', 'o', 'o', 'l', 'b',
36+
'o', 'x','\0'};
37+
38+
static const char windows_application_id[] = {'{', 'e', '1', '2', 'd', '2', 'd', 'a', '7', '-',
39+
'4', '8', '8', '5', '-', '4', '0', '0', 'f', '-',
40+
'b', 'c', 'd', '4', '-', '6', 'c', 'b', 'd', '5',
41+
'b', '8', 'c', 'f', '6', '2', 'c', '}', '\0'};
42+
43+
int orientation = 0;
44+
char report[256];
45+
46+
void sendOrientation(void);
47+
48+
void setup() {
49+
// initialize digital pin LED_BUILTIN as an output.
50+
pinMode(LED_BUILTIN, OUTPUT);
51+
// start serial port at 115200 bps
52+
Serial.begin(115200);
53+
// custom services and characteristics can be added as well
54+
bleSerial.setLocalName("Arduino Primo Core");
55+
// start ble serial
56+
bleSerial.begin();
57+
// set the Android packge name as first and the Windows application id as second
58+
NFC.setAPPmessage(android_package_name, windows_application_id);
59+
// start the NFC module
60+
NFC.start();
61+
// start the core sensors
62+
coresensors.begin();
63+
// enable enable 6D orientation
64+
coresensors.enable6DOrientation();
65+
// set up interrupt pin to sensor
66+
attachInterrupt(INT1, Orientation, RISING);
67+
68+
}
69+
70+
void loop() {
71+
// check interrupt flag
72+
if (orientation)
73+
{
74+
orientation = 0;
75+
uint8_t status = 0;
76+
// get 6D orientation status
77+
coresensors.getStatus6DOrientation(status);
78+
if (status)
79+
{
80+
// print 6D Orientation
81+
sendOrientation();
82+
83+
digitalWrite(LED_BUILTIN, HIGH);
84+
delay(100);
85+
digitalWrite(LED_BUILTIN, LOW);
86+
}
87+
}
88+
}
89+
90+
// interrupt service routine
91+
void Orientation()
92+
{
93+
orientation = 1;
94+
}
95+
96+
void sendOrientation( void )
97+
{
98+
uint8_t xl = 0;
99+
uint8_t xh = 0;
100+
uint8_t yl = 0;
101+
uint8_t yh = 0;
102+
uint8_t zl = 0;
103+
uint8_t zh = 0;
104+
105+
coresensors.get6DOrientationXL(xl);
106+
coresensors.get6DOrientationXH(xh);
107+
coresensors.get6DOrientationYL(yl);
108+
coresensors.get6DOrientationYH(yh);
109+
coresensors.get6DOrientationZL(zl);
110+
coresensors.get6DOrientationZH(zh);
111+
112+
if ( xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 )
113+
{
114+
sprintf( report, "\r\n ________________ " \
115+
"\r\n | | " \
116+
"\r\n | * | " \
117+
"\r\n | | " \
118+
"\r\n | | " \
119+
"\r\n | | " \
120+
"\r\n | | " \
121+
"\r\n |________________| \r\n" );
122+
bleSerial.println("Left");
123+
}
124+
125+
else if ( xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
126+
{
127+
sprintf( report, "\r\n ________________ " \
128+
"\r\n | | " \
129+
"\r\n | * | " \
130+
"\r\n | | " \
131+
"\r\n | | " \
132+
"\r\n | | " \
133+
"\r\n | | " \
134+
"\r\n |________________| \r\n" );
135+
bleSerial.println("Up");
136+
}
137+
138+
else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0 )
139+
{
140+
sprintf( report, "\r\n ________________ " \
141+
"\r\n | | " \
142+
"\r\n | | " \
143+
"\r\n | | " \
144+
"\r\n | | " \
145+
"\r\n | | " \
146+
"\r\n | * | " \
147+
"\r\n |________________| \r\n" );
148+
bleSerial.println("Down");
149+
}
150+
151+
else if ( xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
152+
{
153+
sprintf( report, "\r\n ________________ " \
154+
"\r\n | | " \
155+
"\r\n | | " \
156+
"\r\n | | " \
157+
"\r\n | | " \
158+
"\r\n | | " \
159+
"\r\n | * | " \
160+
"\r\n |________________| \r\n" );
161+
bleSerial.println("Right");
162+
}
163+
164+
else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 )
165+
{
166+
sprintf( report, "\r\n __*_____________ " \
167+
"\r\n |________________| \r\n" );
168+
bleSerial.println("Top");
169+
}
170+
171+
else if ( xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 )
172+
{
173+
sprintf( report, "\r\n ________________ " \
174+
"\r\n |________________| " \
175+
"\r\n * \r\n" );
176+
bleSerial.println("Buttom");
177+
}
178+
179+
else
180+
{
181+
sprintf( report, "None of the 6D orientation axes is set in LSM6DSL - accelerometer.\r\n" );
182+
}
183+
184+
Serial.print(report);
185+
}

0 commit comments

Comments
 (0)