当前位置:网站首页>CoCube传感器MPU6050笔记
CoCube传感器MPU6050笔记
2022-08-09 07:16:00 【zhangrelay】
参考:
输出x,y,z角度信息:
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
void loop() {
mpu6050.update();
Serial.print("angleX : ");
Serial.print(mpu6050.getAngleX());
Serial.print("\tangleY : ");
Serial.print(mpu6050.getAngleY());
Serial.print("\tangleZ : ");
Serial.println(mpu6050.getAngleZ());
}效果如下:

发送到ROS绘制曲线或做其他用途的,晚些时候补充。
结合这一篇,使用CoCube自带显示进行姿态反馈?
再补充一个全部信息:
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
long timer = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
void loop() {
mpu6050.update();
if(millis() - timer > 1000){
Serial.println("=======================================================");
Serial.print("temp : ");Serial.println(mpu6050.getTemp());
Serial.print("accX : ");Serial.print(mpu6050.getAccX());
Serial.print("\taccY : ");Serial.print(mpu6050.getAccY());
Serial.print("\taccZ : ");Serial.println(mpu6050.getAccZ());
Serial.print("gyroX : ");Serial.print(mpu6050.getGyroX());
Serial.print("\tgyroY : ");Serial.print(mpu6050.getGyroY());
Serial.print("\tgyroZ : ");Serial.println(mpu6050.getGyroZ());
Serial.print("accAngleX : ");Serial.print(mpu6050.getAccAngleX());
Serial.print("\taccAngleY : ");Serial.println(mpu6050.getAccAngleY());
Serial.print("gyroAngleX : ");Serial.print(mpu6050.getGyroAngleX());
Serial.print("\tgyroAngleY : ");Serial.print(mpu6050.getGyroAngleY());
Serial.print("\tgyroAngleZ : ");Serial.println(mpu6050.getGyroAngleZ());
Serial.print("angleX : ");Serial.print(mpu6050.getAngleX());
Serial.print("\tangleY : ");Serial.print(mpu6050.getAngleY());
Serial.print("\tangleZ : ");Serial.println(mpu6050.getAngleZ());
Serial.println("=======================================================\n");
timer = millis();
}
}程序简洁,应该直接能看懂,不需要赘述。

结合角度信息给显示赋值。
#include <MPU6050_tockn.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 16 // On Trinket or Gemma, suggest changing this to 1// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 64 // Popular NeoPixel ringMPU6050 mpu6050(Wire);
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);unsigned char DELAYVAL=1; // Time (in milliseconds) to pause between pixels
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}void loop() {
mpu6050.update();
// Serial.print("angleX : ");
// Serial.print(mpu6050.getAngleX());
// Serial.print("\tangleY : ");
// Serial.print(mpu6050.getAngleY());
// Serial.print("\tangleZ : ");
// Serial.println(mpu6050.getAngleZ());
for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(16*(abs(mpu6050.getAngleX())/180.0), 16*(abs(mpu6050.getAngleY())/180.0), 16*(abs(mpu6050.getAngleZ())/180.0)));
pixels.show(); // Send the updated pixel colors to the hardware.
// delay(DELAYVAL); // Pause before next pass through loop
}
}
补充:
MPU-6000(6050)的角速度全格感测范围为±250、±500、±1000与±2000°/sec (dps),可准确追踪快速与慢速动作,并且,用户可程式控制的加速器全格感测范围为±2g、±4g±8g与±16g。产品传输可透过最高至400kHz的IIC或最高达20MHz的SPI(MPU-6050没有SPI)。MPU-6000可在不同电压下工作,VDD供电电压介为2.5V±5%、3.0V±5%或3.3V±5%,逻辑接口VDDIO供电为1.8V± 5%(MPU6000仅用VDD)。MPU-6000的包装尺寸4x4x0.9mm(QFN),在业界是革命性的尺寸。其他的特征包含内建的温度感测器、包含在运作环境中仅有±1%变动的振荡器。
NeoPixels也被称为WS2812 LED彩带,是连接在一起的全彩色led灯串。你可以设置他它们的红色,绿色和蓝色值, 在0到255之间。neopixel模块可通过精确的时间控制,生成WS2812控制信号。
边栏推荐
- 搭载开源鸿蒙系统的嵌入式XM-RK3568工业互联方案
- 【sqlite3】sqlite3.OperationalError: table addresses has 7 columns but 6 values were supplied
- 找出数组中不重复的值php
- 字节也开始缩招了...
- 高项 04 项目变更管理
- 分布式事务的应用场景
- 【MySQL】update mysql.user set authentication_string=password(“123456“) where User=‘root‘; 报错
- HDU - 3183 A Magic Lamp 线段树
- 【烂笔头】各厂商手机手动抓log
- Lottie系列二:高级属性
猜你喜欢
随机推荐
Inception V3 Eye Closure Detection
力扣第 305 场周赛复盘
【Shell】查找进程的pid并根据pid获取该进程所占用的端口号以及该进程在系统中所下达的指令名称
unity第一课
【Oracle 11g】Redhat 6.5 安装 Oracle11g
高项 04 项目变更管理
软件测试的岗位会越来越少吗?
力扣208,实现Trie(前缀树)
P6 ali machine test of 2020 Fibonacci number
P1505 [National Training Team] Tourism Tree Chain Breakdown
eyb:Redis学习(2)
View log common commands
分布式事务产生的原因
Fragments
The AD in the library of library file suffix. Intlib. Schlib. Pcblib difference
Learning Notes---Machine Learning
JSONObject遍历的时候顺序不一致,导致数据对应出错
Variable used in lambda expression should be final or effectively final报错解决方案
The maximum validity period of an SSL certificate is 13 months. Is it necessary to apply for multiple years at a time?
【sqlite3】sqlite3.OperationalError: table addresses has 7 columns but 6 values were supplied









