“(SKU:RB-02S077)三轴数字罗盘 HMC5883L”的版本间的差异

来自ALSROBOT WiKi
跳转至: 导航搜索
产品相关推荐
第27行: 第27行:
 
依照程序将三轴数字罗盘与UNO连接,观察串口输出的X、Y、Z 三轴数据。
 
依照程序将三轴数字罗盘与UNO连接,观察串口输出的X、Y、Z 三轴数据。
 
===示例代码===
 
===示例代码===
<pre style='color:blue'>#include <Wire.h> //I2C Arduino Library
+
<pre style='color:blue'>
 
+
#include <Wire.h> //I2C Arduino Library
 
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
 
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
 
 
void setup(){
 
void setup(){
 
   //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
第42行: 第40行:
 
   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);
第77行: 第73行:
 
打开串口监视器可以观察到输出的X、Y、Z 三轴数据。
 
打开串口监视器可以观察到输出的X、Y、Z 三轴数据。
 
==产品相关推荐==
 
==产品相关推荐==
购买地址:[http://www.alsrobot.cn/goods-588.html Sparkfun HMC5883L三轴数字罗盘传感器]<br/>
+
[[文件:erweima.png|230px|无框|右]]
论坛地址:[http://www.makerspace.cn/portal.php 奥松机器人技术论坛]
+
===产品购买地址===
 +
[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/>
 +
===相关问题解答===
 +
 
 +
===相关学习资料===
 +
[http://www.makerspace.cn/portal.php 奥松机器人技术论坛]<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/>

2015年9月30日 (三) 16:02的版本

3zszlp.jpg

目录

产品概述

HMC5883L是奥松机器人最引进的Sparkfun原装进口的三轴数字罗盘。通过I2C接口并提供2.16-3.6V的稳定电压就可以与HMC5883L完美连接,它可用于各种轮式机器人导航装置。 此款三轴数字罗盘内含HMC5883L测量芯片,可作为各种轮式机器人导航装置,可装在Boe-Bot Kit机器人上,从而做到方位识别定位的作用。附送PC机控制软件,人机介面简洁便于操作与观测,控制器源程序开放,短暂时刻即可架设完成数字式电子罗 盘。可与多种单片机融合,与BASIC Stamp,Javalin Stamp,以及SX 全系列完全相容。

规格参数

  1. 工作电压 :2.16V~3.6V
  2. 工作电流:100uA(测量模式)
  3. 最大输出频率 :160Hz
  4. 磁场有效宽度:(+/-8 gauss)
  5. 罗盘航向精度:1~2度
  6. 通信接口:I2C
  7. 尺寸大小: 17.78x17.78mm

使用方法

引脚定义及内部电路图

  • GND:地(GND)
  • VIN:电源(VCC)
  • SCL:时钟信号
  • SDA:数据信号
3zszlp1.jpg

连接图示

SCL和SDA端口分别接到控制器的模拟5和4 I/O口。VIN和GND分别接到电源的3.3V和GND。

3zszlp2.jpg

应用例程

依照程序将三轴数字罗盘与UNO连接,观察串口输出的X、Y、Z 三轴数据。

示例代码

#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.send(0x02); //select mode register
  Wire.send(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.send(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.receive()<<8; //X msb
    x |= Wire.receive(); //X lsb
    z = Wire.receive()<<8; //Z msb
    z |= Wire.receive(); //Z lsb
    y = Wire.receive()<<8; //Y msb
    y |= Wire.receive(); //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 三轴数据。

产品相关推荐

Erweima.png

产品购买地址

Sparkfun HMC5883L三轴数字罗盘传感器

周边产品推荐

ADXL335模块三轴加速度模块
Arduino ADXL345 三轴加速度计
Arduino 9 Axes Motion Shield 9轴运动扩展板

相关问题解答

相关学习资料

奥松机器人技术论坛
HMC5883L Breakout Quickstart Guide
电路原理图
HMC5883L 数据手册