Difference between revisions of "Matrix - Ball Rolling Switch"
(→Basic Device Operation) |
(→下载Matrix源码) |
||
Line 29: | Line 29: | ||
Please connect Pin V to a power supply, Pin G grounded and Pin S to a digital output. When you move the switch pushing the internal metal ball to connect the trigger point a high level signal will be generated and output to a Schmitt trigger which reverses this signal to output a low level signal. When you move the switch pushing the internal metal ball away from the trigger point a low level signal will be generated and output to a Schmitt trigger which reverses this signal to output a high level signal. | Please connect Pin V to a power supply, Pin G grounded and Pin S to a digital output. When you move the switch pushing the internal metal ball to connect the trigger point a high level signal will be generated and output to a Schmitt trigger which reverses this signal to output a low level signal. When you move the switch pushing the internal metal ball away from the trigger point a low level signal will be generated and output to a Schmitt trigger which reverses this signal to output a high level signal. | ||
− | == | + | ==Download Matrix Source Code== |
− | + | All the matrix modules' code samples are open source. They are maintained on GitHub: git://github.com/friendlyarm/matrix.git <br> | |
− | + | Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with<br> | |
− | * | + | * The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi |
− | * | + | * The matrix-nanopi2 branch contains the matrix modules' code samples for the NanoPi 2 |
− | * | + | * The matrix-tiny4412 branch contains the matrix modules' code samples for the Tiny4412; |
− | * | + | * The matrix-raspberrypi branch contains the matrix modules' code samples for the RaspberryPi; |
− | + | 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> | ||
− | + | Clone the matrix code from GitHub | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ git clone git://github.com/friendlyarm/matrix.git | $ git clone git://github.com/friendlyarm/matrix.git | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples. | |
==与NanoPi 2连接使用== | ==与NanoPi 2连接使用== |
Revision as of 10:13, 25 December 2015
Contents
1 Introduction
- The Matrix-Ball_Rolling_Switch module is a ball switch. Its electrical characteristics are very similar to a mercury switch's however a mercury switch is easily broken, oxidized, leaking and not environment-friendly. This ball switch prevents all these issues.
- The switch is free to move any angle and if that angle is between 15 degrees and 45 degrees a signal will be generated and used as an input to a Schmitt trigger.
2 Features
- GPIO
- Small
- 2.54 mm spacing pin header
- PCB Dimension(mm):16 x 16
- Pin Description:
Pin | Description |
S | Digital GPIO |
V | Supply Voltage 5V |
G | Ground |
3 Basic Device Operation
Please connect Pin V to a power supply, Pin G grounded and Pin S to a digital output. When you move the switch pushing the internal metal ball to connect the trigger point a high level signal will be generated and output to a Schmitt trigger which reverses this signal to output a low level signal. When you move the switch pushing the internal metal ball away from the trigger point a low level signal will be generated and output to a Schmitt trigger which reverses this signal to output a high level signal.
4 Download Matrix Source Code
All the matrix modules' code samples are open source. They are maintained on GitHub: git://github.com/friendlyarm/matrix.git
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with
- The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi
- The matrix-nanopi2 branch contains the matrix modules' code samples for the NanoPi 2
- The matrix-tiny4412 branch contains the matrix modules' code samples for the Tiny4412;
- The matrix-raspberrypi branch contains the matrix modules' code samples for the RaspberryPi;
Please follow the steps below to get the source code:
Install the git utility on a PC running Ubuntu14.04
$ sudo apt-get install git
Clone the matrix code from GitHub
$ git clone git://github.com/friendlyarm/matrix.git
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
5 与NanoPi 2连接使用
5.1 硬件连接
参考下图连接模块Matrix-Ball_Rolling_Switch和NanoPi2:
连接说明:
Matrix-Ball_Rolling_Switch | NanoPi2 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
5.2 编译测试程序
进入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.9.3。
编译成功后库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-Ball_Rolling_Switch对应的测试程序为matrix-ball_switch。
5.3 运行测试程序
将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令将Matrix的硬件驱动、库文件和测试程序拷贝到NanoPi 2的文件系统上。
$ cp modules /media/rootfs/ -r $ cp install/lib/* /media/rootfs/lib/ -d $ cp install/usr/bin/* /media/rootfs/usr/bin/
将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令运行模块Matrix-Ball_Rolling_Switch的测试程序。
$ matrix-ball_switch
运行效果如下:
将模块竖立起来,利用开关中的小珠的滚动,制造与金属端子的触碰或改变光线行进的路线,就能产生导通的效果。
5.4 代码展示
static struct sensor brSwitch[] = { { GPIO_PIN(7), IRQ_TYPE_EDGE_FALLING, } }; int main(int argc, char ** argv) { int i; int retSize = -1; char value[ARRAY_SIZE(brSwitch)]; int devFD = -1; if (argc == 2) { brSwitch[0].pin = atoi(argv[1]); } printf("Using GPIO_PIN(%d)\n", brSwitch[0].pin); if ((devFD =sensorInit(brSwitch, ARRAY_SIZE(brSwitch))) == -1) { printf("Fail to init sensor\n"); return -1; } printf("Lean the switch...\n"); if ((retSize = sensorRead(devFD, value, ARRAY_SIZE(brSwitch))) == -1) { printf("Fail to read sensors\n"); } if (retSize > 0) { i = 0; for (i=0; i<retSize; i++) { printf("Switch[%d]:%d\n", i, value[i]); } } sensorDeinit(devFD); return 0; }