Arduino连接MPU6050陀螺仪
一、线路连接
| Arduino | MPU6050 |
| VCC | 3.3V/5V |
| GND | GND |
| SCL | A5 |
| SDA | A4 |
| INT | D2 |
二、库下载
https://pan.baidu.com/s/1nvt75tJ
下载后,将相关库文件放进Arduino的libraries文件夹中
三、示例代码
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2011-10-07 - initial release /* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/ // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h" // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h" // class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro; int16_t ax, ay, az;
int16_t gx, gy, gz; #define LED_PIN 13
bool blinkState = false; void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin(); // initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(); // initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize(); // verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
} void loop() {
// read raw accel/gyro measurements from device
// accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
int16_t temp = accelgyro.getTemperature();
int16_t tempx = + ( temp / 333.87 ); // these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz); // display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
// Serial.print(ax); Serial.print("\t");
// Serial.print(ay); Serial.print("\t");
// Serial.print(az); Serial.print("\t");
// Serial.print(gx); Serial.print("\t");
// Serial.print(gy); Serial.print("\t");
// Serial.println(gz);
Serial.println(tempx);
Serial.println("================================"); // blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
四、其他
1.其他方法可以在库文件的MPU6050.cpp中查看
2.温度传感器用于零漂校准,用于测温度不准
Arduino连接MPU6050陀螺仪的更多相关文章
- 使用MPU6050陀螺仪自制Arduino数字量角器
MPU6050惯性单元是一个3轴加速度计和一个3轴陀螺仪组合的单元.它还包含温度传感器和DCM,可执行复杂的任务. MPU6050通常用于制作无人机和其他远程控制机器人,如自平衡机器人.在本篇文章中, ...
- 使用Arduino开发板实现与MPU6050陀螺仪传感器连接的方法
MPU6050陀螺仪传感器具有许多强大的功能,采用单芯片封装.它是由一个MEMS加速度计.一个MEMS陀螺仪和温度传感器组成.该模块在将模拟量转换为数字量时非常准确,因为每个通道都有一个16位的模数转 ...
- Arduino连接pH计
关于arduino连接ph,核心的东西就是对ph传感器返回的信号值进行一系列的操作,注意因为返回的信号很弱,而且外部环境对其影响也很大,所以需要在电路设计上加入一些功能,比如信号放大.滤波等,电路设计 ...
- arduino连接1602LCD方法
arduino连接1602LCD方法 参考代码:
- arduino连接12864LCD方法
arduino连接12864LCD方法,参考相关代码. https://blog.csdn.net/txwtech/article/details/95038386
- Arduino连接L298n驱动板驱动小车的电机
1.L298N介绍 先来讲讲电机驱动,驱动一般使用L298N,L298N 是一种双H桥电机驱动芯片,其中每个H桥可以提供2A的电流,功率部分的供电电压范围是2.5-48v,逻辑部分5v供电,接受5vT ...
- Arduino连接SHT10温湿度传感器--返回值不正常解决办法
如题目,arduino中连接温湿度传感器,用的是一个github开源项目,地址:点击打开,其实这个就是一个封装好的库,下载后把解压的文件夹复制到Arduino目录下的librarys文件夹内,重启Ar ...
- 使用Arduino连接HC-SR04超声波距离传感器的方法
距离传感器是机器人项目最有用的传感器之一. HC-SR04是一种便宜的超声波距离传感器,可以帮助您的机器人在房间周围导航.通过一些努力和一个额外的组件,它也可以用作测量设备.在这篇文章中,您将学习到通 ...
- Arduino连接LCD1602显示屏
简介 LCD1602是一种工业字符型液晶,能够同时显示16x02即32个字符.LCD1602液晶显示的原理是利用液晶的物理特性,通过电压对其显示区域进行控制,即可以显示出图形.[百度百科] 引脚说明 ...
随机推荐
- 【图形学手记】Inverse Transform Sampling 逆转换抽样
需求: 我们通过调查,得知大多数人在20岁左右初恋,以20岁为基准,以随机变量X表示早于或晚于该时间的年数,为了简单,假设X值域为[-5,5],并且PDF(X)是一个正态分布函数(当然可以为任意分布, ...
- qwebchannel.js
Qt与JavaScript交互通讯的桥梁 参考资料:[http://doc.qt.io/qt-5/qtwebengine-webenginewidgets-markdowneditor-resourc ...
- mysql用sql语句创建表和数据 设置字符编码为utf-8
简而言之 CREATE DATABASE xx CHARACTER SET utf8 COLLATE utf8_general_ci; USE xx; ),qname ) ) ) ) )); ) ,t ...
- 2019JAVA第九次实验报告
Java实验报告 班级 计科二班 学号 20188442 姓名 吴怡君 完成时间 2019.11.8 评分等级 课程总结 1.实验代码 package Domon8; import java.awt. ...
- urllib库:解析链接
1from urllib.parse import urlparse, urlunparse, urlsplit, urlunsplit, urljoin, urlencode, parse_qs, ...
- 【转】mysql索引的探究
转自:https://mp.weixin.qq.com/s/XTu7jERv3A0CIAzlECFnlA 相信很多人对于MySQL的索引都不陌生,索引(Index)是帮助MySQL高效获取数据的数据结 ...
- property可以声明得位置
property可以声明的位置有4处 1 @interface处 2 扩展处 3 protocol处 4 分类处 其中分类处的property不会合成实例变量,并且编译器也不会自动合成实例变量
- BATJ的常见java面试题
JAVA基础 JAVA中的几种基本数据类型是什么,各自占用多少字节. String类能被继承吗,为什么. 不可以,因为String类有final修饰符,而final修饰的类是不能被继承的,实现细节不允 ...
- spring aop之父子容器
需求;项目对外提供接口,要求每个对外接口都要进行token认证. 解决办法:写一个token认证的工具类,在每个需要认证的接口方法开始的地方,调用工具类中的token认证方法. 问题:因为要满足指定条 ...
- jQuery-点击按钮页面滚动到顶部,底部,指定位置
$('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //页面滚动至顶部 $('. ...