“(SKU:RB-02S077)三轴数字罗盘 HMC5883L”的版本间的差异
来自ALSROBOT WiKi
(→使用方法) |
|||
(未显示2个用户的9个中间版本) | |||
第11行: | 第11行: | ||
#通信接口:I2C | #通信接口:I2C | ||
#尺寸大小: 17.78x17.78mm | #尺寸大小: 17.78x17.78mm | ||
− | == | + | ==接口定义== |
− | + | ||
*GND:地(GND) | *GND:地(GND) | ||
*VIN:电源(VCC) | *VIN:电源(VCC) | ||
*SCL:时钟信号 | *SCL:时钟信号 | ||
*SDA:数据信号 | *SDA:数据信号 | ||
− | [[文件:3zszlp1.jpg| | + | [[文件:3zszlp1.jpg|700px|缩略图|居中]] |
− | === | + | |
+ | ==使用方法== | ||
+ | ===接线方法=== | ||
SCL和SDA端口分别接到控制器的模拟5和4 I/O口。VIN和GND分别接到电源的3.3V和GND。 | SCL和SDA端口分别接到控制器的模拟5和4 I/O口。VIN和GND分别接到电源的3.3V和GND。 | ||
+ | [[文件:RB02S07701.png|500px|缩略图|居中]] | ||
− | + | ===例子程序=== | |
− | + | ||
− | == | + | |
依照程序将三轴数字罗盘与UNO连接,观察串口输出的X、Y、Z 三轴数据。 | 依照程序将三轴数字罗盘与UNO连接,观察串口输出的X、Y、Z 三轴数据。 | ||
− | + | <pre style='color:blue'> | |
− | <pre style='color:blue'>#include <Wire.h> //I2C Arduino Library | + | /* |
− | + | An Arduino code example for interfacing with the HMC5883 | |
+ | Analog input 4 I2C SDA | ||
+ | Analog input 5 I2C SCL | ||
+ | */ | ||
+ | #include <Wire.h> //I2C Arduino Library | ||
#define address 0x1E //0011110b, I2C 7bit address of HMC5883 | #define address 0x1E //0011110b, I2C 7bit address of HMC5883 | ||
第33行: | 第37行: | ||
//Initialize Serial and I2C communications | //Initialize Serial and I2C communications | ||
Serial.begin(9600); | Serial.begin(9600); | ||
− | Wire.begin(); | + | Wire.begin(); |
− | + | ||
//Put the HMC5883 IC into the correct operating mode | //Put the HMC5883 IC into the correct operating mode | ||
Wire.beginTransmission(address); //open communication with HMC5883 | Wire.beginTransmission(address); //open communication with HMC5883 | ||
− | Wire. | + | Wire.write(0x02); //select mode register |
− | Wire. | + | Wire.write(0x00); //continuous measurement mode |
Wire.endTransmission(); | Wire.endTransmission(); | ||
} | } | ||
− | + | void loop(){ | |
− | void loop(){ | + | |
− | + | ||
int x,y,z; //triple axis data | int x,y,z; //triple axis data | ||
− | |||
//Tell the HMC5883 where to begin reading data | //Tell the HMC5883 where to begin reading data | ||
Wire.beginTransmission(address); | Wire.beginTransmission(address); | ||
− | Wire. | + | Wire.write(0x03); //select register 3, X MSB register |
− | Wire.endTransmission(); | + | Wire.endTransmission(); |
− | + | ||
− | + | ||
//Read data from each axis, 2 registers per axis | //Read data from each axis, 2 registers per axis | ||
Wire.requestFrom(address, 6); | Wire.requestFrom(address, 6); | ||
if(6<=Wire.available()){ | if(6<=Wire.available()){ | ||
− | x = Wire. | + | x = Wire.read()<<8; //X msb |
− | x |= Wire. | + | x |= Wire.read(); //X lsb |
− | z = Wire. | + | z = Wire.read()<<8; //Z msb |
− | z |= Wire. | + | z |= Wire.read(); //Z lsb |
− | y = Wire. | + | y = Wire.read()<<8; //Y msb |
− | y |= Wire. | + | y |= Wire.read(); //Y lsb |
− | } | + | } |
− | + | ||
//Print out values of each axis | //Print out values of each axis | ||
Serial.print("x: "); | Serial.print("x: "); | ||
第69行: | 第66行: | ||
Serial.print(y); | Serial.print(y); | ||
Serial.print(" z: "); | Serial.print(" z: "); | ||
− | Serial.println(z); | + | Serial.println(z); |
− | + | ||
delay(250); | delay(250); | ||
− | } </pre> | + | } |
+ | </pre> | ||
===程序效果=== | ===程序效果=== | ||
打开串口监视器可以观察到输出的X、Y、Z 三轴数据。 | 打开串口监视器可以观察到输出的X、Y、Z 三轴数据。 | ||
+ | [[文件:RB02S07710.png|300px|缩略图|居中]] | ||
==产品相关推荐== | ==产品相关推荐== | ||
− | + | [[文件:erweima.png|230px|无框|右]] | |
+ | ===产品购买地址=== | ||
+ | [http://www.alsrobot.cn/goods-588.html Sparkfun HMC5883L三轴数字罗盘传感器]<br/> | ||
+ | ===周边产品推荐=== | ||
+ | [https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-3667083713.14.QyL8Qd&id=18722272286 ADXL335模块三轴加速度模块]<br/> | ||
+ | [https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-3667083713.17.QyL8Qd&id=13280714814 Arduino ADXL345 三轴加速度计]<br/> | ||
+ | [https://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-3667083713.20.QyL8Qd&id=522174307810 Arduino 9 Axes Motion Shield 9轴运动扩展板]<br/> | ||
+ | ===相关问题解答=== | ||
+ | |||
+ | ===相关学习资料=== | ||
+ | [https://www.sparkfun.com/tutorials/301 HMC5883L Breakout Quickstart Guide]<br/> | ||
+ | [http://dlnmh9ip6v2uc.cloudfront.net/datasheets/BreakoutBoards/HMC5883L_Breakout-v11.pdf 电路原理图]<br/> | ||
+ | [http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/HMC5883L-FDS.pdf HMC5883L 数据手册]<br/> | ||
+ | [http://pan.baidu.com/s/1ntD14VZ 三轴数字罗盘 HMC5883L 设计参考 Eagle 文件下载]<br/> | ||
+ | [http://www.makerspace.cn/portal.php 奥松机器人技术论坛]<br/> |
2015年10月23日 (五) 15:41的最后版本
目录 |
产品概述
HMC5883L是奥松机器人最引进的Sparkfun原装进口的三轴数字罗盘。通过I2C接口并提供2.16-3.6V的稳定电压就可以与HMC5883L完美连接,它可用于各种轮式机器人导航装置。 此款三轴数字罗盘内含HMC5883L测量芯片,可作为各种轮式机器人导航装置,可装在Boe-Bot Kit机器人上,从而做到方位识别定位的作用。附送PC机控制软件,人机介面简洁便于操作与观测,控制器源程序开放,短暂时刻即可架设完成数字式电子罗 盘。可与多种单片机融合,与BASIC Stamp,Javalin Stamp,以及SX 全系列完全相容。
规格参数
- 工作电压 :2.16V~3.6V
- 工作电流:100uA(测量模式)
- 最大输出频率 :160Hz
- 磁场有效宽度:(+/-8 gauss)
- 罗盘航向精度:1~2度
- 通信接口:I2C
- 尺寸大小: 17.78x17.78mm
接口定义
- GND:地(GND)
- VIN:电源(VCC)
- SCL:时钟信号
- SDA:数据信号
使用方法
接线方法
SCL和SDA端口分别接到控制器的模拟5和4 I/O口。VIN和GND分别接到电源的3.3V和GND。
例子程序
依照程序将三轴数字罗盘与UNO连接,观察串口输出的X、Y、Z 三轴数据。
/* An Arduino code example for interfacing with the HMC5883 Analog input 4 I2C SDA Analog input 5 I2C SCL */ #include <Wire.h> //I2C Arduino Library #define address 0x1E //0011110b, I2C 7bit address of HMC5883 void setup(){ //Initialize Serial and I2C communications Serial.begin(9600); Wire.begin(); //Put the HMC5883 IC into the correct operating mode Wire.beginTransmission(address); //open communication with HMC5883 Wire.write(0x02); //select mode register Wire.write(0x00); //continuous measurement mode Wire.endTransmission(); } void loop(){ int x,y,z; //triple axis data //Tell the HMC5883 where to begin reading data Wire.beginTransmission(address); Wire.write(0x03); //select register 3, X MSB register Wire.endTransmission(); //Read data from each axis, 2 registers per axis Wire.requestFrom(address, 6); if(6<=Wire.available()){ x = Wire.read()<<8; //X msb x |= Wire.read(); //X lsb z = Wire.read()<<8; //Z msb z |= Wire.read(); //Z lsb y = Wire.read()<<8; //Y msb y |= Wire.read(); //Y lsb } //Print out values of each axis Serial.print("x: "); Serial.print(x); Serial.print(" y: "); Serial.print(y); Serial.print(" z: "); Serial.println(z); delay(250); }
程序效果
打开串口监视器可以观察到输出的X、Y、Z 三轴数据。
产品相关推荐
产品购买地址
周边产品推荐
ADXL335模块三轴加速度模块
Arduino ADXL345 三轴加速度计
Arduino 9 Axes Motion Shield 9轴运动扩展板
相关问题解答
相关学习资料
HMC5883L Breakout Quickstart Guide
电路原理图
HMC5883L 数据手册
三轴数字罗盘 HMC5883L 设计参考 Eagle 文件下载
奥松机器人技术论坛