X-NUCLEO-IKS01A3 sensor test based on STM32F401RE development board 3D acceleration LIS2DW12 sensor test...
[Copy link]
Today I tested the 3D sensor using the LIS2DW12_6Dorientation example. At first I thought this example was for testing acceleration, but after actual operation I realized it was for testing the sensor placement direction, namely horizontal (ZH), horizontal (ZL), upright (YL), inverted (YH), left side (XL), right side (XH), a total of 6 directions.
I still added the LCD driver, added the include path and other "conventional" practices, and then added the LCD display code in the Send_Orientation() function. The code is as follows:
static void Send_Orientation(void)
{
uint8_t xl = 0;
uint8_t xh = 0;
uint8_t yl = 0;
uint8_t yh = 0;
uint8_t zl = 0;
uint8_t zh = 0;
if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_XL(IKS01A3_LIS2DW12_0, &xl) != BSP_ERROR_NONE)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation XL axis from LIS2DW12 - accelerometer.\r\n");
printf("%s", dataOut);
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"XL 轴数据错误");
return;
}
if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_XH(IKS01A3_LIS2DW12_0, &xh) != BSP_ERROR_NONE)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation XH axis from LIS2DW12 - accelerometer.\r\n");
printf("%s", dataOut);
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"XH 轴数据错误");
return;
}
if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_YL(IKS01A3_LIS2DW12_0, &yl) != BSP_ERROR_NONE)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation YL axis from LIS2DW12 - accelerometer.\r\n");
printf("%s", dataOut);
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"YL 轴数据错误");
return;
}
if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_YH(IKS01A3_LIS2DW12_0, &yh) != BSP_ERROR_NONE)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation YH axis from LIS2DW12 - accelerometer.\r\n");
printf("%s", dataOut);
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"YH 轴数据错误");
return;
}
if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_ZL(IKS01A3_LIS2DW12_0, &zl) != BSP_ERROR_NONE)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation ZL axis from LIS2DW12 - accelerometer.\r\n");
printf("%s", dataOut);
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"ZL 轴数据错误");
return;
}
if (IKS01A3_MOTION_SENSOR_Get_6D_Orientation_ZH(IKS01A3_LIS2DW12_0, &zh) != BSP_ERROR_NONE)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "Error getting 6D orientation ZH axis from LIS2DW12 - accelerometer.\r\n");
printf("%s", dataOut);
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"ZH 轴数据错误");
return;
}
if (xl == 1U && yl == 0U && zl == 0U && xh == 0U && yh == 0U && zh == 0U)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n ________________ " \
"\r\n | | " \
"\r\n | * | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n |________________| \r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"运动方向: XL");
}
else if (xl == 0U && yl == 1U && zl == 0U && xh == 0U && yh == 0U && zh == 0U)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n ________________ " \
"\r\n | | " \
"\r\n | * | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n |________________| \r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"运动方向: YL");
}
else if (xl == 0U && yl == 0U && zl == 0U && xh == 0U && yh == 1U && zh == 0U)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n ________________ " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | * | " \
"\r\n |________________| \r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"运动方向: YH");
}
else if (xl == 0U && yl == 0U && zl == 0U && xh == 1U && yh == 0U && zh == 0U)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n ________________ " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | | " \
"\r\n | * | " \
"\r\n |________________| \r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"运动方向: XH");
}
else if (xl == 0U && yl == 0U && zl == 0U && xh == 0U && yh == 0U && zh == 1U)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n __*_____________ " \
"\r\n |________________| \r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"运动方向: ZH");
}
else if (xl == 0U && yl == 0U && zl == 1U && xh == 0U && yh == 0U && zh == 0U)
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "\r\n ________________ " \
"\r\n |________________| " \
"\r\n * \r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"运动方向: ZL");
}
else
{
(void)snprintf(dataOut, MAX_BUF_SIZE, "None of the 6D orientation axes is set in LIS2DW12 - accelerometer.\r\n");
LCD_clear_line(4);
LCD_clear_line(5);
LCD_write_BG(0,4,(uint8_t *)"无运动");
}
printf("%s", dataOut);
}
The test results after compilation and downloading are as follows:
1. Photos taken during testing:
2. Data received by the serial port assistant:
3. Flat (ZH) sensor:
4. Horizontal (ZL) sensor:
5. Upright (YL) sensor:
6. Inverted (YH) sensor:
7. Left side (XL) sensor:
8. Right side stand (XH) sensor:
Note: The "movement direction" shown on the LCD display should actually be the placement direction.
This content is originally created by EEWORLD forum user hujj . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source
|