【合宙ESP32C3】MPU6500六轴姿态传感器
网上好多教程都是MPU6050的,看到有些网友说其实两款传感器读写都差不多,但是对于我这种小小白,只想先用例程上手,读出数据,其他的再慢慢来。
这里提供了一种简单上手的方法:
【MPU6500文档】:
链接:https://pan.baidu.com/s/1-fA5Kqf1M4Ami8VPBi0KAw?pwd=MPU6
提取码:MPU6
MPU-6500模块(三轴陀螺仪 + 三轴加速度)
模块型号 GY-6500 使用芯片 MPU-6500 供电电源 3-5v(内部低压差稳压) 通信方式 标准IIC/SPI通信协议 芯片内置16bit AD转换器,16位数据输出 陀螺仪范围 ±250 500 1000 2000 °/s 加速度范围 ±2±4±8±16g 采用沉金PCB,机器焊接工艺保证质量 引脚间距 2.54mm
【步骤】
0、接线(IIC)
其中SDA和SLK引脚可以指定为ESP的其他GPIO脚,使用Wire.begin(SDA_PIN,SLK_PIN)来指定相应的IO口为IIC引脚。见后述代码
合宙ESP32C3 | MPU6500 |
VCC(3.3V) | VCC |
GND | GND |
SDA(GPIO4) | SDA |
SLK(GPIO5) |
SLK |
文件:
1、添加库
搜索MPU9250,找到“MPU9250_WE”并安装
2、打开示例代码
3、在setup()函数中添加
Wire.begin(4,5); //将GPIO4作为SDA,将GPIO5作为SLK
完整示例代码如下:(注意MPU6500_ADDR地址为0x68)
/***************************************************************************
* Example sketch for the MPU6500_WE library
*
* This sketch shows how to get acceleration, gyroscocope and temperature
* data from the MPU6500. In essence, the difference to the MPU9250 is the
* missing magnetometer. The shall only show how to "translate" all other
* MPU9250 example sketches for use of the MPU6500
*
* For further information visit my blog:
*
* https://wolles-elektronikkiste.de/mpu9250-9-achsen-sensormodul-teil-1 (German)
* https://wolles-elektronikkiste.de/en/mpu9250-9-axis-sensor-module-part-1 (English)
*
***************************************************************************/#include <MPU6500_WE.h>
#include <Wire.h>
#define MPU6500_ADDR 0x68/* There are several ways to create your MPU6500 object:* MPU6500_WE myMPU6500 = MPU6500_WE() -> uses Wire / I2C Address = 0x68* MPU6500_WE myMPU6500 = MPU6500_WE(MPU6500_ADDR) -> uses Wire / MPU6500_ADDR* MPU6500_WE myMPU6500 = MPU6500_WE(&wire2) -> uses the TwoWire object wire2 / MPU6500_ADDR* MPU6500_WE myMPU6500 = MPU6500_WE(&wire2, MPU6500_ADDR) -> all together* Successfully tested with two I2C busses on an ESP32*/
MPU6500_WE myMPU6500 = MPU6500_WE(MPU6500_ADDR);void setup() {Serial.begin(115200);Wire.begin(4,5);if(!myMPU6500.init()){Serial.println("MPU6500 does not respond");}else{Serial.println("MPU6500 is connected");}/* The slope of the curve of acceleration vs measured values fits quite well to the theoretical * values, e.g. 16384 units/g in the +/- 2g range. But the starting point, if you position the * MPU6500 flat, is not necessarily 0g/0g/1g for x/y/z. The autoOffset function measures offset * values. It assumes your MPU6500 is positioned flat with its x,y-plane. The more you deviate * from this, the less accurate will be your results.* The function also measures the offset of the gyroscope data. The gyroscope offset does not * depend on the positioning.* This function needs to be called at the beginning since it can overwrite your settings!*/Serial.println("Position you MPU6500 flat and don't move it - calibrating...");delay(1000);myMPU6500.autoOffsets();Serial.println("Done!");/* This is a more accurate method for calibration. You have to determine the minimum and maximum * raw acceleration values of the axes determined in the range +/- 2 g. * You call the function as follows: setAccOffsets(xMin,xMax,yMin,yMax,zMin,zMax);* Use either autoOffset or setAccOffsets, not both.*///myMPU6500.setAccOffsets(-14240.0, 18220.0, -17280.0, 15590.0, -20930.0, 12080.0);/* The gyroscope data is not zero, even if you don't move the MPU6500. * To start at zero, you can apply offset values. These are the gyroscope raw values you obtain* using the +/- 250 degrees/s range. * Use either autoOffset or setGyrOffsets, not both.*///myMPU6500.setGyrOffsets(45.0, 145.0, -105.0);/* You can enable or disable the digital low pass filter (DLPF). If you disable the DLPF, you * need to select the bandwdith, which can be either 8800 or 3600 Hz. 8800 Hz has a shorter delay,* but higher noise level. If DLPF is disabled, the output rate is 32 kHz.* MPU6500_BW_WO_DLPF_3600 * MPU6500_BW_WO_DLPF_8800*/myMPU6500.enableGyrDLPF();//myMPU6500.disableGyrDLPF(MPU6500_BW_WO_DLPF_8800); // bandwdith without DLPF/* Digital Low Pass Filter for the gyroscope must be enabled to choose the level. * MPU6500_DPLF_0, MPU6500_DPLF_2, ...... MPU6500_DPLF_7 * * DLPF Bandwidth [Hz] Delay [ms] Output Rate [kHz]* 0 250 0.97 8* 1 184 2.9 1* 2 92 3.9 1* 3 41 5.9 1* 4 20 9.9 1* 5 10 17.85 1* 6 5 33.48 1* 7 3600 0.17 8* * You achieve lowest noise using level 6 */myMPU6500.setGyrDLPF(MPU6500_DLPF_6);/* Sample rate divider divides the output rate of the gyroscope and accelerometer.* Sample rate = Internal sample rate / (1 + divider) * It can only be applied if the corresponding DLPF is enabled and 0<DLPF<7!* Divider is a number 0...255*/myMPU6500.setSampleRateDivider(5);/* MPU6500_GYRO_RANGE_250 250 degrees per second (default)* MPU6500_GYRO_RANGE_500 500 degrees per second* MPU6500_GYRO_RANGE_1000 1000 degrees per second* MPU6500_GYRO_RANGE_2000 2000 degrees per second*/myMPU6500.setGyrRange(MPU6500_GYRO_RANGE_250);/* MPU6500_ACC_RANGE_2G 2 g (default)* MPU6500_ACC_RANGE_4G 4 g* MPU6500_ACC_RANGE_8G 8 g * MPU6500_ACC_RANGE_16G 16 g*/myMPU6500.setAccRange(MPU6500_ACC_RANGE_2G);/* Enable/disable the digital low pass filter for the accelerometer * If disabled the bandwidth is 1.13 kHz, delay is 0.75 ms, output rate is 4 kHz*/myMPU6500.enableAccDLPF(true);/* Digital low pass filter (DLPF) for the accelerometer, if enabled * MPU6500_DPLF_0, MPU6500_DPLF_2, ...... MPU6500_DPLF_7 * DLPF Bandwidth [Hz] Delay [ms] Output rate [kHz]* 0 460 1.94 1* 1 184 5.80 1* 2 92 7.80 1* 3 41 11.80 1* 4 20 19.80 1* 5 10 35.70 1* 6 5 66.96 1* 7 460 1.94 1*/myMPU6500.setAccDLPF(MPU6500_DLPF_6);/* You can enable or disable the axes for gyroscope and/or accelerometer measurements.* By default all axes are enabled. Parameters are: * MPU6500_ENABLE_XYZ //all axes are enabled (default)* MPU6500_ENABLE_XY0 // X, Y enabled, Z disabled* MPU6500_ENABLE_X0Z * MPU6500_ENABLE_X00* MPU6500_ENABLE_0YZ* MPU6500_ENABLE_0Y0* MPU6500_ENABLE_00Z* MPU6500_ENABLE_000 // all axes disabled*///myMPU6500.enableAccAxes(MPU6500_ENABLE_XYZ);//myMPU6500.enableGyrAxes(MPU6500_ENABLE_XYZ);delay(200);
}void loop() {xyzFloat gValue = myMPU6500.getGValues();xyzFloat gyr = myMPU6500.getGyrValues();float temp = myMPU6500.getTemperature();float resultantG = myMPU6500.getResultantG(gValue);Serial.print("Acceleration in g (x,y,z):");Serial.print(gValue.x);Serial.print(" ");Serial.print(gValue.y);Serial.print(" ");Serial.print(gValue.z);Serial.print("Resultant g: ");Serial.println(resultantG);Serial.print("Gyroscope data in degrees/s: ");Serial.print(gyr.x);Serial.print(" ");Serial.print(gyr.y);Serial.print(" ");Serial.println(gyr.z);Serial.print("Temperature in °C: ");Serial.println(temp);Serial.println("********************************************");delay(1000);
}
4、编译下载后,串口显示如下:
所有数据都能正常读取了,调用相关函数开发小功能还是可以的。有了数据显示,才有更大的动力探究更深的知识不是么,一开头就从寄存器来,怕是要劝退不少人,/苦笑
【合宙ESP32C3】MPU6500六轴姿态传感器相关推荐
- 维特智能六轴姿态传感器JY61P_stm32f1xx驱动代码解析
目录 硬件准备/上位机直连 代码驱动 关于官方给出的示例 代码功能及其走位 1.怎样不依托代码验证传感器的某个功能是否有效或者能用? 2.写寄存器的方式 3.为什么不使用WIT私有协议中的关闭上电输出 ...
- 【合宙ESP32C3】DHT11温湿度传感器
我买的DHT11模块自带上拉电阻(1k),若你买的只是模块,直接读取可能读取不到温度,需要自行接一个上拉电阻(1k~10k都行)到模块的DATA引脚. 1.添加DHT库: 找到Adafruit的DHT ...
- stm32 MPU6050 6轴姿态传感器的介绍与DMP的应用
最近应用到三轴姿态传感器,因为之前有MPU6050(6轴传感器,这是6轴的), 进行搭配使用,通过三轴姿态传感器进行舵机的角度调整.(内容来源学习正点原子的教程) 同步B站也已经发布过原子官方教程.让 ...
- MPU6050 6轴姿态传感器的分析与使用(一)
一.MPU6050简介 MPU6050是一个6轴姿态传感器(3轴加速度计和3轴陀螺仪传感器),可以测量芯片自身X.Y.Z轴的加速度.角度参数,通过数据融合,可以得到姿态角. 二.简介分析 1.常见的姿 ...
- STM32实现六轴姿态测量陀螺仪模块JY61P(标准库与HAL库实现)
本模块支持串口采用串口实现数据采集和处理 设备型号选择 目录 设备型号选择 六轴姿态测量陀螺仪模块简介 产品概述 产品特点 引脚说明 模块UART与MCU连接 应用领域 模块与单片机的接线表设计 标准 ...
- 三轴加速度传感器和六轴惯性传感器_一文读懂三轴,六轴,MEMS陀螺仪(角速率传感器)的区别...
原标题:一文读懂三轴,六轴,MEMS陀螺仪(角速率传感器)的区别 随着现代科技的不断发展,陀螺仪也被应用到越来越多的领域和行业,例如我们常见纸飞机等飞行类游戏,赛车类游戏等.以陀螺仪为核心的惯性制导系 ...
- 学习 STM32之九轴姿态传感器(BWT901CL)串口通信读取数据
由于个人应用到3轴传感器,所以买了直接买了一个9轴的,用于学习STM32Core平台串口2连接维特智能串口Normal协议,然后通过串口1直接打印数据,接收传感器数据和与传感器进行通信:需要看产品文档 ...
- 005.Python制作客户端截屏通过合宙ESP32-C3投屏到0.96OLED
Python制作客户端截屏通过ESP32-C3投屏到0.96'OLED 一.实现原理 Python对屏幕进行截屏,并进行数据处理 Python与ESP32-C3通过WIFI建立tcp连接 Python ...
- ICM-42670-P 六轴运动传感器 TDK ICP-10740 气压计实现运动监测
ICM-42670-P 六轴运动传感器 & TDK ICP-10740 气压计,配合 CyweeMotion 算法,实现了运动监测.CyweeMotion 算法不仅支持多种运动模式:如走路.跑 ...
最新文章
- Vue项目中使用wangEditor富文本输入框(推荐)
- boost线程之类成员函数
- 局部图像特征描述概述
- 京东 你访问的页面需要验证证书_SSL证书安全认证有什么原理?
- 操作系统学习(三)-- CPU调度
- MySQL对字符集_对MySQL字符集的认识
- 昨天食物中毒,至今浑身酸痛
- js高级学习笔记(b站尚硅谷)-8-关于语句分号的问题
- esp32+超声波传感器测距
- 奢华酒店品牌美高梅将入驻上海西岸;ClinChoice昆翎完成1.5亿美元融资 | 美通企业日报...
- 一分钟搞懂 微调(fine-tuning)和prompt
- 即将被社会淘汰的五种人
- 开环放大倍数和闭环放大倍数的区别
- 高级JavaScript第(五)篇
- 简易kafka消息服务器搭建
- 分享一个游戏《Flappy 2048》!
- 大厂SQL题1-月活、每日登录次数、留存率、连续登录N天
- Win10解决能Ping通但不能访问局域网主机的问题
- Android开发蓝牙与ble设备的通讯
- Android 高德地图显示国外地图,安卓地图只显示高德地图四个字
热门文章
- 计算机软考软件设计师2019试题,最新2018年上半年软件设计师真题+答案解析上午选择+下午案例完整版(全国计算机软考)...
- 物理学的大厦已经建成,只是天边还有两朵小乌云
- 一个简单的步骤让你的 Python 代码更干净
- 无需编程经验,这份Python自动聊天机器人代码帮你玩转对话交流!
- Java调用百度API实现图像识别
- NFS 与 NAS 是什么关系
- python 加法代码_python运行加法
- 超级计算机模型,迄今为止最精确的黑洞合并模拟,由超级计算机和人工智能创建!...
- 软件项目管理笔记Software Project Management
- 天河计算机二级未来教育第几套,计算机二级考试的题目是从未来教育套题里抽的吗?...