|
基于stm32的电子计步器,使用MPU6050角速度传感器检测角速度和温度,使用的官方库检测位置信息。分享出来供同学们使用,传感器数据采集板和主控板的完整源码pcb文件都有提供,可以直接使用嘉立创商城制版。欢迎大家下载.
- #include "stm32f10x.h" // Device header
- #include "Delay.h"
- #include "OLED.h"
- #include "MPU6050.h"
- #include "inv_mpu.h"
- #include "inv_mpu_dmp_motion_driver.h"
- #include "TIM.h"
- #include "MyRTC.h"
- //float Pitch,Roll,Yaw; //俯仰角默认跟中值一样,翻滚角,偏航角
- //int16_t ax,ay,az,gx,gy,gz; //加速度,陀螺仪角速度
- //u8 MPU_Get_Gyroscope(short *gx,short *gy,short *gz);
- //u8 MPU_Get_Accelerometer(short *ax,short *ay,short *az);
- //int temp;
- //short MPU_Get_Temperature(void);
- u8 mpu6050InitFlag = 1;
- int temp;
- unsigned long int count = 0;
- unsigned long int lastcount = 0;
- int step;
- int main(void)
- {
- OLED_Init();
- OLED_ShowString(2, 2, "Starting....");
- MyRTC_Init(); //RTC初始化
- MPU6050_Init();
- MPU6050_DMP_Init();
- // OLED_ShowString(6, 1, "Mode1");
-
- while(mpu6050InitFlag)
- {
- mpu6050InitFlag = MPU6050_DMP_Init();
- }
-
-
- OLED_ShowString(2, 1, "Time:");
- OLED_ShowString(2, 8, ":");
- OLED_ShowString(2, 11, ":");
- OLED_ShowString(3, 8, ".");
- OLED_ShowString(2, 8, ":");
- OLED_ShowString(2, 11, ":");
- OLED_ShowString(3, 1, "Temp:");
- OLED_ShowString(4, 1, "Step:");
- OLED_ShowString(3, 8, ".");
-
-
-
-
-
-
- // TIM3_Int_Iint(9999 , 7199);//定时器3的1秒中断初始化
- while (1)
- {
- // MPU6050_DMP_Get_Data(&Pitch,&Roll,&Yaw); //读取姿态信息(其中偏航角有飘移是正常现象)
- // MPU_Get_Gyroscope(&gx,&gy,&gz);
- // MPU_Get_Accelerometer(&ax,&ay,&az);
- // temp = MPU_Get_Temperature();
- // OLED_ShowNum(3, 1, temp, 3);
- // OLED_ShowSignedNum(2, 1, Pitch, 5);
- // OLED_ShowSignedNum(3, 1, Roll, 5);
- // OLED_ShowSignedNum(4, 1, Yaw, 5);
- // OLED_ShowSignedNum(2, 8, gx, 5);
- // OLED_ShowSignedNum(3, 8, gy, 5);
- // OLED_ShowSignedNum(4, 8, gz, 5);
-
-
-
- MyRTC_ReadTime();
-
-
- temp = MPU_Get_Temperature()/10;
- OLED_ShowNum(3, 6, temp, 2);
- temp = MPU_Get_Temperature()%10;
- OLED_ShowNum(3, 9, temp, 1);
-
-
- // temp = MPU_Get_Temperature()%100;
- // OLED_ShowNum(3, 9, temp, 1);
-
- OLED_ShowNum(2, 6, MyRTC_Time[3], 2); //时
- OLED_ShowNum(2, 9, MyRTC_Time[4], 2); //分
- OLED_ShowNum(2, 12, MyRTC_Time[5], 2); //秒
- //OLED_ShowNum(4, 1, RTC_GetCounter(), 10); //显示32位的秒计数器
- OLED_ShowNum(5, 1, RTC_GetDivider(), 10); //显示余数寄存器
-
-
-
- lastcount = count;
- dmp_get_pedometer_step_count(&count);
- step = count/3;
- OLED_ShowNum(4, 6, step, 3);
- // if(lastcount!=count)
- // OLED_ShowSignedNum(4, 10, (int)count, 3);
- }
- }
复制代码 |
评分
-
查看全部评分
|