This is mpu6050 driver for HaaS Python. HaaS Python is forked from micropython.
Project description
HaaS Python介绍
HaaS Python是阿里云IoT团队最新研发的一套低代码编程框架,兼容MicroPython编程规范,依托HaaS平台软硬件积木提供AI、支付、蓝牙配网、云连接、UI等物联网场景常用的能力,从而解决了物联网应用开发难的问题。有了Python轻应用框架,物联网编程不再局限于专业软件开发人员,一般的技术员也可以快速实现复杂的物联网需求。 更多HaaS Python介绍和开发资料见HaaS Python官网,创意案例, 硬件积木
HaaS Python is a set of low-code programming frameworks newly developed by Alibaba Cloud IoT team. It is compatible with MicroPython programming specifications. It relies on the hardware and software building blocks of the HaaS platform to provide capabilities commonly used in IoT scenarios such as AI, payment, Bluetooth network configuration, cloud connection, and UI. Solve the difficult problem of IoT application development. With the Python light application framework, IoT programming is no longer limited to professional software developers, and general technicians can quickly implement complex IoT requirements. For more HaaS Python introduction and development materials, see HaaS Python official website, Creative Case, Hardware Building Blocks
安装方法
- 在HaaS Python官网下载开发板对应的固件,并完成固件烧录
Download the firmware corresponding to the development board at HaaS Python website and complete the firmware burning
- 在开发板上运行以下命令完成安装和使用,如果您在使用过程中遇到问题,欢迎在github上向我们提交issue,我们的工程师会及时解答
Run the following commands on the development board to complete the installation and use. If you encounter problems during use, please submit an issue to us on github, Our engineers will answer in time
import upip
upip.install("haas-python-mpu6050")
import haas-python-mpu6050
mpu6050
一、产品简介
MPU6050是一款6轴运动传感器,它集成了3 轴MEMS 陀螺仪,3 轴MEMS加速度计,以及一个可扩展的数字运动处理器DMP(Digital Motion Processor),可用I2C接口连接一个第三方的数字传感器,比如磁力计。扩展之后就可以通过其I2C 或SPI 接口输出一个9 轴的信号。
MPU6050主要应用在智能手机、平板电脑、可穿戴设备、机顶盒、3D遥控器和游戏控制器等产品中。
引脚定义
- VCC:电源正(5V)
- GND:电源地
- SCL:I2C时钟线,用于与主设备通讯
- SDA:I2C数据线,用于与主设备通讯
- XDA:I2C数据线,用于与拓展处理器通讯
- XCL:I2C时钟线,用于与拓展处理器通讯
- AD0:I2C地址控制引脚
- INT:中断上报引脚
二、技术参数
-
工作电压:2.375V~3.46V
-
睡眠电流:<=10uA@25°C
-
工作电流(Low-Noise Mode):
(1) 6轴(陀螺仪+加速度):<=3mA
(2) 3轴(加速度):<=370uA
(3) 3轴(陀螺仪):<=2.8mA
-
工作温度:-40°C~+85°C
-
通信接口:400KHz I2C或10MHz SPI
-
三轴陀螺仪可编程范围:±250dps、±500dps、±1000dps和±2000dps
-
陀螺仪灵敏度误差:±1%
-
陀螺仪噪声:4mdps/√Hz
-
三轴加速度计可编程范围:±2g、±4g、±8g和±16g
-
加速度计噪声:100μg/√Hz
-
片上16位ADC和可编程滤波器
-
用户可编程中断
-
封装尺寸:LGA 3mm * 3mm * 0.75mm
三、软件接口
MPU6050六轴运动传感器HaaS Python驱动:下载地址
MPU6050(i2cObj) - 创建MPU6050驱动对象
- 函数原型:
MPU6050Obj = MPU6050(i2cObj)
- 参数说明:
参数 | 类型 | 必选参数? | 说明 |
---|---|---|---|
i2cObj | I2C | 是 | 调用此函数前需确保I2C对象已被open |
-
返回值: MPU6050对象成功,返回MPU6050对象;MPU6050对象创建失败,抛出Exception
-
示例代码:
from driver import I2C
from mpu6050 import MPU6050
i2cObj = I2C()
i2cObj.open("mpu6050")
MPU6050Dev = MPU6050(i2cObj)
getTemperature - 测量温度
-
函数功能: 量测周围温度并返回测量结果
-
函数原型:
MPU6050.getTemperature()
-
参数说明: 无
-
返回值: 成功返回温度测量结果(数据类型:浮点型;单位:摄氏度);失败抛出Exception
-
示例:
temp = MPU6050Dev.getTemperature()
print("temperature is ", temp, "°C")
- 输出:
temperature is 28.9°C
getAcceleration - 获取加速度值
-
函数功能: 获取传感器的加速度值
-
函数原型:
MPU6050.getAcceleration()
-
参数说明: 无
-
返回值: 成功返回加速度计的原始值数值,其数据类型为tuple (gx,gy,gz) ;失败抛出Exception
-
示例:
acc = MPU6050Dev.getAcceleration()
print(acc)
- 输出:
(7382, 14618, 3306)
getGyroscope - 获取陀螺仪值
-
函数功能: 获取传感器的陀螺仪值
-
函数原型:
MPU6050.getGyroscope()
-
参数说明: 无
-
返回值: 成功返回陀螺仪的原始值数值,其数据类型为tuple (gx,gy,gz) ;失败抛出Exception
-
示例:
gyro = MPU6050Dev.getGyro()
print(gyro)
- 输出:
(14, 9, -49)
四、接口案例
- board.json
⚠️对于MPU6050而言,其 I2C 地址并不是完全确定的,开发者可以通过MPU6050的AD0引脚来决定其 I2C 通讯地址。 其DataSheet中相关的描述如下:
AD0是从I2C接口的地址控制引脚,该引脚控制I2C地址的最低位。如果接GND,则MPU60SO的IIC地址是:0x68,如果接VDD,则是0x69。
因此,开发者在配置和使用此段案例时,需注意你使用的模块具体的硬件连接。
{
"name": "board-name",
"version": "1.0.0",
"io": {
"MPU6050": {
"type": "I2C",
"port": 0,
"addrWidth": 7,
"freq": 400000,
"mode": "master",
"devAddr": 104
}
},
"debugLevel": "ERROR",
"repl": "disable"
}
import utime
from driver import I2C
from mpu6050 import MPU6050
print("Testing mpu6050 ...")
i2cDev = I2C()
i2cDev.open("mpu6050")
mpu6050Dev = MPU6050(i2cDev)
acc = mpu6050Dev.getAcceleration()
print("The Acceleration data is:", acc)
gyro = mpu6050Dev.getGyro()
print("The Gyro data is: ", gyro)
i2cDev.close()
del mpu6050Dev
print("Test mpu6050 done!")
- 输出:
Testing mpu6050 ...
The Acceleration data is: (7382, 14618, 3306)
The Gyro data is: (14, 9, -49)
The mpu6050 data is: (14, 9, -49)
Test mpu6050 done!
参考文献及购买链接
[1] 购买链接
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file haas-python-mpu6050-0.0.7.tar.gz
.
File metadata
- Download URL: haas-python-mpu6050-0.0.7.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f00ddc5ff7d4374f9cc104fbae1059cb900308f29766f6b5cd27c25b023e4b2b |
|
MD5 | 21e849722b72b4904c829308e48cf677 |
|
BLAKE2b-256 | 68b5df1085f5c113b273528ece8ed3905076840196b9ceab375f7a0299e4292d |