Hi again.
I am just copying the nicla sense ingestion code here from EI with some modifications.
Apologies for the first message
Regards
#define SAMPLE_ACCELEROMETER
#define SAMPLE_GYROSCOPE
#define SAMPLE_ORIENTATION
// #define SAMPLE_ENVIRONMENTAL
// #define SAMPLE_ROTATION_VECTOR
#define SAMPLE_MAGNETOMETER
/**
* Configure the sample frequency. This is the frequency used to send the data
* to the studio regardless of the frequency used to sample the data from the
* sensor. This differs per sensors, and can be modified in the API of the sensor
*/
#define FREQUENCY_HZ 5
/* Include ----------------------------------------------------------------- */
#include "Arduino.h" // not needed ?
#include "Arduino_BHY2.h"
#include "Nicla_System.h" //not needed ?
/* Constants --------------------------------------------------------------- */
#if (FREQUENCY_HZ <= 0)
#error "FREQUENCY_HZ should have a value greater dan 0"
#endif
#define INTERVAL_MS (1000 / FREQUENCY_HZ)
#define CONVERT_G_TO_MS2 9.80665f
/* Forward declerations ---------------------------------------------------- */
void ei_printf(const char *format, ...);
/* Private variables ------------------------------------------------------- */
static unsigned long last_interval_ms = 0;
#ifdef SAMPLE_ACCELEROMETER
SensorXYZ accel(SENSOR_ID_ACC);
#endif
#ifdef SAMPLE_GYROSCOPE
SensorXYZ gyro(SENSOR_ID_GYRO);
#endif
#ifdef SAMPLE_ORIENTATION
SensorOrientation orientation(SENSOR_ID_ORI);
#endif
#ifdef SAMPLE_MAGNETOMETER
SensorXYZ mag(SENSOR_ID_MAG);
#endif
#ifdef SAMPLE_ENVIRONMENTAL
Sensor temp(SENSOR_ID_TEMP);
Sensor baro(SENSOR_ID_BARO);
Sensor hum(SENSOR_ID_HUM);
Sensor gas(SENSOR_ID_GAS);
#endif
void setup() {
/* Init serial */
Serial.begin(115200);
Serial.println("Edge Impulse sensor data ingestion\r\n");
/* Init & start sensors */
BHY2.begin(NICLA_I2C);
#ifdef SAMPLE_ACCELEROMETER
accel.begin();
#endif
#ifdef SAMPLE_GYROSCOPE
gyro.begin();
#endif
#ifdef SAMPLE_ORIENTATION
orientation.begin();
#endif
#ifdef SAMPLE_ROTATION_VECTOR
rotation.begin();
#endif
#ifdef SAMPLE_MAGNETOMETER
mag.begin();
#endif
#ifdef SAMPLE_ENVIRONMENTAL
temp.begin();
baro.begin();
hum.begin();
gas.begin();
#endif
}
void loop() {
BHY2.update();
delay(INTERVAL_MS);
#ifdef SAMPLE_ACCELEROMETER
ei_printf("%f, %f, %f,", (accel.x() * 8.0 / 32768.0) * CONVERT_G_TO_MS2, (accel.y() * 8.0 / 32768.0) * CONVERT_G_TO_MS2, (accel.z() * 8.0 / 32768.0) * CONVERT_G_TO_MS2);
#endif
#ifdef SAMPLE_GYROSCOPE
ei_printf("%f, %f, %f,", (gyro.x() * 8.0 / 32768.0) * CONVERT_G_TO_MS2, (gyro.y() * 8.0 / 32768.0) * CONVERT_G_TO_MS2, (gyro.z() * 8.0 / 32768.0) * CONVERT_G_TO_MS2);
#endif
#ifdef SAMPLE_ORIENTATION
ei_printf("%f, %f, %f,", orientation.heading(), orientation.pitch(), orientation.roll());
#endif
#ifdef SAMPLE_MAGNETOMETER
ei_printf("%f, %f, %f,", mag.x(), mag.y(), mag.z());
#endif
#ifdef SAMPLE_ROTATION_VECTOR
ei_printf("%f, %f, %f, %f,", rotation.x(), rotation.y(), rotation.z(), rotation.w());
#endif
#ifdef SAMPLE_ENVIRONMENTAL
ei_printf("%.2f, %.2f, %.2f, %.2f,", temp.value(), baro.value(), hum.value(), gas.value());
#endif
ei_printf("\r\n");
}
/**
* @brief Printf function uses vsnprintf and output using Arduino Serial
*
* @param[in] format Variable argument list
*/
void ei_printf(const char *format, ...) {
static char print_buf[1024] = { 0 };
va_list args;
va_start(args, format);
int r = vsnprintf(print_buf, sizeof(print_buf), format, args);
va_end(args);
if (r > 0) {
Serial.write(print_buf);
}
}