Difference between revisions of "Matrix - Compact Kit"

From FriendlyELEC WiKi
Jump to: navigation, search
(介绍)
(Applications)
 
(50 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
==Introduction==
 
==Introduction==
 
[[File:Matrix-Compact_Kit.png|thumb|]]
 
[[File:Matrix-Compact_Kit.png|thumb|]]
*The Matrix-Compact Kit is a compact board with various hardware resources, interfaces and ports including user button, LED, buzzer, ADC, compass, temperature sensor, IR receiver, TFT port and etc. This board can be connected to the NanoPi, NanoPi 2 and Raspberry Pi via its 40 pin header. In addition you can connect other external modules to its GPIOs.
+
*The Matrix-Compact Kit is a compact board with various hardware resources, interfaces and ports. It includes user keys, LED, buzzer, ADC, compass, temperature sensor, IR receiver, TFT port and etc. This board can be connected to the NanoPi, NanoPi 2 and Raspberry Pi via its 40 pin header. In addition you can connect other external modules to its GPIOs.
  
==资源==
+
==Features==
Matrix - Compact Kit集成的元件如下<br>
+
* PCB Dimension(mm):
 +
[[File:Matrix-Compact_Kit_PCB.png|frameless|400px|]]
 +
[[File:Matrix-Compact_Kit.png |thumb|300px|Matrix-Compact_Kit Layout]]
 +
* '''40pin female connector's GPIO Pin Spec'''
 +
::{| class="wikitable"
 +
|-
 +
|Pin# || Name          ||Pin#  || Name   
 +
|-
 +
|1    || VDD_SYS_3.3V  ||2    || VDD_5V
 +
|-
 +
|3    || I2C0_SDA      ||4    || VDD_5V
 +
|-
 +
|5    || I2C0_SCL      ||6    || DGND
 +
|-
 +
|7    || GPIOB28      ||8    || UART3_TXD
 +
|-
 +
|9    || DGND          ||10    || UART3_RXD   
 +
|-
 +
|11  || GPIOB29      ||12    || GPIOB26
 +
|-
 +
|13  || GPIOB30      ||14    || DGND
 +
|-
 +
|15  || GPIOB31      ||16    || PWM2
 +
|-
 +
|17  || VDD_SYS_3.3V ||18    || GPIOB27
 +
|-
 +
|19  || SPI0_MOSI    ||20    || DGND
 +
|-
 +
|21  || SPI0_MISO    ||22    || PWM0
 +
|-
 +
|23  || SPI0_CLK      ||24    || SPI0_CS
 +
|-
 +
|25  || DGND          ||26    || PWM1
 +
|-
 +
|27  || I2C1_SDA      ||28    || I2C1_SCL
 +
|-
 +
|29  || GPIOC8        ||30    || DGND
 +
|-
 +
|31  || SPI2_CLK      ||32    || GPIOC28
 +
|-
 +
|33  || SPI2_CS      ||34    || DGND
 +
|-
 +
|35  || SPI2_MOSI    ||36    || GPIOC7
 +
|-
 +
|37  || SPI2_MISO    ||38    || ALIVEGPIO2
 +
|-
 +
|39  || DGND          ||40    || ALIVEGPIO3
 +
|}
 +
 
 +
[[File:Matrix-Compact_Kit3*10.png |thumb|300px|Matrix-Compact_Kit Layout]]
 +
* '''30pin Pin Spec'''
 +
::{| class="wikitable"
 +
|-
 +
|Pin# || Name          ||Pin#  || Name          ||Pin#  || Name     
 +
|-
 +
|1    || GND ||2    || VDD_5V ||3    ||A1_PCF
 +
|-
 +
|4    || GND ||5    || VDD_5V ||6    ||A2_PCF
 +
|-
 +
|7    || GND ||8    || VDD_5V ||9    ||A3_PCF
 +
|-
 +
|10    || GND ||11    || VDD_5V ||12    ||D1_Pi11
 +
|-
 +
|13    || GND ||14    || VDD_5V ||15    ||D2_Pi26
 +
|-
 +
|16    || GND ||17    || VDD_5V ||18    ||D3_Pi16
 +
|-
 +
|19    || GND ||20    || VDD_5V ||21    ||D4_Pi19
 +
|-
 +
|22    || GND ||23    || VDD_5V ||24    ||D5_Pi21
 +
|-
 +
|25    || GND ||26    || VDD_5V ||27    ||D6_Pi23
 +
|-
 +
|28    || GND ||29    || VDD_5V ||30    ||D7_Pi24
 +
|-
 +
|}
 +
 
 +
[[File:18B20 and IRR.png |thumb|300px|18B20 & IR Receiver Layout]]
 +
* '''18B20 & IR Receiver Pin Spec'''
 +
::{| class="wikitable"
 +
|-
 +
|Module        ||Pin#  || Name        ||Pin#  || Name          ||Pin#  || Name     
 +
|-
 +
|18B20      ||1    || VDD_5V      ||2    || DATA          ||3    || GND
 +
|-
 +
|IR Receiver  ||1    || DATA        ||2    || GND          ||3    || VDD_5V
 +
|-
 +
|}
 +
 
 +
==Applications==
 +
===Connect to NanoPi 2===
 +
Refer to the following connection diagram to connect the module to the NanoPi 2:<br>
 +
[[File:Matrix-Compact_Kit_nanopi2.jpg|frameless|600px|Matrix-Compact_Kit_nanopi2]]
 +
 
 +
==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-compact_kit
 +
</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">
 +
LED blinking 1
 +
LED blinking 2
 +
Button:  1 1 1
 +
ADC channel0: 550
 +
Compass angle: 328.5
 +
Pwm start
 +
Pwm stop
 +
</syntaxhighlight>
 +
 
 +
Run Qt program to test the TFT LCD:
 +
<syntaxhighlight lang="bash">
 +
cd matrix/demo/nanopi-status
 +
./build.sh
 +
./run.sh /dev/fb-st7735s
 +
</syntaxhighlight>
 +
The program will present the system's basic information:<br>
 +
[[File:st7735s-status.pnc|frameless|600px|st7735s-status]]
 +
 
 +
==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-compact_kit". Here is its source code:
 +
<syntaxhighlight lang="c">
 +
int main(int argc, char ** argv)
 +
{
 +
    int board;
 +
   
 +
    if ((board = boardInit()) < 0) {
 +
        printf("Fail to init board\n");
 +
        return -1;
 +
    }
 +
    testLED(board);
 +
    readButton();
 +
    readADC();
 +
    readCompass();
 +
    testPWM(board);
 +
    // readTemp();
 +
    // testIR();
 +
   
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
For more details about this APIs called in this code sample refer to [[Matrix API reference manual]] <br>
 +
 
 +
==Code Samples in Python==
 +
The Python version is 2.7.9 in the following samples<br>
 +
Install the Python libraries and modules:
 +
<syntaxhighlight lang="bash">
 +
$ apt-get install Python-dev libi2c-dev
 +
</syntaxhighlight>
 +
 
 +
The python code is in our github:
 +
<syntaxhighlight lang="bash">
 +
$ git clone https://github.com/friendlyarm/matrix-python.git
 +
</syntaxhighlight>
 +
After it is done a matrix-python directory will be generated.
 +
 
 +
Access LED:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/Matrix.GPIO
 +
$ python setup.py install
 +
$ python test/matrix_output.py 33
 +
</syntaxhighlight>
 +
The red LED will be flashing.
 +
 
 +
Read KEY1:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/Matrix.GPIO
 +
$ python setup.py install
 +
$ python test/matrix_input.py 36
 +
</syntaxhighlight>
 +
When you press KEY1 "value" will be set to 0. When you release KEY1 "value" will be set to 1.
 +
 
 +
Test AD:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/modules
 +
$ modprobe pcf8591
 +
$ cd ../Matrix.pcf8591
 +
$ python setup.py install
 +
$ python test/matrix_adc.py
 +
</syntaxhighlight>
 +
When you change the resistor AD value will be changed accordingly.
 +
 
 +
Test Compass:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/Matrix.I2C
 +
$ python setup.py install
 +
$ python test/matrix_compass.py
 +
</syntaxhighlight>
 +
When you rotate the compass you will get changing direction values.
 +
 
 +
<!---
 +
==Features==
 +
Matrix - Compact Kit has the following onboard resources:<br>
 
* 0.9 TFT LCD
 
* 0.9 TFT LCD
  
* 轻触开关3个
+
* 3 x tact switch
  
* 5mm LED4个
+
* 4 x 5mm LED
  
* 无源蜂鸣器
+
* Buzzer
  
 
* ADC
 
* ADC
  
* 滑动变阻器
+
* Potentiometer
  
* 40pin排母
+
* 40 pin female connector
  
* 4pin排针---I2C接口
+
* 4 pin header - I2C interface
  
* 4pin排针---UART接口
+
* 4 pin header - UART interface
  
* 3pin双排针---3.3V和GND
+
* 3 pin double row pin-header - 3.3V and GND
  
* 18B20温度传感器
+
* DS18B20 temperature sensor
  
* 红外接收器
+
* IR receiver
  
* 3pin排座10个---3个模拟IO,7个数字IO(其中两个可复用为PWM,四个复用为SPI 接口)
+
* 10 x 3 pin header - 3 x AIO, 7 x DIO (two of them can be configured to PWM and four of them can be configured to SPI)
  
* 指南针
+
* Compass
  
==特性==
+
==Dimensional Diagram and Pin Description==
* PCB尺寸(mm):
+
* PCB Dimension (mm):
 
[[File:Matrix-Compact_Kit_PCB.png|frameless|400px|]]
 
[[File:Matrix-Compact_Kit_PCB.png|frameless|400px|]]
[[File:Matrix-Compact_Kit.png |thumb|300px|Matrix-Compact_Kit接口布局]]
+
[[File:Matrix-Compact_Kit01.png |thumb|300px|Matrix-Compact_Kit Interface]]
* '''40pin排母GPIO管脚定义'''
+
* '''40 pin female connector's pin description'''
 
::{| class="wikitable"
 
::{| class="wikitable"
 
|-
 
|-
Line 85: Line 291:
 
|}
 
|}
  
[[File:Matrix-Compact_Kit3*10.png |thumb|300px|Matrix-Compact_Kit接口布局]]
+
[[File:Matrix-Compact_Kit3*10.png |thumb|300px|Matrix-Compact_Kit Interface]]
* '''30pin排针管脚定义'''
+
* '''30 pin header's pin description'''
 
::{| class="wikitable"
 
::{| class="wikitable"
 
|-
 
|-
|Pin# || Name         ||Pin#  || Name         ||Pin#  || Name      
+
|Ch# || G         ||Ch#  || V         ||Ch#  || S      
 
|-
 
|-
 
|1    || GND ||2    || VDD_5V ||3    ||A1_PCF
 
|1    || GND ||2    || VDD_5V ||3    ||A1_PCF
Line 113: Line 319:
 
|}
 
|}
  
[[File:18B20 and IRR.png |thumb|300px|18B20和红外接收接口布局]]
+
[[File:18B20 and IRR.png |thumb|300px|DS18B20 and IR receiver's interface]]
* '''18B20和红外接收管脚定义'''
+
* '''DS18B20 and IR receiver's pin description'''
 
::{| class="wikitable"
 
::{| class="wikitable"
 
|-
 
|-
Line 125: Line 331:
 
|}
 
|}
  
==下载Matrix源码==
+
==Download Matrix Source Code==
Matrix配件相关的代码是完全开源的,统一由一个仓库进行管理:https://github.com/friendlyarm/matrix.git <br>
+
All the matrix modules' code samples are open source. They are maintained on GitHub: https://github.com/friendlyarm/matrix.git <br>
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。<br>
+
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with<br>
* nanopi分支用于支持NanoPi;
+
* The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi
* nanopi2分支用于支持NanoPi 2;
+
* The matrix-nanopi2 branch contains the matrix modules' code samples for the NanoPi 2
* tiny4412分支用于支持Tiny4412;
+
* The matrix-tiny4412 branch contains the matrix modules' code samples for the Tiny4412;
* raspberrypi分支用于支持RaspberryPi;
+
* The matrix-raspberrypi branch contains the matrix modules' code samples for the RaspberryPi;
  
在主机PC上安装git,以Ubuntu14.04为例
+
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 https://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 2连接使用==
+
==Connect to NanoPi 2==
===硬件连接===
+
===Hardware Connection===
参考下图连接模块Matrix-Compact_Kit和NanoPi 2:<br>
+
Refer to the following connection diagram to connect the Matrix-Compact_Kit to the NanoPi 2:<br>
 
[[File:Matrix-Compact_Kit_nanopi2.jpg|frameless|600px|Matrix-Compact_Kit_nanopi2]]
 
[[File:Matrix-Compact_Kit_nanopi2.jpg|frameless|600px|Matrix-Compact_Kit_nanopi2]]
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到nanopi2分支
+
Login to the matrix hub and enter the nanopi2 branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 156: Line 363:
 
</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 162: Line 369:
 
$ make CROSS_COMPILE=arm-linux- install
 
$ make CROSS_COMPILE=arm-linux- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为NanoPi 2配套的arm-linux-gcc-4.9.3。<br>
+
Note: 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>
编译成功后库文件位于install/lib目录下,测试程序位于install/usr/bin目录下,硬件驱动模块位于modules目录。<br>
+
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" 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>
  
===拷贝测试程序===
+
===Copy Test Program===
将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。<br>
+
Insert a TF card which is flashed with Debian into a Linux host and mount its boot and rootfs sections.<br>
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令将Matrix的硬件驱动、库文件和测试程序拷贝到NanoPi 2的文件系统上。<br>
+
We assume the rootfs is mounted to /media/rootfs then run the following commands to copy the module, library and test program to the card<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cp modules /media/rootfs/ -r
 
$ cp modules /media/rootfs/ -r
Line 174: Line 382:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===测试LCD显示===
+
===Test LCD===
将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令。<br>
+
Insert this TF card to your NanoPi 2, power on and run the following commands.<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd /modules
 
$ cd /modules
Line 181: Line 389:
 
$ sudo FRAMEBUFFER=/dev/fb-st7735s startx &
 
$ sudo FRAMEBUFFER=/dev/fb-st7735s startx &
 
</syntaxhighlight>
 
</syntaxhighlight>
fbtft_device是LCD驱动,成功加载驱动后,可以看到LCD被清屏。<br>
+
"fbtft_device" is the LCD's driver.After it is loaded the LCD will be initialized.<br>  
startx命令会将1寸屏作为桌面显示设备,运行效果如下:<br>
+
"startx" sets the LCD to the output device. Here is what you should expect:<br>
 
[[File:matrix-cpt_kit_result1.png|frameless|600px|matrix-cpt_kit_result_lcd]]
 
[[File:matrix-cpt_kit_result1.png|frameless|600px|matrix-cpt_kit_result_lcd]]
  
===测试AD转换===
+
===Access LED===
执行以下命令获得Channel 0的AD转换值:
+
{| class="wikitable"
 +
|-
 +
|LED  || CPU GPIO || linux ID
 +
|-
 +
|LED1 || GPIOC10 || 74
 +
|-
 +
|LED2 || GPIOC9  || 73
 +
|-
 +
|LED3 || GPIOC11 || 75
 +
|-
 +
|LED4 || GPIOC12 || 76
 +
|}
 +
We used LED1 as an example. Run the following commands to access LED1:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ matrix-adc
+
$ cd /sys/class/gpio/
 +
$ echo 74 > export
 +
$ echo out > gpio74/direction
 +
$ echo 1 > gpio74/value
 
</syntaxhighlight>
 
</syntaxhighlight>
通过旋转可调电阻可以改变AD转换值,运行效果如下:<br>
+
1 indicates LED on and 0 indicates LED1 off.
[[File:matrix-cpt_kit_result2.png|frameless|600px|matrix-cpt_kit_result_ad]]
+
 
+
===测试指南针===
+
执行以下命令获得当前方向:
+
<syntaxhighlight lang="bash">
+
$ matrix-compass
+
</syntaxhighlight>
+
通过改变开发板的朝向可以获得不同的方向值,运行效果如下:<br>
+
[[File:matrix-cpt_kit_result3.png|frameless|600px|matrix-cpt_kit_result_cps]]
+
  
===读按键值===
+
===Test Key===
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|按键 || CPU GPIO  || linux索引号
+
|Key || CPU GPIO  || linux ID
 
|-  
 
|-  
 
|KEY1 || GPIOC7    || 71
 
|KEY1 || GPIOC7    || 71
Line 212: Line 426:
 
|KEY3 || ALIVEGPIO3 || 163
 
|KEY3 || ALIVEGPIO3 || 163
 
|}
 
|}
以KEY1为例,执行以下命令读取按键值:
+
We used KEY1 as an example. Running the following commands reads its value:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd /sys/class/gpio/
 
$ cd /sys/class/gpio/
Line 219: Line 433:
 
$ cat gpio71/value
 
$ cat gpio71/value
 
</syntaxhighlight>
 
</syntaxhighlight>
当KEY1按下时value=0,KEY1弹起时value=1。
+
After you press KEY1 the value will be 0. After it is released the value will be 1.
  
===控制LED===
+
===Test AD===
{| class="wikitable"
+
Run the following command to get Channel 0's value:
|-
+
|LED  || CPU GPIO || linux索引号
+
|-
+
|LED1 || GPIOC10 || 74
+
|-
+
|LED2 || GPIOC9  || 73
+
|-
+
|LED3 || GPIOC11 || 75
+
|-
+
|LED4 || GPIOC12 || 76
+
|}
+
以LED1为例,执行以下命令控制LED:
+
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ cd /sys/class/gpio/
+
$ matrix-adc
$ echo 74 > export
+
$ echo out > gpio74/direction
+
$ echo 1 > gpio74/value
+
 
</syntaxhighlight>
 
</syntaxhighlight>
1表示点亮LED1,0表示熄灭LED1。
+
When you turn the resistor the AD value will change. Here is what you should expect:<br>
 +
[[File:matrix-cpt_kit_result2.png|frameless|600px|matrix-cpt_kit_result_ad]]
 +
 
 +
===Test Compass===
 +
Run the following command to activate the compass:
 +
<syntaxhighlight lang="bash">
 +
$ matrix-compass
 +
</syntaxhighlight>
 +
When you change the module's direction you will get a changing value. Here is what you should expect:<br>
 +
[[File:matrix-cpt_kit_result3.png|frameless|600px|matrix-cpt_kit_result_cps]]
 +
 
 +
===Test Temperature Sensor===
 +
Refer to the following connection diagram to connect the Matrix-Compact_Kit to the DS18B20 temperature sensor:<br>
 +
[[File:Matrix-Compact_Kit_ds18b20.jpg|frameless|600px|Matrix-Compact_Kit_ds18b20]]
 +
 
 +
Run the following commands:
 +
<syntaxhighlight lang="bash">
 +
$ cd /modules
 +
$ insmod w1-gpio.ko
 +
$ insmod w1-gpio-board gpio=72
 +
$ matrix-temp_sensor
 +
</syntaxhighlight>
 +
gpio=72 means pin GPIOC8 is used. 72 is the index number in Linux.<br>
 +
Here is what you should expect:<br>
 +
[[File:matrix-temperature_sensor_result.png|frameless|600px|matrix-temperature_sensor_result]]
 +
 
 +
===Test IR Receiver===
 +
Refer to the following connection diagram to connect the Matrix-Compact_Kit to the VS1833B IR receiver:<br>
 +
[[File:Matrix-Compact_Kit_vs1833b.jpg|frameless|600px|Matrix-Compact_Kit_vs1833b]]
 +
 
 +
Run the following commands:
 +
<syntaxhighlight lang="bash">
 +
$ cd /modules
 +
$ insmod matrix_ir_recv.ko gpio=92
 +
</syntaxhighlight>
 +
gpio=92 means pin GPIOC28 is used. 92 is the index number in Linux.<br>
 +
After the driver is successfully loaded a device node will be generated under /dev/input/. We assume it is event1 in our example.<br>
 +
 
 +
An open source utility "input-utils" can be used to read a device's data. Here is how to do it:<br>
 +
<syntaxhighlight lang="bash">
 +
$ apt-get install input-utils
 +
$ input-events 1
 +
</syntaxhighlight>
 +
1 stands for device node event1。<br>
 +
 
 +
If you send data to the IR receiver with a remote control you will be able to see this:<br>
 +
[[File:matrix-ir_receiver_result.png|frameless|600px|matrix-ir_receiver_result]]
 +
 
 +
===Code Samples in Python===
 +
The Python version is 2.7.9 in the following samples<br>
 +
Install the Python libraries and modules:
 +
<syntaxhighlight lang="bash">
 +
$ apt-get install Python-dev
 +
$ apt-get install libi2c-dev
 +
</syntaxhighlight>
 +
The python code is in our github:
 +
<syntaxhighlight lang="bash">
 +
$ git clone https://github.com/friendlyarm/matrix-python.git
 +
</syntaxhighlight>
 +
After it is done a matrix-python directory will be generated.
 +
 
 +
 
 +
Access LED:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/Matrix.GPIO
 +
$ python setup.py install
 +
$ python test/matrix_output.py 33
 +
</syntaxhighlight>
 +
The red LED will be flashing.
 +
 
 +
Read KEY1:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/Matrix.GPIO
 +
$ python setup.py install
 +
$ python test/matrix_input.py 36
 +
</syntaxhighlight>
 +
When you press KEY1 "value" will be set to 0. When you release KEY1 "value" will be set to 1.
 +
 
 +
Test AD:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/modules
 +
$ insmod pcf8591.ko
 +
$ cd ../Matrix.pcf8591
 +
$ python setup.py install
 +
$ python test/matrix_adc.py
 +
</syntaxhighlight>
 +
When you change the resistor AD value will be changed accordingly.
 +
 
 +
Test Compass:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix-python/Matrix.I2C
 +
$ python setup.py install
 +
$ python test/matrix_compass.py
 +
</syntaxhighlight>
 +
When you rotate the compass you will get changing direction values
 +
 
 +
==Connect to NanoPi==
 +
 
 +
==Connect to Tiny4412==
 +
 
 +
==Connect to RaspberryPi==
 +
 
 +
==Connect to Arduino==
 +
--->
 +
 
 +
==Resources==
 +
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/9/94/Schematic-Martix_Compact_Kit.pdf Matrix - Compact Kit-Schematic.pdf])
 +
