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

From FriendlyELEC WiKi
Jump to: navigation, search
(准备工作)
(Connect to NanoPi M2 / NanoPi 2 Fire)
 
(44 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Matrix - 3-Axis Digital Compass|English]]
+
[[Matrix - 3-Axis Digital Compass/zh|查看中文]]
  
==介绍==
+
==Introduction==
[[File:Example.jpg|thumb|3-Axis Digital Accelerometer]]
+
[[File:Matrix-3_Axis_Digital_Compass.jpg|thumb|3-Axis Digital Compass]]
*模块Matrix-3_Axis_Digital_Compass上搭载了一颗HMC5883L芯片,HMC5883L利用霍尼韦尔的各种异性磁阻的(AMR)技术,包含最先进的高分辨率HMC118X系列磁阻传感器,并附带Honeywel专利的集成电路包括放大器、自动消磁驱动器、偏差校准、能使指南针精度控制在1°~2°的12位模数转换器,能在±8高斯的磁场中实现5毫高斯分辨率测量。这些传感器的固态结构结合非常低的横轴灵敏度目的是测量方向和地球磁场的大小。,采用I2C方式通讯。
+
* The Matrix-3_Axis_Digital_Compass module is designed to measure the direction and functions like to a compass.
*此模块集成了3.3V电源转换IC给HMC5883L供电,只需连接5V电源和主控的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.
 +
* 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:
* GND===>接地
+
{| class="wikitable"
* 5V  ===>接5V
+
|-
* SCL===>I2C SCL
+
|Pin || Description
* SDA===>I2C SDA
+
|-
 +
|SDA    || I2C SDA
 +
|-
 +
|SCL   || I2C SCL
 +
|-
 +
|5V      || Supply Voltage 5V
 +
|-
 +
|GND    || Ground
 +
|}
  
==工作原理==  
+
==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|三轴重力加速度]]
  
==下载Matrix源码==
+
<!---
Matrix配件相关的代码是完全是开源的,统一由一个仓库进行管理:git://github.com/friendlyarm/matrix.git <br>
+
==Download Matrix Source Code==
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。<br>
+
All the matrix modules' code samples are open source. They are maintained on GitHub - https://github.com/friendlyarm/matrix.git <br>
*matrix-nanopi分支包含了Matrix对NanoPi的支持;
+
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.<br>
*matrix-tiny4412分支包含了Matrix对Tiny4412的支持;
+
* The nanopi branch contains the matrix modules' code samples for the NanoPi
*matrix-raspberrypi分支包含了Matrix对RaspberryPi的支持;
+
* The nanopi 2 branch contains the matrix modules' code samples for the NanoPi 2
 +
* The tiny4412 branch contains the matrix modules' code samples for the Tiny4412
 +
* The raspberrypi branch contains the matrix modules' code samples for the RaspberryPi
  
在主机PC上安装git,以Ubuntu14.04为例
+
Please follow the steps below to get the source code:<br>
 +
Install the git utility on a PC running Ubuntu14.04
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ sudo apt-get install git
 
$ sudo apt-get install git
 
</syntaxhighlight>
 
</syntaxhighlight>
  
克隆Matrix配件代码仓库
+
Clone the matrix code from GitHub
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ git clone git://github.com/friendlyarm/matrix.git
+
$ git clone https://github.com/friendlyarm/matrix.git
 
</syntaxhighlight>
 
</syntaxhighlight>
克隆完成后会得到一个matrix目录,里面存放着所有Matrix配件的代码。
+
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
 +
--->
  
==与NanoPi连接使用==
 
===准备工作===
 
