2024-04-24 12:02 AM - last edited on 2025-05-07 5:26 AM by Andrew Neil
Hello STM32 community,
I'm relatively new to STM32 development and I'm currently working with the I3G4250D Gyro Sensor on the STM32F411e-Discovery board. I've been using the stm32f411e_discovery_gyroscope.c file provided by STM32Cube to interface with the sensor.
I've managed to retrieve data from the sensor using the provided code snippet:
BSP_GYRO_GetXYZ(Buffer2);
Xval = Buffer2[0];
Yval = Buffer2[1];
Zval = Buffer2[2];
However, the output I'm getting seems to be raw data, and I'm not quite sure how to interpret it correctly. My understanding is that these values represent the raw sensor readings, but I'm unsure how to convert them into meaningful X, Y, and Z values.
Could someone please provide guidance on how to properly interpret and convert these raw values into meaningful data? Additionally, if there are any specific calibration steps or formulas that need to be applied to obtain accurate results, I would greatly appreciate any insights on that as well.
Thank you in advance for your help!
Solved! Go to Solution.
2024-05-02 1:17 AM
Hi @Duc ,
To have data in mdps you need to multiply the raw data in LSB by the sensitivity reported in the datasheet according to your FS setting:
In addition, you could also look at our PID examples.
2024-05-02 1:17 AM
Hi @Duc ,
To have data in mdps you need to multiply the raw data in LSB by the sensitivity reported in the datasheet according to your FS setting:
In addition, you could also look at our PID examples.
2025-05-07 5:12 AM
I got the same problem. In addition, I found that the output values keep varying even if the system is at rest (not moving at all). The output values are not zero
2025-05-07 5:29 AM
@Kushal_Es wrote:I got the same problem.
So did you do as @Federica Bossi said to fix that?
@Kushal_Es wrote:I found that the output values keep varying even if the system is at rest (not moving at all). The output values are not zero
So what values are you getting?
All measurements are subject to noise and offsets...
Do the values change when the system is moving?
2025-05-07 6:05 AM
Hi there,
I believe your setup may not be configured correctly, and the investigation might be incomplete. If you're using the same hardware as I am, you should be able to obtain the correct values with the proper settings.
Feel free to refer to my test code at: refer_code.
2025-05-07 6:45 AM
As I'm using BSP drivers available in the BSP folder of STM32Cube, In the I3G4250D.c file the function is already defined and the sensitivity is being multiplied in this function already (as @Federica Bossi said):
void I3G4250D_ReadXYZAngRate(float *pfData)
{
uint8_t tmpbuffer[6] = {0};
int16_t RawData[3] = {0};
uint8_t tmpreg = 0;
float sensitivity = 0;
int i = 0;
GYRO_IO_Read(&tmpreg, I3G4250D_CTRL_REG4_ADDR, 1);
GYRO_IO_Read(tmpbuffer, I3G4250D_OUT_X_L_ADDR, 6);
/* check in the control register 4 the data alignment (Big Endian or Little Endian)*/
if (!(tmpreg & I3G4250D_BLE_MSB))
{
for (i = 0; i < 3; i++)
{
RawData[i] = (int16_t)(((uint16_t)tmpbuffer[2 * i + 1] << 8) + tmpbuffer[2 * i]);
}
}
else
{
for (i = 0; i < 3; i++)
{
RawData[i] = (int16_t)(((uint16_t)tmpbuffer[2 * i] << 8) + tmpbuffer[2 * i + 1]);
}
}
/* Switch the sensitivity value set in the CRTL4 */
switch (tmpreg & I3G4250D_FULLSCALE_SELECTION)
{
case I3G4250D_FULLSCALE_245:
sensitivity = I3G4250D_SENSITIVITY_245DPS;
break;
case I3G4250D_FULLSCALE_500:
sensitivity = I3G4250D_SENSITIVITY_500DPS;
break;
case I3G4250D_FULLSCALE_2000:
sensitivity = I3G4250D_SENSITIVITY_2000DPS;
break;
}
/* Multiplied by sensitivity */
for (i = 0; i < 3; i++)
{
pfData[i] = (float)(RawData[i] * sensitivity);
}
}
2025-05-07 6:46 AM
I've attached a video of the values I'm getting when the system is stationery:
2025-05-07 6:49 AM
Here is the video of values I'm getting if I move the system around z axis
2025-05-07 6:00 PM
Which board or hardware are you using?
2025-05-07 10:59 PM
I'm using STM32F411E - DISCO board.
Thanks for providing the refer code!
I tried using it but using that code, its giving constant values at outputs even while moving.