-
Notifications
You must be signed in to change notification settings - Fork 20
/
Nano33BLESensorExample_AllSensors-SerialPlotter.ino
135 lines (121 loc) · 4.98 KB
/
Nano33BLESensorExample_AllSensors-SerialPlotter.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Nano33BLESensorExample_AllSensors-SerialPlotter.ino
Copyright (c) 2020 Dale Giancono. All rights reserved..
This program is an example program showing some of the cababilities of the
Nano33BLESensor Library. In this case it outputs sensor data and from all
of the Arduino Nano 33 BLE Sense's on board sensors via serial in a format
that can be displayed on the Arduino IDE serial plotter.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/*INCLUDES */
/*****************************************************************************/
#include "Arduino.h"
#include "Nano33BLEAccelerometer.h"
#include "Nano33BLEGyroscope.h"
#include "Nano33BLEMagnetic.h"
#include "Nano33BLEProximity.h"
#include "Nano33BLEColour.h"
#include "Nano33BLEGesture.h"
#include "Nano33BLEPressure.h"
#include "Nano33BLETemperature.h"
#include "Nano33BLEMicrophoneRMS.h"
/*****************************************************************************/
/*MACROS */
/*****************************************************************************/
/*****************************************************************************/
/*GLOBAL Data */
/*****************************************************************************/
/*
* Objects which we will store data in each time we read
* the each sensor.
*/
Nano33BLEMagneticData magneticData;
Nano33BLEGyroscopeData gyroscopeData;
Nano33BLEAccelerometerData accelerometerData;
Nano33BLEProximityData proximityData;
Nano33BLEColourData colourData;
Nano33BLEGestureData gestureData;
Nano33BLEPressureData pressureData;
Nano33BLETemperatureData temperatureData;
Nano33BLEMicrophoneRMSData MicrophoneRMSData;
char buffer[300];
/*****************************************************************************/
/*SETUP (Initialisation) */
/*****************************************************************************/
void setup()
{
/* Serial setup for UART debugging */
Serial.begin(115200);
/*
* Initialises the all the sensor, and starts the periodic reading
* of the sensor using a Mbed OS thread. The data is placed in a
* circular buffer and can be read whenever.
*/
Magnetic.begin();
Gyroscope.begin();
Accelerometer.begin();
Proximity.begin();
Colour.begin();
Gesture.begin();
Pressure.begin();
Temperature.begin();
MicrophoneRMS.begin();
delay(500);
}
/*****************************************************************************/
/*LOOP (runtime super loop) */
/*****************************************************************************/
void loop()
{
/*
* This gets all the data from each sensor. Note that each sensor gets data
* at different frequencies. Seeing as this super loop runs every 50mS, not
* all the sensors will have new data. If a sensor does not have new data,
* the old data will just be printed out again. This is a little sloppy, but
* allows the data to be printed in a coherrent way inside serial plotter.
*/
Magnetic.pop(magneticData);
Gyroscope.pop(gyroscopeData);
Accelerometer.pop(accelerometerData);
Proximity.pop(proximityData);
Colour.pop(colourData);
Gesture.pop(gestureData);
Pressure.pop(pressureData);
Temperature.pop(temperatureData);
MicrophoneRMS.pop(MicrophoneRMSData);
snprintf(
buffer,
sizeof(buffer),
"%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%f,%f,%f,%d",
magneticData.x,
magneticData.y,
magneticData.z,
gyroscopeData.x,
gyroscopeData.y,
gyroscopeData.z,
accelerometerData.x,
accelerometerData.y,
accelerometerData.z,
proximityData.proximity,
colourData.r,
colourData.g,
colourData.b,
colourData.c,
gestureData.gesture,
pressureData.barometricPressure,
temperatureData.temperatureCelsius,
temperatureData.humidity,
MicrophoneRMSData.RMSValue);
Serial.println(buffer);
delay(50);
}