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

From FriendlyELEC WiKi
Jump to: navigation, search
(硬件连接)
(Resources)
Line 449: Line 449:
  
 
--->
 
--->
 +
 +
==编译运行测试程序==
 +
启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库:
 +
<syntaxhighlight lang="bash">
 +
$ apt-get update && apt-get install git
 +
$ git clone https://github.com/friendlyarm/matrix.git
 +
</syntaxhighlight>
 +
克隆完成后会得到一个名为matrix的目录。
 +
 +
编译并安装Matrix:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ make && make install
 +
</syntaxhighlight>
 +
 +
运行测试程序:
 +
<syntaxhighlight lang="bash">
 +
$ matrix-compass
 +
</syntaxhighlight>
 +
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br>
 +
运行效果如下:<br>
 +
<syntaxhighlight lang="bash">
 +
The angle is 305.2
 +
</syntaxhighlight>
 +
305.2为角度值,角度值的范围为0~360。
 +
 +
==代码说明==
 +
所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-3_axis_digital_compass,内容如下:
 +
<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>
 +
API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br>
 +
  
 
==Resources==
 
==Resources==

Revision as of 09:21, 17 June 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

Please 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

Please 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

Please 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

Please 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 编译运行测试程序

启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库:

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

克隆完成后会得到一个名为matrix的目录。

编译并安装Matrix:

$ cd matrix
$ make && make install

运行测试程序:

$ matrix-compass

注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
运行效果如下:

The angle is 305.2

305.2为角度值,角度值的范围为0~360。

6 代码说明

所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-3_axis_digital_compass,内容如下:

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;
}

API说明参考维基: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