-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand CI coverage to four examples from the Nicla Sense ME User Manu…
…al (#139) * add ActivityRecognition sketch * add magnetometer example * Add three examples * Spelling corrections * Update Arduino_BHY2/examples/Pressure/Pressure.ino Co-authored-by: Christopher Méndez <[email protected]> --------- Co-authored-by: Christopher Méndez <[email protected]>
- Loading branch information
Showing
4 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* This example shows how to use the access the IMU data and plot it in real time. | ||
* | ||
* Every 50 milliseconds, this sketch will send the x,y and z accelerometer (SensorID 4) and | ||
* gyroscope (SensorID 22) values over serial from the BHI260AP six axis IMU. | ||
* These six values are visually displayed with the Serial Plotter in the Arduino IDE. | ||
* | ||
* Instructions: | ||
* 1. Upload this sketch to your Nicla Sense ME board. | ||
* 2. Open the Serial Plotter at a baud rate of 115200. | ||
* 3. The three axis values for both the accelerometer and gyroscope will be printed to the Serial Plotter. | ||
* 4. Optionally, you can change the visibility of each data by clicking on the legend. | ||
* | ||
* Initial author: @mcmchris | ||
*/ | ||
|
||
#include "Arduino_BHY2.h" | ||
|
||
SensorXYZ accel(SENSOR_ID_ACC); | ||
SensorXYZ gyro(SENSOR_ID_GYRO); | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
BHY2.begin(); | ||
accel.begin(); | ||
gyro.begin(); | ||
} | ||
|
||
void loop() { | ||
static auto printTime = millis(); | ||
|
||
// Update function should be continuously polled | ||
BHY2.update(); | ||
|
||
if (millis() - printTime >= 50) { | ||
printTime = millis(); | ||
|
||
// Accelerometer values | ||
Serial.print("acc_X:"); | ||
Serial.print(accel.x()); | ||
Serial.print(","); | ||
Serial.print("acc_Y:"); | ||
Serial.print(accel.y()); | ||
Serial.print(","); | ||
Serial.print("acc_Z:"); | ||
Serial.print(accel.z()); | ||
Serial.print(","); | ||
|
||
// Gyroscope values | ||
Serial.print("gyro_X:"); | ||
Serial.print(gyro.x()); | ||
Serial.print(","); | ||
Serial.print("gyro_Y:"); | ||
Serial.print(gyro.y()); | ||
Serial.print(","); | ||
Serial.print("gyro_Z:"); | ||
Serial.println(gyro.z()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Arduino_BHY2/examples/ActivityRecognition/ActivityRecognition.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* This example shows how to use the Nicla Sense ME library to detect activity and send it over serial. | ||
* | ||
* Every 1 second, this sketch will send the latest activity detected via the BHI260AP sensor to the serial port. | ||
* Without any additional training, it is possible to detect Still, Walking, Running and Tilting activities | ||
* A full description of supported activities is available in Table 93 of the BHI260AP datasheet. | ||
* | ||
* Instructions: | ||
* 1. Upload this sketch to your Nicla Sense ME board. | ||
* 2. Open the Serial Monitor at a baud rate of 115200. | ||
* 3. Observe the detected activity, by moving the Nicla Sense ME board. | ||
* | ||
* Initial author: @mcmchris | ||
*/ | ||
|
||
#include "Arduino_BHY2.h" | ||
|
||
SensorActivity active(SENSOR_ID_AR); | ||
|
||
unsigned long previousMillis = 0; // will store last time the sensor was updated | ||
const long interval = 1000; | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
BHY2.begin(); | ||
active.begin(); | ||
} | ||
|
||
void loop() { | ||
BHY2.update(); | ||
unsigned long currentMillis = millis(); | ||
if (currentMillis - previousMillis >= interval) { | ||
previousMillis = currentMillis; | ||
Serial.println(String("Activity info: ") + active.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* This example shows how to use the access the magnetometer data and send it over serial. | ||
* | ||
* Every 1 second, this sketch will send the heading of the magnetometer over serial. | ||
* by calculating the arctangent between the x and y axis and multiplied in a conversion | ||
* factor to convert the headings from radians to degrees. | ||
* | ||
* Instructions: | ||
* 1. Upload this sketch to your Nicla Sense ME board. | ||
* 2. Open the Serial Monitor at a baud rate of 115200. | ||
* 3. The heading of the magnetometer will be printed to the serial monitor. | ||
* | ||
* Initial author: @mcmchris | ||
*/ | ||
|
||
#include "Arduino_BHY2.h" | ||
#include "Math.h" | ||
|
||
SensorXYZ magnetometer(SENSOR_ID_MAG); | ||
|
||
float heading = 0; | ||
unsigned long previousMillis = 0; // will store last time the sensor was updated | ||
const long interval = 1000; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
BHY2.begin(); | ||
magnetometer.begin(); | ||
} | ||
|
||
void loop() { | ||
BHY2.update(); | ||
unsigned long currentMillis = millis(); | ||
if (currentMillis - previousMillis >= interval) { | ||
previousMillis = currentMillis; | ||
heading = round(atan2(magnetometer.x(), magnetometer.y()) * 180.0 / PI); | ||
Serial.println(String(heading) + "º"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This example shows how to use the access the pressure data and send it over serial. | ||
* | ||
* Every 1 second, this sketch will send the pressure in hPa over serial. | ||
* SensorID 129 (SENSOR_ID_BARO) is read with the Sensor class from the BMP390. | ||
* | ||
* Instructions: | ||
* 1. Upload this sketch to your Nicla Sense ME board. | ||
* 2. Open the Serial Monitor at a baud rate of 115200. | ||
* 3. The pressure will be printed to the serial monitor. | ||
* | ||
* Initial author: @mcmchris | ||
*/ | ||
|
||
#include "Arduino_BHY2.h" | ||
|
||
|
||
unsigned long previousMillis = 0; // will store last time the sensor was updated | ||
const long interval = 1000; | ||
|
||
Sensor pressure(SENSOR_ID_BARO); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
BHY2.begin(); | ||
pressure.begin(); | ||
} | ||
|
||
void loop() { | ||
BHY2.update(); | ||
unsigned long currentMillis = millis(); | ||
if (currentMillis - previousMillis >= interval) { | ||
previousMillis = currentMillis; | ||
Serial.println(String(pressure.value()) + " hPa"); | ||
} | ||
} |