Difference between revisions of "Matrix - Joystick/zh"
From FriendlyELEC WiKi
(→与NanoPi M2连接使用) |
|||
Line 32: | Line 32: | ||
*为了更加方便地配合扩展板等标准接口,在设计上把 X,Y轴的电路都单独引出,以控制输入这个操纵杆模块的 x、y的值以及在特定的值下实现某种功能。 | *为了更加方便地配合扩展板等标准接口,在设计上把 X,Y轴的电路都单独引出,以控制输入这个操纵杆模块的 x、y的值以及在特定的值下实现某种功能。 | ||
− | == | + | ==硬件连接== |
− | + | ===连接NanoPi M1=== | |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix_Joystick_nanopi_m1.jpg|frameless|600px|Matrix_Joystick_nanopi_m1]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | = | + | |
− | + | ||
− | + | ||
− | [[File: | + | |
连接说明: | 连接说明: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | |Matrix-Joystick || | + | |Matrix-Joystick || |
|- | |- | ||
− | |GND || NanoPi | + | |GND || NanoPi M1 Pin14 |
|- | |- | ||
− | |5V || NanoPi | + | |5V || NanoPi M1 Pin2 |
|- | |- | ||
|X || Matrix-Analog_to_Digital_Converter A1 | |X || Matrix-Analog_to_Digital_Converter A1 | ||
Line 70: | Line 51: | ||
|} | |} | ||
− | === | + | ===连接NanoPi 2=== |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix-Joystick_nanopi_2.jpg|frameless|600px|Matrix-Joystick_nanopi_2]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[File:Matrix- | + | |
连接说明: | 连接说明: | ||
Line 136: | Line 60: | ||
|Matrix-Joystick || | |Matrix-Joystick || | ||
|- | |- | ||
− | |GND || NanoPi | + | |GND || NanoPi 2 Pin14 |
|- | |- | ||
− | |5V || NanoPi | + | |5V || NanoPi 2 Pin2 |
|- | |- | ||
|X || Matrix-Analog_to_Digital_Converter A1 | |X || Matrix-Analog_to_Digital_Converter A1 | ||
Line 145: | Line 69: | ||
|} | |} | ||
− | === | + | ===连接NanoPi M2 / NanoPi 2 Fire=== |
− | + | NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。<br> | |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix_Joystick_nanopi_m2.jpg|frameless|600px|Matrix_Joystick_nanopi_m2]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[File: | + | |
连接说明: | 连接说明: | ||
Line 211: | Line 79: | ||
|Matrix-Joystick || | |Matrix-Joystick || | ||
|- | |- | ||
− | |GND || | + | |GND || NanoPi M2 Pin14 |
|- | |- | ||
− | |5V || | + | |5V || NanoPi M2 Pin2 |
|- | |- | ||
|X || Matrix-Analog_to_Digital_Converter A1 | |X || Matrix-Analog_to_Digital_Converter A1 | ||
Line 220: | Line 88: | ||
|} | |} | ||
− | === | + | ===连接NanoPC-T2=== |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix_Joystick_NanoPC-T2.jpg|frameless|600px|Matrix_Joystick_NanoPC-T2]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[File: | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
连接说明: | 连接说明: | ||
Line 300: | Line 97: | ||
|Matrix-Joystick || | |Matrix-Joystick || | ||
|- | |- | ||
− | |GND || | + | |GND || NanoPC-T2 Pin30 |
+ | |- | ||
+ | |5V ||NanoPC-T2 Pin29 | ||
|- | |- | ||
− | |||
− | |||
|X || Matrix-Analog_to_Digital_Converter A1 | |X || Matrix-Analog_to_Digital_Converter A1 | ||
|- | |- | ||
Line 309: | Line 106: | ||
|} | |} | ||
− | == | + | ==编译运行测试程序== |
− | + | 启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ | + | $ apt-get update && apt-get install git |
− | $ git | + | $ git clone https://github.com/friendlyarm/matrix.git |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | 克隆完成后会得到一个名为matrix的目录。 | ||
− | + | 编译并安装Matrix: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ cd matrix | $ cd matrix | ||
− | $ | + | $ make && make install |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 运行测试程序: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ matrix-joystick | $ matrix-joystick | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | 注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。 | + | 注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br> |
+ | 运行效果如下:<br> | ||
+ | [[File:matrix-joystick_result.png|frameless||matrix-joystick_result]] <br> | ||
− | == | + | ==代码说明== |
+ | 所有的开发板都共用一套Matrix代码,本模块的测试示例代码如下: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
int main(int argc, char ** argv) | int main(int argc, char ** argv) | ||
Line 415: | Line 135: | ||
int i = 0; | int i = 0; | ||
int x, y; | int x, y; | ||
− | + | ||
x = y = 0; | x = y = 0; | ||
+ | boardInit(); | ||
for (i=0; i<PS2_READ_TIMES; i++) { | for (i=0; i<PS2_READ_TIMES; i++) { | ||
if (pcf8591Read(1, &x) != -1 && pcf8591Read(2, &y) != -1) { | if (pcf8591Read(1, &x) != -1 && pcf8591Read(2, &y) != -1) { | ||
Line 425: | Line 146: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br> | |
− | + | ||
− | + | ||
− | + | ||
==相关资料== | ==相关资料== |
Revision as of 03:57, 31 May 2016
Contents
1 介绍
- Matrix-Joystick是一个双轴按键摇杆模块,由两个滑动变阻器和一个按键组成。
- 当拨动摇杆时,滑动变阻器的阻值就发生变化,对应的X/Y电压值也随之变化,而用力按下摇杆就会触发按键按下,对应的SW信号变为低电平。
2 特性
- X和Y轴,一个按键
- 2.54mm排针接口,接线方便,通用性强
- PCB尺寸(mm):24X32
- 引脚说明:
名称 | 描述 |
GND | 地 |
5V | 电源5V |
SW | 按键 |
X | X轴 |
Y | Y轴 |
3 工作原理
- 模块特设二路模拟输出和一路数字输出接口,输出值分别对应(X,Y)双轴偏移量,其类型为模拟量;按键表示用户是否在Z轴上按下,其类型为数字开关量。模块集成电源指示灯,可显示工作状态;坐标标识符清晰简明、准确定位。
- 为了更加方便地配合扩展板等标准接口,在设计上把 X,Y轴的电路都单独引出,以控制输入这个操纵杆模块的 x、y的值以及在特定的值下实现某种功能。
4 硬件连接
4.1 连接NanoPi M1
连接说明:
Matrix-Joystick | |
GND | NanoPi M1 Pin14 |
5V | NanoPi M1 Pin2 |
X | Matrix-Analog_to_Digital_Converter A1 |
Y | Matrix-Analog_to_Digital_Converter A2 |
4.2 连接NanoPi 2
连接说明:
Matrix-Joystick | |
GND | NanoPi 2 Pin14 |
5V | NanoPi 2 Pin2 |
X | Matrix-Analog_to_Digital_Converter A1 |
Y | Matrix-Analog_to_Digital_Converter A2 |
4.3 连接NanoPi M2 / NanoPi 2 Fire
NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。
参考下图连接模块:
Matrix_Joystick_nanopi_m2
连接说明:
Matrix-Joystick | |
GND | NanoPi M2 Pin14 |
5V | NanoPi M2 Pin2 |
X | Matrix-Analog_to_Digital_Converter A1 |
Y | Matrix-Analog_to_Digital_Converter A2 |
4.4 连接NanoPC-T2
参考下图连接模块:
Matrix_Joystick_NanoPC-T2
连接说明:
Matrix-Joystick | |
GND | NanoPC-T2 Pin30 |
5V | NanoPC-T2 Pin29 |
X | Matrix-Analog_to_Digital_Converter A1 |
Y | Matrix-Analog_to_Digital_Converter A2 |
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-joystick
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
运行效果如下:
6 代码说明
所有的开发板都共用一套Matrix代码,本模块的测试示例代码如下:
int main(int argc, char ** argv) { int i = 0; int x, y; x = y = 0; boardInit(); for (i=0; i<PS2_READ_TIMES; i++) { if (pcf8591Read(1, &x) != -1 && pcf8591Read(2, &y) != -1) { printf("x=%4d y=%4d\n", x, y); } } return 0; }
API说明参考维基:Matrix API reference manual