Difference between revisions of "Matrix - 3-Axis Digital Compass"

From FriendlyELEC WiKi
Jump to: navigation, search
Line 1: Line 1:
 
[[Matrix - 3-Axis Digital Compass/zh|查看中文]]
 
[[Matrix - 3-Axis Digital Compass/zh|查看中文]]
  
==介绍==
+
==Introduction==
 
[[File:Example.jpg|thumb|3-Axis Digital Accelerometer]]
 
[[File:Example.jpg|thumb|3-Axis Digital Accelerometer]]
* 模块Matrix-3_Axis_Digital_Compass的功能为测量方向,相当于指南针。
+
* The Matrix-3_Axis_Digital_Compass module is designed to measure the direction and functions like to a compass.
* 搭载了一颗HMC5883L芯片,HMC5883L利用霍尼韦尔的各种异性磁阻的(AMR)技术,包含最先进的高分辨率HMC118X系列磁阻传感器,并附带Honeywel专利的集成电路包括放大器、自动消磁驱动器、偏差校准、能使指南针精度控制在1°~2°的12位模数转换器,能在±8高斯的磁场中实现5毫高斯分辨率测量。这些传感器的固态结构结合非常低的横轴灵敏度目的是测量方向和地球磁场的大小,采用I2C方式通讯。
+
* It utilizes the HMC5883L chip. The HMC5883L includes high-resolution HMC118X series magneto-resistive sensors plus an ASIC containing amplification, automatic degaussing strap drivers, offset cancellation, and a 12-bit ADC that enables 1° to 2° compass heading accuracy. It achieves 2 milli-gauss field resolution in ±8 gauss fields. These sensors’ solid-state construction with very low cross-axis sensitivity is designed to measure both the direction and the magnitude of Earth’s magnetic fields, from milli-gauss to 8 gauss.  It has an I2C serial bus interface.
* 集成了3.3V电源转换IC给HMC5883L供电,只需连接5V电源和主控的I2C接口就可以使用。
+
* It integrates a 3.3V power conversion IC allowing it to be powered by an external 5V power source. It can be controlled by an I2C master.  
  
==特性==
+
==Features==
 
* I2C,3.3V
 
* I2C,3.3V
* 1~2度精度
+
* 1° to 2° compass heading accuracy
* 2.54mm排针接口,接线方便,通用性强
+
* 2.54 mm spacing pin
* PCB尺寸(mm):16x16
+
* PCB Dimension(mm): 16 x 16
 
[[File:Example.jpg|frameless|400px|重力加速度PCB]]
 
[[File:Example.jpg|frameless|400px|重力加速度PCB]]
  
* 引脚说明:
+
* Pin Description:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-

Revision as of 07:02, 21 September 2015

查看中文

1 Introduction

3-Axis Digital Accelerometer
  • The Matrix-3_Axis_Digital_Compass module is designed to measure the direction and functions like to a compass.
  • It utilizes the HMC5883L chip. The HMC5883L includes high-resolution HMC118X series magneto-resistive sensors plus an ASIC containing amplification, automatic degaussing strap drivers, offset cancellation, and a 12-bit ADC that enables 1° to 2° compass heading accuracy. It achieves 2 milli-gauss field resolution in ±8 gauss fields. These sensors’ solid-state construction with very low cross-axis sensitivity is designed to measure both the direction and the magnitude of Earth’s magnetic fields, from milli-gauss to 8 gauss. It has an I2C serial bus interface.
  • It integrates a 3.3V power conversion IC allowing it to be powered by an external 5V power source. It can be controlled by an I2C master.

2 Features

  • I2C,3.3V
  • 1° to 2° compass heading accuracy
  • 2.54 mm spacing pin
  • PCB Dimension(mm): 16 x 16

重力加速度PCB

  • Pin Description:
名称 描述
SDA I2C SDA
SCL I2C SCL
5V 电源5V
GND

