使用市面上最常用esp32c3合宙开发板无串口芯片9.9包邮
mpu6050模块
一开始按照拼夕夕官网链接I2C导致没有输出亲们按照我的来链接
GPIO08—>SDA
GPIO09—>SCL
需要在arduino平台安装库文件名字和版本号可以参考我截图
复制粘贴下面的代码到界面
#include <Wire.h>#include <MPU6050.h>#include <Kalman.h>MPU6050 mpu;Kalman kalmanX;Kalman kalmanY;unsigned long t;void setup() {Serial.begin(9600);Wire.begin();mpu.initialize();Serial.println("MPU6050 init done");kalmanX.setAngle(0);kalmanY.setAngle(0);}void loop() {int16_t ax, ay, az, gx, gy, gz;mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);double roll = atan2(ay, az) * 180.0 / PI;double pitch = atan2(-ax, sqrt(ay * ay + az * az)) * 180.0 / PI;double kalmanRoll = kalmanX.getAngle(roll, gx, (double)(micros() - t));double kalmanPitch = kalmanY.getAngle(pitch, gy, (double)(micros() - t));t = micros();// double kalmanRoll = kalmanX.getAngle(roll, gx, (double)1 / 100);// double kalmanPitch = kalmanY.getAngle(pitch, gy, (double)1 / 100);Serial.print("Roll: ");Serial.print(kalmanRoll);Serial.print("\tPitch: ");Serial.println(kalmanPitch);delay(10);}
然后打开arduino自带的串口示波器
就可以看到这样的图形
放在桌子上不动的时候
摇摆开发板的时候
如果觉得《《从零开始打造固定翼飞控》arduino平台esp32-c3芯片mpu6050 卡尔曼滤波kalman》对你有帮助,请点赞、收藏,并留下你的观点哦!