logging_csv_usb.ino

Arduino Nicla Sense ME · File : logging_csv_usb.ino · Language : Arduino · Use case : Journaliser tous les capteurs en CSV série

The Sense ME USB serial bridge (SAMD11) acts as a logger cable: acceleration, gyro, pressure and temperature stream as timestamped CSV at 1 Hz. Paste into a spreadsheet and the curve is drawn — the board simplest data acquisition.

Hardware

An Arduino Nicla Sense ME (nRF52832, BLE only) with Bosch BHI260AP hub, BMM150, BMP390, BME688 sensors, RGB LED on an I2C driver and LiPo charger. The board linked to a PC over USB (the connector rides the SAMD11 bridge, the nRF52832 has no native USB). A serial terminal or spreadsheet open.

Wiring

No wiring. For a PC-free version, the 2 MB on-board flash holds the journal (StandaloneFlashStorage example in the BHY2 library).

How it works

BHY2.update pumps the hub, accel/gyro.update refresh the latest values, static accessors give pressure and temperature. The CSV header up front eases spreadsheet import.

Running it

Programmed from the Arduino IDE (ArduinoCore-mbed); Arduino_BHY2 and Nicla_System libraries; USB through a serial bridge.

Variants

Move to the internal flash for autonomy, send the CSV over BLE to a plotting app, or add BME688 IAQ columns for an air-quality + activity report.

logging_csv_usb.ino

// Enregistreur multi-capteurs : une ligne CSV par seconde sur
// l'USB (pont série SAMD11). Copier-coller la sortie dans un
// tableur, ou la logger avec un enregistreur de terminal (PuTTY).

#include "Arduino_BHY2.h"

SensorAccel accel(0);
SensorGyro gyro(0);

void setup() {
  Serial.begin(115200);
  BHY2.begin();
  accel.begin();
  gyro.begin();
  BHY2.update();
  Serial.println("t_ms,ax,ay,az,gx,gy,gz,p_hPa,t_C");
}

void loop() {
  BHY2.update();

  static unsigned long t = 0;
  if (millis() - t >= 1000) {
    t = millis();
    accel.update();
    gyro.update();
    Serial.print(t);
    Serial.print(","); Serial.print(accel.x(), 3);
    Serial.print(","); Serial.print(accel.y(), 3);
    Serial.print(","); Serial.print(accel.z(), 3);
    Serial.print(","); Serial.print(gyro.x(), 2);
    Serial.print(","); Serial.print(gyro.y(), 2);
    Serial.print(","); Serial.print(gyro.z(), 2);
    Serial.print(","); Serial.print(BHY2.readPressure(), 2);
    Serial.print(","); Serial.println(BHY2.readTemperature(), 2);
  }
  delay(2);
}

← Back to the board