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

From FriendlyELEC WiKi
Jump to: navigation, search
(Features)
(工作原理)
Line 28: Line 28:
 
|}
 
|}
  
==工作原理==  
+
==Basic Device Operation==  
*片内的磁阻元件两两对齐,形成一个共同的敏感轴(如图上的箭头所示),在磁场存在的情况下,磁阻传感器的变化将引起跨电桥输出电压的相应变动。随着磁场在敏感方向上不断增强,电压也就正向增长,输出与沿着该轴方向上的磁阻元件变化成比例,其他磁阻电桥放置在正交方向上,就能精密测量其他方向的磁场强度。 传感器内部还可产生标准磁场而进行的自测试(不论是正向配置还是负向配置),再去测量此标准磁场强度并输出。
+
* The Honeywell HMC5883L magnetoresistive sensor circuit is a trio of sensors and application specific support circuits to measure magnetic fields. With power supply applied, the sensor converts any incident magnetic field in the sensitive axis directions to a differential voltage output. The magnetoresistive sensors are made of a nickel-iron (Permalloy) thin-film and patterned as a resistive strip element. In the presence of a magnetic field, a change in the bridge resistive elements causes a corresponding change in voltage across the bridge outputs. These resistive elements are aligned together to have a common sensitive axis (indicated by arrows in the pinout diagram) that will provide positive voltage change with magnetic fields increasing in the sensitive direction. Because the output is only proportional to the magnetic field component along its axis, additional sensor bridges are placed at orthogonal directions to permit accurate measurement of magnetic field in any orientation.
*HMC5883LL 通过两线I2C 总线系统作为一个从机装置进行通信。数据传输速率是标准模式100kbps 或400kbps 速率。总线位格式是一个8 位数据/地址传送和1 位应答位。格式的数据字节(有效载荷)应区分HMC5883L 从机上的大小写的ASCII 字符或二进制数据,以及返回的二进制数据。负二进制值将是以二进制的补码形式(这涉及到后面读到的数据判断有没有超过正数范围)。
+
* The HMC5883L communicates via a two-wire I2C bus system as a slave device. It has 8-bit read address and 8-bit write address. This device supports standard and fast modes, 100kHz and 400kHz, respectively, but does not support the high speed mode (Hs). The bus bit format is an 8-bit Data/Address send and a 1-bit acknowledge bit. The format of the data bytes (payload) shall be case sensitive ASCII characters or binary data to the HMC5883L slave, and binary data returned. Negative binary values will be in two’s complement form. The default (factory) HMC5883L 8-bit slave address is 0x3C for write operations, or 0x3D for read operations.
*这里采用I2C通信,接线方式如下图:
+
* The module has an I2C interface which complies to the I2C standard protocol and the connection diagram is as follows
 
[[File:三轴重力.png|frameless|400px|三轴重力加速度]]
 
[[File:三轴重力.png|frameless|400px|三轴重力加速度]]
  

Revision as of 07:33, 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:
Pin Description
SDA I2C SDA
SCL I2C SCL
5V Power 5V
GND Ground

3 Basic Device Operation

  • The Honeywell HMC5883L magnetoresistive sensor circuit is a trio of sensors and application specific support circuits to measure magnetic fields. With power supply applied, the sensor converts any incident magnetic field in the sensitive axis directions to a differential voltage output. The magnetoresistive sensors are made of a nickel-iron (Permalloy) thin-film and patterned as a resistive strip element. In the presence of a magnetic field, a change in the bridge resistive elements causes a corresponding change in voltage across the bridge outputs. These resistive elements are aligned together to have a common sensitive axis (indicated by arrows in the pinout diagram) that will provide positive voltage change with magnetic fields increasing in the sensitive direction. Because the output is only proportional to the magnetic field component along its axis, additional sensor bridges are placed at orthogonal directions to permit accurate measurement of magnetic field in any orientation.
  • The HMC5883L communicates via a two-wire I2C bus system as a slave device. It has 8-bit read address and 8-bit write address. This device supports standard and fast modes, 100kHz and 400kHz, respectively, but does not support the high speed mode (Hs). The bus bit format is an 8-bit Data/Address send and a 1-bit acknowledge bit. The format of the data bytes (payload) shall be case sensitive ASCII characters or binary data to the HMC5883L slave, and binary data returned. Negative binary values will be in two’s complement form. The default (factory) HMC5883L 8-bit slave address is 0x3C for write operations, or 0x3D for read operations.
  • The module has an I2C interface which complies to the I2C standard protocol and the connection diagram is as follows

三轴重力加速度

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