当前位置:网站首页>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控制信号。
边栏推荐
猜你喜欢

半导体新能源智能装备整机软件系统方案设计

Mysql实操

【Oracle 11g】Redhat 6.5 安装 Oracle11g

postgresql Window Functions

95后,刚工作2-3年就年薪50W+ ,才发现打败我们的,从来不是年龄···

【报错】Root Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

分布式事务产生的原因

Important news丨.NET Core 3.1 will end support on December 13 this year

XILINX K7 FPGA+RK3399 PCIE驱动调试

c语言位段
随机推荐
codeforces Valera and Elections (这思维题是做不明白了)
灵活好用的sql monitoring 脚本 part7
链表专项练习(三)
Mysql实操
View log common commands
AD picture PCB tutorial 20 minutes clear label shop operation process, copper network
线程API
虚拟机网卡报错:Bringing up interface eth0: Error: No suitable device found: no device found for connection
【sqlite3】sqlite3.OperationalError: table addresses has 7 columns but 6 values were supplied
2017 G icpc shenyang Infinite Fraction Path BFS + pruning
sklearn数据预处理
分布式事务产生的原因
Learning Notes---Machine Learning
postgresql Window Functions
【烂笔头】各厂商手机手动抓log
MYSQLWorkbench看数据库ER图
XxlJobConfig distributed timer task management XxlJob configuration class, replace
XILINX K7 FPGA+RK3399 PCIE驱动调试
力扣第 305 场周赛复盘
unity第一课