SEN0386 accelerometer non-zero X and Y static measurements
Hi, I´m currently trying to build a simple system with the SEN0386 sensor and an Arduino Uno Rev4 Wifi.
My issue is that, using the example code from the "DFRobot_WT62PC" library with a freq of 10Hz, and without moving the sensor, I always get an acceleration value of around 313, sometimes on X axis and sometimes on Y:
Acc 0.05 313.39 9.80
Gyro 0.00 0.00 0.00
Angle 358.92 0.28 331.06
Acc 313.60 313.42 9.80
Gyro 0.00 0.00 0.00
Angle 358.93 0.01 192.99
Z axis acceleration seems to work properly though.
Another issue I´ve found is that whenever I move the sensor, gyroscope values suddenly go up to around 4000:
Acc 313.59 313.43 9.81
Gyro 3999.76 3999.94 0.00
Angle 354.36 359.17 74.60
Acc 305.03 309.87 3.26
Gyro 3.60 11.72 3985.05
Angle 312.79 59.04 2.30
Maybe I don´t understand how the sensor configuration workd, but I can´t seem to find a way to work it out.
Here´s the code I´m using:
/*!
* @brief Set the frequency of data output by the sensor, read the acceleration,
* @n angular velocity, and angle of X, Y, and Z axes.
* @n Experimental phenomenon: when the sensor starts, it outputs data at the set frequency and the data will be displayed on serial monitor.
* @url https://github.com/DFRobot/DFRobot_WT61PC
*/
#include <DFRobot_WT61PC.h>
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/9, /*tx =*/10);
#define FPSerial softSerial
#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port
#include <SoftwareSerial.h>
SoftwareSerial softSerial(/*rx =*/10, /*tx =*/11);
#define FPSerial softSerial
#else
#define FPSerial Serial1
#endif
DFRobot_WT61PC sensor(&FPSerial);
void setup()
{
//Use Serial as debugging serial port
Serial.begin(115200);
#if (defined ESP32)
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
#else
FPSerial.begin(9600);
#endif
/**
* @brief Revise the data output frequncy of sensor
* @param frequency - FREQUENCY_0_1HZ for 0.1Hz, FREQUENCY_0_5HZ for 0.5Hz, FREQUENCY_1HZ for 1Hz,
* @n FREQUENCY_2HZ for 2Hz, FREQUENCY_5HZ for 5Hz, FREQUENCY_10HZ for 10Hz,
* @n FREQUENCY_20HZ for 20Hz, FREQUENCY_50HZ for 50Hz, FREQUENCY_100HZ for 100Hz,
* @n FREQUENCY_125HZ for 125Hz, FREQUENCY_200HZ for 200Hz.
*/
sensor.modifyFrequency(FREQUENCY_10HZ);
}
void loop()
{
if (sensor.available()) {
Serial.print("Acc\t"); Serial.print(sensor.Acc.X); Serial.print("\t");
Serial.print(sensor.Acc.Y); Serial.print("\t"); Serial.println(sensor.Acc.Z); //acceleration information of X,Y,Z
Serial.print("Gyro\t"); Serial.print(sensor.Gyro.X); Serial.print("\t");
Serial.print(sensor.Gyro.Y); Serial.print("\t"); Serial.println(sensor.Gyro.Z); //angular velocity information of X,Y,Z
Serial.print("Angle\t"); Serial.print(sensor.Angle.X); Serial.print("\t");
Serial.print(sensor.Angle.Y); Serial.print("\t"); Serial.println(sensor.Angle.Z); //angle information of X, Y, Z
Serial.println();
}
}
Solved by changing the function “getAcc()” in the library from:
Acc.X = ((int16_t)(buf[WT61PC_XH] << 8) | buf[WT61PC_XL]) / 32768.000 * 16.000 * 9.8;
To:
Acc.X = ((buf[WT61PC_XH] << 8) | buf[WT61PC_XL]) / 32768.000 * 16.000 * 9.8;
Same fix for the other two axes, and for “getGyro” and "getAngle".
salva