基于STM32F401RE开发板的X-NUCLEO-IKS01A3传感器测试之三3D加速度LIS2DW12传感器测...
[复制链接]
今天测试了3D传感器的测试,使用的是LIS2DW12_6Dorientation范例,开始我还以为这个范例是测试加速度的,经过实际操作后才知道是测试传感器放置方向的,即平放(ZH)、卧放(ZL)、正立(YL)、倒立(YH)、左侧立(XL)、右侧立(XH),共6个方向。
依旧是添加LCD驱动程序,添加包含路径等“常规”做法,然后在Send_Orientation()函数中添加LCD的显示代码,代码如下:
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);
}
编译下载后的测试情况如下:
1、测试时的照片:
2、串口助手接收到的数据:
3、平放(ZH)传感器:
4、卧放(ZL)传感器:
5、正立(YL)传感器:
6、倒立(YH)传感器:
7、左侧立(XL)传感器:
8、右侧立(XH)传感器:
注:LCD显示屏中显示的“运动方向”实际上应该为放置方向。
此内容由EEWORLD论坛网友hujj原创,如需转载或用于商业用途需征得作者同意并注明出处
|