The device I am using is Arduino Nano 33 BLE Sense. It has the LSM9DS1 sensor. The main library is LSM9DS1.cpp. I am reading the data via pre-defined functions from Arduino's library.. Here is how I read the data. This one generates data with 2 decimal points:
if(IMU.gyroscopeAvailable()){
IMU.readGyroscope(x, y, z);
gyroData.values[0] = x; // 0.11
gyroData.values[1] = y; // 1.13
gyroData.values[2] = z; // -1.13
gyroData.updated = true;
}
This is how they generate in the source code:
int LSM9DS1Class::readGyroscope(float& x, float& y, float& z)
{
int16_t data[3];
if (!readRegisters(LSM9DS1_ADDRESS, LSM9DS1_OUT_X_G, (uint8_t*)data, sizeof(data))) {
x = NAN;
y = NAN;
z = NAN;
return 0;
}
x = data[0] * 2000.0 / 32768.0;
y = data[1] * 2000.0 / 32768.0;
z = data[2] * 2000.0 / 32768.0;
return 1;
}
Honestly, I don't know much to verify how accurate is that. I am sending this data over BLE where we cannot send multiple sensor float data (we cannot send float array). Hence I need to convert those to byte first then reconvert to float.
When I add the warn there I did not get any errors. This is the function node:
for(const key in msg.payload){
node.warn(`key: ${key}, value: ${msg.payload[key]}`);
msg.payload[key] = Number(msg.payload[key]).toFixed(3);
}
return msg;
This is from the Node-RED log which keeps repeating:
29 Nov 16:00:49 - [warn] [function:rounder] key: gyroX, value: -0.244140625
29 Nov 16:00:49 - [warn] [function:rounder] key: gyroY, value: -2.197265625
29 Nov 16:00:49 - [warn] [function:rounder] key: gyroZ, value: 0.1220703125
29 Nov 16:00:49 - [warn] [function:rounder] key: accX, value: -0.0068359375
29 Nov 16:00:49 - [warn] [function:rounder] key: accY, value: -0.0093994140625
29 Nov 16:00:49 - [warn] [function:rounder] key: accZ, value: 1.01953125
29 Nov 16:00:49 - [warn] [function:rounder] key: magX, value: 3.271484375
29 Nov 16:00:49 - [warn] [function:rounder] key: magY, value: 21.435546875
29 Nov 16:00:49 - [warn] [function:rounder] key: magZ, value: 46.6552734375
I am very confused tbh.