3 工作原理

  • 片内的磁阻元件两两对齐,形成一个共同的敏感轴(如图上的箭头所示),在磁场存在的情况下,磁阻传感器的变化将引起跨电桥输出电压的相应变动。随着磁场在敏感方向上不断增强,电压也就正向增长,输出与沿着该轴方向上的磁阻元件变化成比例,其他磁阻电桥放置在正交方向上,就能精密测量其他方向的磁场强度。 传感器内部还可产生标准磁场而进行的自测试(不论是正向配置还是负向配置),再去测量此标准磁场强度并输出。
  • HMC5883LL 通过两线I2C 总线系统作为一个从机装置进行通信。数据传输速率是标准模式100kbps 或400kbps 速率。总线位格式是一个8 位数据/地址传送和1 位应答位。格式的数据字节(有效载荷)应区分HMC5883L 从机上的大小写的ASCII 字符或二进制数据,以及返回的二进制数据。负二进制值将是以二进制的补码形式(这涉及到后面读到的数据判断有没有超过正数范围)。
  • 这里采用I2C通信,接线方式如下图:

三轴重力加速度

4 下载Matrix源码

Matrix配件相关的代码是完全是开源的,统一由一个仓库进行管理:git://github.com/friendlyarm/matrix.git
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。

  • nanopi分支包含了Matrix对NanoPi的支持;
  • tiny4412分支包含了Matrix对Tiny4412的支持;
  • raspberrypi分支包含了Matrix对RaspberryPi的支持;

在主机PC上安装git,以Ubuntu14.04为例

$ sudo apt-get install git

克隆Matrix配件代码仓库

$ git clone git://github.com/friendlyarm/matrix.git

克隆完成后会得到一个matrix目录,里面存放着所有Matrix配件的代码。

5 与NanoPi连接使用

5.1 准备工作

在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器。参考wiki:NanoPi
注意:必须使用nanopi-v4.1.y-matrix分支编译出来的内核。
下载NanoPi内核源代码并编译

$ git clone https://github.com/friendlyarm/linux-4.x.y.git
$ cd linux-4.x.y
$ git checkout nanopi-v4.1.y-matrix
$ make nanopi_defconfig
$ touch .scmversion
$ make

5.2 硬件连接

参考下图连接模块Matrix-3_Axis_Digital_Compass和NanoPi
matrix-3_axis_digital_compass_nanopi

连接说明:

Matrix-3_Axis_Digital_Compass NanoPi
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

5.3 编译测试程序

进入matrix代码仓库,切换到nanopi分支

$ cd matrix
$ git checkout nanopi

编译Matrix配件代码

$ make CROSS_COMPILE=arm-linux- clean
$ make CROSS_COMPILE=arm-linux-
$ make CROSS_COMPILE=arm-linux- install

注意:请确保你的主机PC当前使用的交叉编译器为NanoPi-Debian配套的arm-linux-gcc-4.4.3。
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-3_Axis_Digital_Compass对应的测试程序为matrix-3_axis_digital_compass。

5.4 运行测试程序

拷贝matrix相关的库文件和测试程序到NanoPi的文件系统上

