-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Standalone.ino
78 lines (63 loc) · 1.98 KB
/
Standalone.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
/*
* This sketch shows how nicla can be used in standalone mode.
* Without the need for an host, nicla can run sketches that
* are able to configure the bhi sensors and are able to read all
* the bhi sensors data.
*/
#include "Arduino.h"
#include "Arduino_BHY2.h"
SensorXYZ accel(SENSOR_ID_ACC);
SensorXYZ gyro(SENSOR_ID_GYRO);
Sensor temp(SENSOR_ID_TEMP);
Sensor gas(SENSOR_ID_GAS);
SensorQuaternion rotation(SENSOR_ID_RV);
void setup()
{
Serial.begin(115200);
while(!Serial);
BHY2.begin();
accel.begin();
gyro.begin();
temp.begin();
gas.begin();
rotation.begin();
SensorConfig cfg = accel.getConfiguration();
Serial.println(String("range of accel: +/-") + cfg.range + String("g"));
accel.setRange(2); //this sets the range of accel to +/-4g,
cfg = accel.getConfiguration();
Serial.println(String("range of accel: +/-") + cfg.range + String("g"));
cfg = gyro.getConfiguration();
Serial.println(String("range of gyro: +/-") + cfg.range + String("dps"));
gyro.setRange(1000);
cfg = gyro.getConfiguration();
Serial.println(String("range of gyro: +/-") + cfg.range + String("dps"));
}
void loop()
{
static auto printTime = millis();
// Update function should be continuously polled
BHY2.update();
if (millis() - printTime >= 1000) {
printTime = millis();
if(accel.dataAvailable()) {
Serial.println(String("acceleration: ") + accel.toString());
accel.clearDataAvailFlag();
}
if(gyro.dataAvailable()) {
Serial.println(String("gyroscope: ") + gyro.toString());
gyro.clearDataAvailFlag();
}
if (temp.dataAvailable()) {
Serial.println(String("temperature: ") + String(temp.value(),3));
temp.clearDataAvailFlag();
}
if (gas.dataAvailable()) {
Serial.println(String("gas: ") + String(gas.value(),3));
gas.clearDataAvailFlag();
}
if (rotation.dataAvailable()) {
Serial.println(String("rotation: ") + rotation.toString());
rotation.clearDataAvailFlag();
}
}
}