在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器。参考wiki:[[http://wiki.friendlyarm.com/wiki/index.php/NanoPi]]
 
  
===硬件连接===
+
==Applications==
参考下图连接模块Matrix-3_Axis_Digital_Compass和NanoPi <br>
+
===Connect to NanoPi M1===
 +
Refer to the following connection diagram to connect the module to the NanoPi M1:<br>
 +
[[File:Matrix-3_Axis_Digital_Compass_nanopi_m1.jpg|frameless|600px|Matrix-3_Axis_Digital_Compass_nanopi_m1]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || NanoPi M1     
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPi 2===
 +
Refer to the following connection diagram to connect the module to the NanoPi 2:<br>
 +
[[File:Matrix-3_Axis_Digital_Compass_nanopi_2.jpg|frameless|600px|Matrix-3_Axis_Digital_Compass_nanopi_2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || NanoPi 2     
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPi M2 / NanoPi 2 Fire===
 +
Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire.<br>
 +
[[File:Matrix-3_Axis_Digital_Compass_nanopi_m2.jpg|frameless|600px|Matrix-3_Axis_Digital_Compass_nanopi_m2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || NanoPi M2     
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPC-T2===
 +
Refer to the following connection diagram to connect the module to the NanoPC-T2<br>
 +
[[File:Matrix-3_Axis_Digital_Compass_nanopc-T2.jpg|frameless|600px|Matrix-3_Axis_Digital_Compass_NanoPC-T2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || NanoPC-T2
 +
|-
 +
|SDA    || Pin6
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin29
 +
|-
 +
|GND    || Pin30
 +
|}
 +
 
 +
<!---
 +
==Connect to NanoPi 2==
 +
===Hardware Connection===
 +
Please refer to the following connection diagram to connect the Matrix-3_Axis_Digital_Compass to the NanoPi 2:<br>
 +
[[File:Matrix-3_Axis_Digital_Compass_nanopi_2.jpg|frameless|600px|Matrix-3_Axis_Digital_Compass_nanopi_2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || NanoPi 2     
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V    || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Compile Test Program===
 +
Please login the matrix hub and enter the nanopi2 branch
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ git checkout nanopi2
 +
</syntaxhighlight>
 +
 
 +
Compile the Matrix code
 +
<syntaxhighlight lang="bash">
 +
$ make CROSS_COMPILE=arm-linux- clean
 +
$ make CROSS_COMPILE=arm-linux-
 +
$ make CROSS_COMPILE=arm-linux- install
 +
</syntaxhighlight>
 +
Note: please make sure to install the cross compiler "arm-linux-gcc-4.9.3" on your PC, which is used to compile files for the NanoPi 2.<br>
 +
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" directory. The modules are under the "modules" directory.<br>
 +
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git <br>
 +
 
 +
 
 +
 
 +
===Run Test Program===
 +
 
 +
Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.<br>
 +
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the module, library and test program to the card.<br>
 +
<syntaxhighlight lang="bash">
 +
$ cp modules /media/rootfs/ -r
 +
$ cp install/lib/* /media/rootfs/lib/ -d
 +
$ cp install/usr/bin/* /media/rootfs/usr/bin/
 +
</syntaxhighlight>
 +
 
 +
Insert this TF card to your NanoPi 2, power on and run the following command to start the matrix-compass program.<br>
 +
<syntaxhighlight lang="bash">
 +
$ matrix-compass
 +
</syntaxhighlight>
 +
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi 2.<br>
 +
Here is what you should expect:<br>
 +
[[File:matrix-compass_result.png|frameless|600px|matrix-compass_result]]
 +
 
 +
===Code Sample===
 +
<syntaxhighlight lang="c">
 +
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;
 +
}
 +
</syntaxhighlight>
 +
 
 +
==Connect to NanoPi==
 +
===Preparations===
 +
Please install a Debian on a NanoPi and an appropriate cross compiler on a PC. Please refer to wiki: [[NanoPi/zh|NanoPi]] <br>
 +
Compile a NanoPi kernel. Note: please use the kernel's source code from the nanopi-v4.1.y-matrix branch.<br>
 +
<syntaxhighlight lang="bash">
 +
$ 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
 +
</syntaxhighlight>
 +
 
 +
===Hardware Connection===
 +
Please refer to the following connection diagram to connect the Matrix-3_Axis_Digital_Compass module to the NanoPi <br>
 
[[File:matrix-3_axis_digital_compass_nanopi.jpg|frameless|600px|matrix-3_axis_digital_compass_nanopi]]
 
[[File:matrix-3_axis_digital_compass_nanopi.jpg|frameless|600px|matrix-3_axis_digital_compass_nanopi]]
  
===编译测试程序===
+
Connection Details:
进入matrix代码仓库,切换到matrix-nanopi分支
+
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || NanoPi     
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|5V      || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Compile Test Program===
 +
Please login the matrix hub and enter the nanopi branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
$ git checkout matrix-nanopi
+
$ git checkout nanopi
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ make CROSS_COMPILE=arm-linux- clean
 
$ make CROSS_COMPILE=arm-linux- clean
Line 64: Line 279:
 
$ make CROSS_COMPILE=arm-linux- install
 
$ make CROSS_COMPILE=arm-linux- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为NanoPi-Debian配套的arm-linux-gcc.4.4.3。<br>
+
Note: please make sure to install the cross compiler "arm-linux-gcc-4.4.3" on your PC, which is used to compile files for the NanoPi-Debian.<br>
编译出来的库文件位于install/lib目录下,而测试程序则位于install/bin目录下,模块Matrix-3_Axis_Digital_Compass对应的测试程序为matrix-3_axis_digital_compass。<br>
+
Generated library files are under the "install/lib" directory. Applications are under the "install/usr/bin" directory. The test program for the "Matrix-3_Axis_Digital_Compass" module is "matrix-compass".<br>
  
===运行测试程序===
+
===Run Test Program===
拷贝matrix相关的库文件和测试程序到NanoPi的文件系统上
+
Please copy the library files and test program to the NanoPi
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cp install/bin/* nanopi_rootfs/bin/
+
$ cp install/usr/bin/* nanopi_rootfs/usr/bin/
 
$ cp install/lib/* nanopi_rootfs/lib/ -d
 
$ cp install/lib/* nanopi_rootfs/lib/ -d
 
</syntaxhighlight>
 
</syntaxhighlight>
  
然后启动NanoPi,在Debian的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Compass的测试程序 <br>
+
Power on the NanoPi and run the following command in Debian's terminal <br>
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-3_axis_digital_compass
 
$ matrix-3_axis_digital_compass
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===代码展示===
+
===Code Sample===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)
 
int main(int argc, char ** argv)
Line 128: Line 343:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==与Tiny4412连接使用==
+
==Connect to Tiny4412==
===准备工作===
+
===Preparations===
参考Tiny4412光盘里的《友善之臂Ubuntu使用手册》,在Tiny4412上运行UbuntuCore系统,安装并使用相应的编译器。<br>
+
Please refer to the Tiny4412's user's manual to install a UbuntuCore on the Tiny4412 and install an appropriate cross compiler on a PC.<br>
注意:只能使用Tiny4412SDK-1506的底板。
+
Note: only the Tiny4412SDK-1506 carrier board can work with this module.
  
===硬件连接===
+
===Hardware Connection===
参考下图连接模块Matrix-3_Axis_Digital_Compass和Tiny4412 <br>
+
Please refer to the following diagram to connect the Matrix-3_Axis_Digital_Compass to the Tiny4412 <br>
 
[[File:matrix-3_axis_digital_compass_tiny4412.jpg|frameless|600px|matrix-3_axis_digital_compass_tiny4412]]
 
[[File:matrix-3_axis_digital_compass_tiny4412.jpg|frameless|600px|matrix-3_axis_digital_compass_tiny4412]]
  
===编译测试程序===
+
Connection Details:
进入matrix代码仓库,切换到matrix-tiny4412分支
+
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Compass || Tiny4412     
 +
|-
 +
|SDA    || CON18 SDA
 +
|-
 +
|SCL    || CON18 SCL
 +
|-
 +
|5V      || CON18 5V
 +
|-
 +
|GND    || CON18 GND
 +
|}
 +
 
 +
===Compile Test Program===
 +
Please login the Matrix hub and enter the matrix-tiny4412 branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
$ git checkout matrix-tiny4412
+
$ git checkout tiny4412
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
Line 150: Line 379:
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- install
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为tiny4412-UbuntuCore配套的arm-linux-gnueabihf-gcc-4.7.3。<br>
+
Note: please make sure to install the cross compiler "arm-linux-gnueabihf-gcc-4.7.3" on your PC, which is used to compile files for the Tiny4412-UbuntuCore.<br>
编译出来的库文件位于install/lib目录下,而测试程序则位于install/bin目录下,模块Matrix-3_Axis_Digital_Compass对应的测试程序为matrix-3_axis_digital_compass。
+
Generated library files are under the "install/lib" directory. Applications are under the "install/usr/bin" directory. The test program for the "Matrix-3_Axis_Digital_Compass" module is "matrix-compass".
  
===运行测试程序===
+
===Run Test Program===
拷贝matrix相关的库文件和测试程序到Tiny4412的UbuntuCore的文件系统上
+
Please copy the library files and test program to the Tiny4412
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cp install/bin/* tiny4412_rootfs/bin/
+
$ cp install/usr/bin/* tiny4412_rootfs/usr/bin/
 
$ cp install/lib/* tiny4412_rootfs/lib/ -d
 
$ cp install/lib/* tiny4412_rootfs/lib/ -d
 
</syntaxhighlight>
 
</syntaxhighlight>
  
然后启动Tiny4412,在UbuntuCore的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Compass的测试程序 <br>
+
Power on the Tiny4412 and run the following command in UbuntuCore's terminal <br>
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to a Tiny4412.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-3_axis_digital_compass
 
$ matrix-3_axis_digital_compass
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===代码展示===
+
===Code Sample===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)
 
int main(int argc, char ** argv)
Line 214: Line 443:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==与RaspberryPi连接使用==
+
==Connect to RaspberryPi==
 +
 
 +
==Connect to Arduino==
 +
 
 +
--->
 +
 
 +
==Compile & Run Test Program==
 +
Boot your ARM board with Debian and copy the matrix code:
 +
<syntaxhighlight lang="bash">
 +
$ apt-get update && apt-get install git
 +
$ git clone https://github.com/friendlyarm/matrix.git
 +
</syntaxhighlight>
 +
If your cloning is done successfully a "matrix" directory will be generated.
 +
 
 +
Compile and install Matrix:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ make && make install
 +
</syntaxhighlight>
 +
 
 +
Run test program:
 +
<syntaxhighlight lang="bash">
 +
$ matrix-compass
 +
</syntaxhighlight>
 +
Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.<br>
 +
Here is what you should observe:<br>
 +
<syntaxhighlight lang="bash">
 +
The angle is 305.2
 +
</syntaxhighlight>
 +
305.2 is the angle's value whose range is 0 ~ 360.
 +
 
 +
==Code Sample==
 +
This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-3_axis_digital_compass". Here is its source code:
 +
<syntaxhighlight lang="c">
 +
int main(int argc, char ** argv)
 +
{
 +
    int devFD;
 +
    double angle;
 +
    int i2cDev = 0;
 +
   
 +
    if (boardInit() < 0) {
 +
        printf("Fail to init board\n");
 +
        return -1;
 +
    }
 +
   
 +
    if (argc == 2)
 +
        i2cDev = atoi(argv[1]);
 +
    if ((devFD = hmc5883Init(i2cDev)) == -1) {
 +
        printf("Fail to init hmc5883\n");
 +
        return -1;
 +
    }
 +
    if ((angle = hmc5883Read(devFD)) != -1) {
 +
        printf("The angle is %.1f\n", angle);
 +
    } else {
 +
        printf("Fail to read hmc5883\n");
 +
    }
 +
    hmc5883DeInit(devFD);
 +
   
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
For more details about this APIs called in this code sample refer to [[Matrix API reference manual]] <br>
 +
 
 +
 
 +
==Resources==
 +
[http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf HMC5883L_3-Axis_Digital_Compass_IC.pdf]
  
==与Arduino连接使用==
+
==Update Log==
 +
===Feb-23-2016===
 +
* Added the description for "NanoPi 2 branch" in Section 4
 +
* Added driver's source code location in Section 5.2
  
==相关资料==
+
===June-16-2016===
 +
* Re-organized and simplified wiki

Latest revision as of 08:50, 7 July 2016

查看中文

1 Introduction

3-Axis Digital Compass
  • 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 Supply Voltage 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 Applications

4.1 Connect to NanoPi M1

Refer to the following connection diagram to connect the module to the NanoPi M1:
Matrix-3_Axis_Digital_Compass_nanopi_m1

Connection Details:

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

4.2 Connect to NanoPi 2

Refer to the following connection diagram to connect the module to the NanoPi 2:
Matrix-3_Axis_Digital_Compass_nanopi_2

Connection Details:

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

4.3 Connect to NanoPi M2 / NanoPi 2 Fire

Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire.
Matrix-3_Axis_Digital_Compass_nanopi_m2

Connection Details:

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

4.4 Connect to NanoPC-T2

Refer to the following connection diagram to connect the module to the NanoPC-T2
Matrix-3_Axis_Digital_Compass_NanoPC-T2

Connection Details:

Matrix-3_Axis_Digital_Compass NanoPC-T2
SDA Pin6
SCL Pin5
5V Pin29
GND Pin30


5 Compile & Run Test Program

Boot your ARM board with Debian and copy the matrix code:

$ apt-get update && apt-get install git
$ git clone https://github.com/friendlyarm/matrix.git

If your cloning is done successfully a "matrix" directory will be generated.

Compile and install Matrix:

$ cd matrix
$ make && make install

Run test program:

$ matrix-compass

Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.
Here is what you should observe:

The angle is 305.2

305.2 is the angle's value whose range is 0 ~ 360.

6 Code Sample

This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-3_axis_digital_compass". Here is its source code:

int main(int argc, char ** argv)
{
    int devFD;
    double angle;
    int i2cDev = 0;
 
    if (boardInit() < 0) {
        printf("Fail to init board\n");
        return -1;
    }
 
    if (argc == 2)
        i2cDev = atoi(argv[1]);
    if ((devFD = hmc5883Init(i2cDev)) == -1) {
        printf("Fail to init hmc5883\n");
        return -1;
    }
    if ((angle = hmc5883Read(devFD)) != -1) {
        printf("The angle is %.1f\n", angle);
    } else {
        printf("Fail to read hmc5883\n");
    }
    hmc5883DeInit(devFD);
 
    return 0;
}

For more details about this APIs called in this code sample refer to Matrix API reference manual


7 Resources

HMC5883L_3-Axis_Digital_Compass_IC.pdf

8 Update Log

8.1 Feb-23-2016

  • Added the description for "NanoPi 2 branch" in Section 4
  • Added driver's source code location in Section 5.2

8.2 June-16-2016

  • Re-organized and simplified wiki