$ cp install/usr/bin/* nanopi_rootfs/usr/bin/
$ cp install/lib/* nanopi_rootfs/lib/ -d

然后启动NanoPi,在Debian的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Compass的测试程序
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。

$ matrix-3_axis_digital_compass

5.5 代码展示

int main(int argc, char ** argv)
{
    int devFD;
    double angle;
 
    if ((devFD = hmc5883Init()) == -1) {
        printf("Fail to init hmc5883\n");
        return -1;
    }
 
    if ((angle = hmc5883Read(devFD)) == -1) {
        printf("Fail to read hmc5883\n");
        hmc5883DeInit(devFD);
        return -1;
    }
    printf("The angle is %f\n", angle);
    printf("You are heading ");
    if((angle < 22.5) || (angle > 337.5 )) {           
        printf("South\n");
    }
    else if((angle > 22.5) && (angle < 67.5 )) {
        printf("South-West\n");
    }
    else if((angle > 67.5) && (angle < 112.5 )) {  
        printf("West\n");
    }
    else if((angle > 112.5) && (angle < 157.5 )) {  
        printf("North-West\n");
    }
    else if((angle > 157.5) && (angle < 202.5 )) {   
        printf("North\n");
    }
    else if((angle > 202.5) && (angle < 247.5 )) {  
        printf("NorthEast\n");
    }
    else if((angle > 247.5) && (angle < 292.5 )) {  
        printf("East\n");
    }
    else if((angle > 292.5) && (angle < 337.5 )) {   
        printf("SouthEast\n");
    }
    hmc5883DeInit(devFD);
    return 0;
}

6 与Tiny4412连接使用

6.1 准备工作

参考Tiny4412光盘里的《友善之臂Ubuntu使用手册》,在Tiny4412上运行UbuntuCore系统,然后在主机PC上安装并使用相应的编译器。
注意:只能使用Tiny4412SDK-1506的底板。

6.2 硬件连接

参考下图连接模块Matrix-3_Axis_Digital_Compass和Tiny4412
matrix-3_axis_digital_compass_tiny4412

连接说明:

Matrix-3_Axis_Digital_Compass Tiny4412
SDA CON18 SDA
SCL CON18 SCL
5V CON18 5V
GND CON18 GND

6.3 编译测试程序

进入matrix代码仓库,切换到tiny4412分支

$ cd matrix
$ git checkout tiny4412

编译Matrix配件代码

$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
$ make CROSS_COMPILE=arm-linux-gnueabihf-
$ make CROSS_COMPILE=arm-linux-gnueabihf- install

注意:请确保你的主机PC当前使用的交叉编译器为tiny4412-UbuntuCore配套的arm-linux-gnueabihf-gcc-4.7.3。
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-3_Axis_Digital_Compass对应的测试程序为matrix-3_axis_digital_compass。

6.4 运行测试程序

拷贝matrix相关的库文件和测试程序到Tiny4412的UbuntuCore的文件系统上

$ cp install/usr/bin/* tiny4412_rootfs/usr/bin/
$ cp install/lib/* tiny4412_rootfs/lib/ -d

然后启动Tiny4412,在UbuntuCore的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Compass的测试程序
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。

$ matrix-3_axis_digital_compass

6.5 代码展示

int main(int argc, char ** argv)
{
    int devFD;
    double angle;
 
    if ((devFD = hmc5883Init()) == -1) {
        printf("Fail to init hmc5883\n");
        return -1;
    }
 
    if ((angle = hmc5883Read(devFD)) == -1) {
        printf("Fail to read hmc5883\n");
        hmc5883DeInit(devFD);
        return -1;
    }
    printf("The angle is %f\n", angle);
    printf("You are heading ");
    if((angle < 22.5) || (angle > 337.5 )) {           
        printf("South\n");
    }
    else if((angle > 22.5) && (angle < 67.5 )) {
        printf("South-West\n");
    }
    else if((angle > 67.5) && (angle < 112.5 )) {  
        printf("West\n");
    }
    else if((angle > 112.5) && (angle < 157.5 )) {  
        printf("North-West\n");
    }
    else if((angle > 157.5) && (angle < 202.5 )) {   
        printf("North\n");
    }
    else if((angle > 202.5) && (angle < 247.5 )) {  
        printf("NorthEast\n");
    }
    else if((angle > 247.5) && (angle < 292.5 )) {  
        printf("East\n");
    }
    else if((angle > 292.5) && (angle < 337.5 )) {   
        printf("SouthEast\n");
    }
    hmc5883DeInit(devFD);
    return 0;
}

7 与RaspberryPi连接使用

8 与Arduino连接使用

9 相关资料

HMC5883L_3-Axis_Digital_Compass_IC.pdf