Difference between revisions of "Matrix - Rotary Encoder/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(运行测试程序)
Line 192: Line 192:
 
$ matrix-rotary_encoder
 
$ matrix-rotary_encoder
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。
+
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。<br>
 +
运行效果:<br>
 +
[[File:matrix-rotary_encoder_nanopi_shell.png|frameless|400px|matrix-rotary_encoder_nanopi_shell]]
  
 
===代码展示===
 
===代码展示===
Line 263: Line 265:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
 
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
 +
运行效果:<br>
 +
[[File:matrix-rotary_encoder_tiny4412_shell.png|frameless|400px|matrix-rotary_encoder_tiny4412_shell]]
  
 
===代码展示===
 
===代码展示===

Revision as of 10:33, 16 November 2015

English

1 介绍

2 特性

File:Matrix-Rotary Encoder PCB.png

  • 引脚说明:
名称 描述

3 工作原理

4 下载Matrix源码

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

  • nanopi分支用于支持NanoPi;
  • nanopi2分支用于支持NanoPi 2;
  • tiny4412分支用于支持Tiny4412;
  • raspberrypi分支用于支持RaspberryPi;

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

$ sudo apt-get install git

克隆Matrix配件代码仓库

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

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

5 与NanoPi 2连接使用

5.1 准备工作

在NanoPi 2上运行Debian系统,然后在主机PC上安装并使用相应的编译器,参考wiki: NanoPi_2 & How to Build the Compiling Environment
注意: 只有使用s5p4418-nanopi2-matrix分支编译出来的内核才能配合Matrix配件正常工作。
下载NanoPi 2内核源代码并编译:

$ git clone https://github.com/friendlyarm/linux-3.4.y.git
$ cd linux-3.4.y
$ git checkout s5p4418-nanopi2-matrix
$ make nanopi2_linux_defconfig
$ touch .scmversion
$ make

编译好后的uImage位于内核源码arch/arm/boot/目录下,把该uImage替换掉SD卡boot分区上的uImage即可。

5.2 硬件连接

参考下图连接模块Matrix-Rotary_Encoder和NanoPi 2:
Matrix-Rotary_Encoder_nanopi_2

连接说明:

Matrix-Rotary_Encoder NanoPi 2
SIB Pin12
SIA Pin11
SW Pin7
5V Pin2
GND Pin6

5.3 编译测试程序

进入Matrix代码仓库,切换到nanopi2分支

$ cd matrix
$ git checkout nanopi2

编译Matrix配件代码

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

注意:请确保你的主机PC当前使用的交叉编译器为NanoPi 2配套的arm-linux-gcc.4.8.5。
编译成功后库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Rotary_Encoder对应的测试程序为matrix-rotary_encoder。

5.4 运行测试程序

将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令可将Matrix的所有库文件和测试程序拷贝到NanoPi 2的文件系统上。

$ cp install/usr/bin/* /media/rootfs/usr/bin/
$ cp install/lib/* /media/rootfs/lib/ -d

将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令运行模块Matrix-Rotary_Encoder的测试程序。

$ matrix-rotary_encoder

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

5.5 代码展示

int main(int argc, char ** argv) 
{ 
    int ret = -1;
    int encoderSw = 0;
    int encoderValue = 0;
 
    if ((ret = rotaryEncoderRead(ENCODER_SW, &encoderSw)) != -1) {
        printf("Get sw : %d\n", encoderSw);
    } else {
        printf("Faided to get sw\n");
    }
 
    if ((ret = rotaryEncoderRead(ENCODER_VALUE, &encoderValue)) != -1) {
        printf("Get value : %d\n", encoderValue);
    } else {
        printf("Faided to get value\n");
    }
 
    return 0;
}

6 与NanoPi连接使用

6.1 准备工作

在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器,参考wiki: NanoPi & How to Build the Compiling Environment
注意: 只有使用nanopi-v4.1.y-matrix分支编译出来的内核才能配合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

编译好后的zImage位于内核源码arch/arm/boot/目录下,把该zImage替换掉NanoPi烧写文件sd-fuse_nanopi/prebuilt下的zImage,重新制作SD卡即可。

6.2 硬件连接

参考下图连接模块Matrix-Rotary_Encoder和NanoPi:
Matrix-Rotary_Encoder_nanopi

连接说明:

Matrix-Rotary_Encoder NanoPi
SIB Pin12
SIA Pin11
SW Pin7
5V Pin2
GND Pin6

6.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-Rotary_Encoder对应的测试程序为matrix-rotary_encoder。

6.4 运行测试程序

将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令可将Matrix的所有库文件和测试程序拷贝到NanoPi的文件系统上。

$ cp install/usr/bin/* /media/rootfs/usr/bin/
$ cp install/lib/* /media/rootfs/lib/ -d

将SD卡重新插入NanoPi,上电启动,在Debian的shell终端中执行以下命令运行模块Matrix-Rotary_Encoder的测试程序。

$ matrix-rotary_encoder

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

6.5 代码展示

int main(int argc, char ** argv) 
{ 
    int ret = -1;
    int encoderSw = 0;
    int encoderValue = 0;
 
    if ((ret = rotaryEncoderRead(ENCODER_SW, &encoderSw)) != -1) {
        printf("Get sw : %d\n", encoderSw);
    } else {
        printf("Faided to get sw\n");
    }
 
    if ((ret = rotaryEncoderRead(ENCODER_VALUE, &encoderValue)) != -1) {
        printf("Get value : %d\n", encoderValue);
    } else {
        printf("Faided to get value\n");
    }
 
    return 0;
}

7 与Tiny4412连接使用

7.1 准备工作

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

7.2 硬件连接

参考下图连接模块Matrix-Rotary_Encoder和Tiny4412:
Matrix-Rotary_Encoder_tiny4412

连接说明:

Matrix-Rotary_Encoder Tiny4412

7.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-Rotary_Encoder对应的测试程序为matrix-rotary_encoder。

7.4 运行测试程序

将带有UbuntuCore系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令可将Matrix的所有库文件和测试程序拷贝到Tiny4412的文件系统上。

$ cp install/usr/bin/* /media/rootfs/usr/bin/
$ cp install/lib/* /media/rootfs/lib/ -d

将SD卡重新插入Tiny4412,上电启动,在UbuntuCore的shell终端中执行以下命令运行模块Matrix-Rotary_Encoder的测试程序。

$ matrix-rotary_encoder

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

7.5 代码展示

int main(int argc, char ** argv) 
{ 
    int ret = -1;
    int encoderSw = 0;
    int encoderValue = 0;
 
    if ((ret = rotaryEncoderRead(ENCODER_SW, &encoderSw)) != -1) {
        printf("Get sw : %d\n", encoderSw);
    } else {
        printf("Faided to get sw\n");
    }
 
    if ((ret = rotaryEncoderRead(ENCODER_VALUE, &encoderValue)) != -1) {
        printf("Get value : %d\n", encoderValue);
    } else {
        printf("Faided to get value\n");
    }
 
    return 0;
}

8 与RaspberryPi连接使用

9 与Arduino连接使用

10 相关资料