SKU:RB-02S112 电子罗盘

来自ALSROBOT WiKi
2018年10月25日 (四) 17:16Arduino77讨论 | 贡献的版本

跳转至: 导航搜索
02S112001.png

目录

产品概述

电子罗盘,又称数字罗盘,在现代技术条件中电子罗盘作为导航仪器或姿态传感器已被广泛应用。此款传感器是三轴数字罗盘,采用I2C串行总线接口,芯片选用Honeywell HMC5883L,具有高精度,偏移抑制等特点。此传感器具有12位ADC、低噪声、自检测、低电压操作和宽磁场范围等特点,并且内置驱动电路,采用I2C数字接口,体积小,轻便,操作简单。

产品参数

  1. 产品类型:数字传感器
  2. 接口类型:KF2510
  3. 工作电压:5V
  4. 工作温度:-25℃~+85℃
  5. 产品尺寸(mm):30x25mm
  6. 固定孔尺寸(mm):M3 * 4个
  7. 固定孔间距:23 * 18 mm
  8. 重量(g):3g
  • 产品尺寸图:
Size036.jpg

基本使用方法

1、测试环境

  • 硬件环境:Arduino 、电子罗盘
  • 软件环境:Arduino IDE 1.7.7

2、引脚定义

  • SDA:I2C总线的数据线引脚
  • SCL:2C总线的时钟信号引脚
  • -:电源负极
  • +:电源正极

3、硬件连接

02S11201.png

4、测试程序

#include <Wire.h>
/*
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);
}

5、程序效果
在串口监控窗口中分别打印X、Y、Z轴输出值,如图所示:

02S11202.png

产品相关推荐

Erweima.png

产品购买地址

相关学习资料