*[Schematic]([http://pan.baidu.com/s/1pJQ29Az?qq-pf-to=pcqq.temporaryc2c Matrix - Compact Kit-Schematic.pdf])
 +
*[0.9'LCD datasheet]([http://wiki.friendlyarm.com/wiki/images/3/3b/0.9inch_TFT_ST7735S.pdf Matrix - Compact Kit-0.9'LCD datasheet.pdf])
  
==与NanoPi连接使用==
+
==Update Log==
 +
===Feb-17-2016===
 +
* Added 5.9, 5.10 and 5.11
  
==与Tiny4412连接使用==
+
===Feb-24-2016===
 +
* Added the driver's source code location in Section 5.2
  
==与RaspberryPi连接使用==
+
===Mar-21-2016===
 +
* Corrected typo in Section 5.9
 +
* Added lib installation steps in Section 5.11
  
==与Arduino连接使用==
+
===Mar-29-2016===
 +
* Corrected expression errors
  
==相关资料==
+
===June-19-2016===
*[Schematic]()
+
* Re-organized and simplified wiki

Latest revision as of 10:32, 19 June 2016

查看中文

1 Introduction

Matrix-Compact Kit.png
  • The Matrix-Compact Kit is a compact board with various hardware resources, interfaces and ports. It includes user keys, LED, buzzer, ADC, compass, temperature sensor, IR receiver, TFT port and etc. This board can be connected to the NanoPi, NanoPi 2 and Raspberry Pi via its 40 pin header. In addition you can connect other external modules to its GPIOs.

2 Features

  • PCB Dimension(mm):

Matrix-Compact Kit PCB.png

Matrix-Compact_Kit Layout
  • 40pin female connector's GPIO Pin Spec
Pin# Name Pin# Name
1 VDD_SYS_3.3V 2 VDD_5V
3 I2C0_SDA 4 VDD_5V
5 I2C0_SCL 6 DGND
7 GPIOB28 8 UART3_TXD
9 DGND 10 UART3_RXD
11 GPIOB29 12 GPIOB26
13 GPIOB30 14 DGND
15 GPIOB31 16 PWM2
17 VDD_SYS_3.3V 18 GPIOB27
19 SPI0_MOSI 20 DGND
21 SPI0_MISO 22 PWM0
23 SPI0_CLK 24 SPI0_CS
25 DGND 26 PWM1
27 I2C1_SDA 28 I2C1_SCL
29 GPIOC8 30 DGND
31 SPI2_CLK 32 GPIOC28
33 SPI2_CS 34 DGND
35 SPI2_MOSI 36 GPIOC7
37 SPI2_MISO 38 ALIVEGPIO2
39 DGND 40 ALIVEGPIO3
Matrix-Compact_Kit Layout
  • 30pin Pin Spec
Pin# Name Pin# Name Pin# Name
1 GND 2 VDD_5V 3 A1_PCF
4 GND 5 VDD_5V 6 A2_PCF
7 GND 8 VDD_5V 9 A3_PCF
10 GND 11 VDD_5V 12 D1_Pi11
13 GND 14 VDD_5V 15 D2_Pi26
16 GND 17 VDD_5V 18 D3_Pi16
19 GND 20 VDD_5V 21 D4_Pi19
22 GND 23 VDD_5V 24 D5_Pi21
25 GND 26 VDD_5V 27 D6_Pi23
28 GND 29 VDD_5V 30 D7_Pi24
18B20 & IR Receiver Layout
  • 18B20 & IR Receiver Pin Spec
Module Pin# Name Pin# Name Pin# Name
18B20 1 VDD_5V 2 DATA 3 GND
IR Receiver 1 DATA 2 GND 3 VDD_5V

3 Applications

3.1 Connect to NanoPi 2

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

4 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-compact_kit

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:

LED blinking 1
LED blinking 2
Button:  1 1 1
ADC channel0: 550
Compass angle: 328.5
Pwm start
Pwm stop

Run Qt program to test the TFT LCD:

cd matrix/demo/nanopi-status
./build.sh
./run.sh /dev/fb-st7735s

The program will present the system's basic information:
st7735s-status

5 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-compact_kit". Here is its source code:

int main(int argc, char ** argv)
{
    int board;
 
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
    testLED(board);
    readButton();
    readADC();
    readCompass();
    testPWM(board);
    // readTemp();
    // testIR();
 
    return 0;
}

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

6 Code Samples in Python

The Python version is 2.7.9 in the following samples
Install the Python libraries and modules:

$ apt-get install Python-dev libi2c-dev

The python code is in our github:

$ git clone https://github.com/friendlyarm/matrix-python.git

After it is done a matrix-python directory will be generated.

Access LED:

$ cd matrix-python/Matrix.GPIO
$ python setup.py install
$ python test/matrix_output.py 33

The red LED will be flashing.

Read KEY1:

$ cd matrix-python/Matrix.GPIO
$ python setup.py install
$ python test/matrix_input.py 36

When you press KEY1 "value" will be set to 0. When you release KEY1 "value" will be set to 1.

Test AD:

$ cd matrix-python/modules
$ modprobe pcf8591
$ cd ../Matrix.pcf8591
$ python setup.py install
$ python test/matrix_adc.py

When you change the resistor AD value will be changed accordingly.

Test Compass:

$ cd matrix-python/Matrix.I2C
$ python setup.py install
$ python test/matrix_compass.py

When you rotate the compass you will get changing direction values.


7 Resources

8 Update Log

8.1 Feb-17-2016

  • Added 5.9, 5.10 and 5.11

8.2 Feb-24-2016

  • Added the driver's source code location in Section 5.2

8.3 Mar-21-2016

  • Corrected typo in Section 5.9
  • Added lib installation steps in Section 5.11

8.4 Mar-29-2016

  • Corrected expression errors

8.5 June-19-2016

  • Re-organized and simplified wiki