esp32 mpu9250数据获取
做这个的目地是获取mpu9250数据
按键处理按键按下 mcu暂停读取数据两秒 在loop 循环里面开始就是结束结束就是开始
用到这几库
//============================================ //mpu9250 配置 #include "MPU9250.h" // an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68 MPU9250 IMU(Wire,0x68); int status; //scl sdc pin22 pin21 //============================================ #include "OneButton.h" //引入头文件 #define BTN 0 //默认按键 OneButton button(BTN, true); //实例化一个OneButton对象 void click() { delay(1000); Serial.println("Stop"); delay(1000); } //============================================ void setup() { //============================================ // serial to display data Serial.begin(115200); //============================================ button.setClickTicks(500);//设置单击时间 button.attachClick(click);//关联单击事件 //============================================ while(!Serial) {} // start communication with IMU status = IMU.begin(); if (status < 0) { Serial.println("IMU initialization unsuccessful"); Serial.println("Check IMU wiring or try cycling power"); Serial.print("Status: "); Serial.println(status); while(1) {} } // setting the accelerometer full scale range to +/-8G IMU.setAccelRange(MPU9250::ACCEL_RANGE_8G); // setting the gyroscope full scale range to +/-500 deg/s IMU.setGyroRange(MPU9250::GYRO_RANGE_500DPS); // setting DLPF bandwidth to 20 Hz IMU.setDlpfBandwidth(MPU9250::DLPF_BANDWIDTH_20HZ); // setting SRD to 19 for a 50 Hz update rate IMU.setSrd(19); } void Rmpu9650(){ // read the sensor IMU.readSensor(); // display the data Serial.print("AccX:"); Serial.print(IMU.getAccelX_mss(),6); Serial.print("\t"); Serial.print("AccY:"); Serial.print(IMU.getAccelY_mss(),6); Serial.print("\t"); Serial.print("AccZ:"); Serial.print(IMU.getAccelZ_mss(),6); Serial.print("\t"); Serial.print("GyroX:"); Serial.print(IMU.getGyroX_rads(),6); Serial.print("\t"); Serial.print("GyroY:"); Serial.print(IMU.getGyroY_rads(),6); Serial.print("\t"); Serial.print("GyroZ:"); Serial.print(IMU.getGyroZ_rads(),6); Serial.print("\t"); // Serial.print(IMU.getMagX_uT(),6); // Serial.print("\t"); // Serial.print(IMU.getMagY_uT(),6); // Serial.print("\t"); // Serial.print(IMU.getMagZ_uT(),6); // Serial.print("\t"); Serial.print("T:"); Serial.println(IMU.getTemperature_C(),6); delay(20); } void loop() { Rmpu9650(); button.tick();//监视按钮 }
数据显示
先到这里吧简单的到这里先,构思下上位机程序准备做数据处理 每个动作执行后的。
本文作者:Yang-blackSun
本文链接:https://www.cnblogs.com/Yang-blackSun/p/18025360
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
本文作者:Yang-blackSun
本文链接:https://www.cnblogs.com/Yang-blackSun/p/18025360
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步