Sending Output Data

Sensor Data Output Format

The SensiML toolkit expect data to be sent as 16-bit signed integers. This is usually the raw output format for most ADCs and sensors.

The data coming out of the device should also match the order described in the device description.

As with the JSON description, the following code from the GitHub repository for the Nano33 reads the IMU data in the order given, based on configuration at compile-time.

int update_imu(int startIndex)
{
    int sensorRawIndex = startIndex;
    if (ENABLE_ACCEL)
    {
        IMU.readRawAccelInt16(sensorRawData[sensorRawIndex++],
                            sensorRawData[sensorRawIndex++],
                            sensorRawData[sensorRawIndex++]);
    }

    if (ENABLE_GYRO)
    {
        IMU.readRawGyroInt16(sensorRawData[sensorRawIndex++],
                            sensorRawData[sensorRawIndex++],
                            sensorRawData[sensorRawIndex++]);
    }

    if (ENABLE_MAG)
    {
        IMU.readRawMagnetInt16(sensorRawData[sensorRawIndex++],
                            sensorRawData[sensorRawIndex++],
                            sensorRawData[sensorRawIndex++]);
    }
    return sensorRawIndex;
}

Sending Data over Serial

Data should be sent over serial after a “connect” string is received while sending the JSON description. The serial port does not need to be read again on the device after this, until a system reset.

On a serial port, data is output in chunks, depending on the sensor being used. For IMU data, multiple sensor readings are sent per chunk of data. For audio and higher sample rate data, the data is directly written out as it is sampled.

Samples Per Packet

Data should be sent in chunks of data, using the specified number of samples per packet used in the device description. This can be done by filling a buffer until the number of samples is reached. In the case of audio, a single chunk of data is used as the number of samples.