Software/Arduino Core/Sensors and Audio

On-board Sensors

The LSM6DSL inertial unit and MMC5603NJ magnetometer on the Neuro N6, the VL53L1CB time of flight sensor on the camera modules, their libraries, and streaming readings to Neuro Studio.

intermediate3 min read

Three sensors share the I2C1 bus. The inertial unit and the magnetometer are on the Neuro N6 board and are present with every module. The time of flight sensor is on the Neuro Vision OV5640, TFT and STCam modules and their -W variants; the Thermal module does not have one. Each sensor has a bundled library with the same structure: an object is declared, begin() initialises it, a read method returns a value, and sendNS() streams the reading to Neuro Studio.

SensorPartLocationMeasuresLibraryAddress
Inertial unitST LSM6DSLNeuro N6Acceleration, angular rate, temperatureLSM6DSL0x6A or 0x6B
MagnetometerMEMSIC MMC5603NJNeuro N6Magnetic field on three axes, temperatureMMC5603NJ0x30
Time of flightST VL53L1CBOV5640, TFT, STCam modulesDistance, as a 4x4 grid of zonesVL53L1CB0x29

Inertial unit

cpp
#include <Wire.h>
#include <LSM6DSL_Arduino.h>
#include <PostProcess.h>     // for sendNS()

LSM6DSL imu;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  if (!imu.begin()) Serial.println("LSM6DSL not found");
}

void loop() {
  imuVec3 a = imu.readAccel();   // g
  imuVec3 g = imu.readGyro();    // degrees per second
  float   t = imu.readTemp();    // degrees Celsius
  imu.sendNS();
  delay(200);
}

begin() probes both possible addresses. whoami() returns the WHO_AM_I register. With the board at rest, the axis pointing down reads approximately +1 g.

Magnetometer

cpp
#include <Wire.h>
#include <MMC5603NJ.h>
#include <PostProcess.h>

MMC5603NJ mag;

void loop() {
  magSensorFloatXYZ m = mag.getMag();
  float heading = atan2(m.y, m.x) * 57.29578f;
  if (heading < 0.0f) heading += 360.0f;
  float t = mag.getTemp();
  mag.sendNS();
  delay(200);
}

getMag() triggers a single-shot measurement on each call. setContinuousMode(hz) selects continuous measurement. A heading derived from the horizontal components is uncalibrated for nearby ferrous material and magnets. getTemp() returns a sentinel of approximately 26.6 degrees if the measurement-done flag never asserts, so a faulty sensor does not block the sketch.

The MMC5603NJ library is GPL-3.0 licensed. See Licensing.

Time of flight

cpp
#include <Wire.h>
#include <VL53L1CB_Arduino.h>
#include <PostProcess.h>

VL53L1CB tof;

void loop() {
  tofFrame f = tof.read();       // f.mm[4][4], millimetres, 0 = no target
  tof.sendNS();
  delay(100);
}

The VL53L1CB ranges one region of interest at a time. Each read() or sendNS() call advances the 4x4 sweep, and a zone completes when its measurement of about 60 ms is ready, so a full grid refreshes over roughly one second. whoami() returns the 16-bit device ID 0xEACC and may be called before begin().

The ST driver owns the I2C handle directly; the library's address and Wire arguments are ignored.

Streaming to Neuro Studio

sendNS() publishes the reading to a metadata slot. PostProcess.h is required because the metadata builders live there. The core delivers the slots in either of two ways:

  • With a camera, every reading is attached to the metadata of each video frame.
  • Without a camera, the core emits the slots as metadata-only frames.

Neuro Studio shows readings under Magnetometer, IMU and ToF entries in its side panels. Each panel has a Numbers page with live values and a Graph page with rolling line charts. The IMU graph shows acceleration and angular rate separately. Charts have labelled axes and an automatic or manual y scale. A panel whose sensor is not streaming shows a "No data" message, and panels reset on disconnect.

Bus sharing

The sensors share I2C1 with the camera. Per-transaction locking is applied by every library. A publisher that must not stall behind a long bus claim uses n6_i2c_trylock():

cpp
if (n6_i2c_trylock()) {
  imu.sendNS();
  mag.sendNS();
  n6_i2c_unlock();
}

See I2C with Wire.

Combined example

The GlobalShutterVision example, under File > Examples > VD66GY, streams the VD66GY at 1.4 MP and 45 fps with YOLOv8 segmentation while publishing all three sensors on every frame. A sensor that is not fitted, such as the time of flight sensor on the Thermal module, fails begin() and is skipped.

Power

The power save library places the IMU and magnetometer in their lowest power states with imuSleep() and magSleep(). See Low Power.