Difference between revisions of "Matrix - Compact Kit B"

From FriendlyELEC WiKi
Jump to: navigation, search
(特性)
(下载Matrix源码)
Line 122: Line 122:
 
|}
 
|}
  
==下载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

Revision as of 02:45, 23 May 2016

查看中文

1 Introduction

Matrix-Compact Kit B.png
  • The Matrix Compact Kit B is a FriendlyARM developed compact board with various hardware resources, interfaces and ports. It contains user keys, LEDs, buzzer, ADC, compass, temperature sensor, IR receiver and TFT interface. It works with FriendlyARM's NanoPi 2 Fire and NanoPi M2 via its 40 pin male connector and is compatible with Raspberry Pi and Arduino boards. In addition you can connect various devices to its IO pin-header.

2 Features

Matrix - Compact Kit B contains the following components:

  • 0.9 TFT LCD
  • 3 x Switch
  • 4 x 5mm LED
  • Buzzer
  • ADC
  • Potentiometer
  • 40pin Female Connector
  • 4pin pin-header – I2C
  • 4pin pin-header – UART
  • 3pin double pin-header – 3.3V and GND
  • 18B20 Temperature Sensor
  • IR Receiver
  • 10 x 3pin pin-header – 3 x AIO & 7 x DIO (two can be configured to PWM and four can be configured to SPI)
  • Compass

3 Dimensional Diagram and Pin Description

  • PCB Dimension(mm):64 x 40

Matrix-Compact Kit B PCB.png

  • 40 pin female connector's pin description
Pin# Name Pin# Name
1 SYS_3.3V 2 VDD_5V
3 I2C0_SDA 4 VDD_5V
5 I2C0_SCL 6 DGND
7 GPIOD8/PPM 8 UART3_TXD/GPIOD21
9 DGND 10 UART3_RXD/GPIOD17
11 UART4_TX/GPIOB29 12 GPIOD1/PWM0
13 GPIOB30 14 DGND
15 GPIOB31 16 GPIOC14/PWM2
17 SYS_3.3V 18 GPIOB27
19 SPI0_MOSI/GPIOC31 20 DGND
21 SPI0_MISO/GPIOD0 22 UART4_RX/GPIOB28
23 SPI0_CLK/GPIOC29 24 SPI0_CS/GPIOC30
25 DGND 26 GPIOB26
27 I2C1_SDA 28 I2C1_SCL
29 GPIOC8 30 DGND
31 GPIOC7 32 GPIOC28
33 GPIOC13/PWM1 34 DGND
35 SPI2_MISO/GPIOC11 36 SPI2_CS/GPIOC10
37 AliveGPIO3 38 SPI2_MOSI/GPIOC12
39 DGND 40 SPI2_CLK/GPIOC9
  • 30 pin header's pin description
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_Pi33
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 and IR Receiver's Layout
  • DS18B20 and IR receiver's pin description
Module Pin# Name Pin# Name Pin# Name
18B20 1 VDD_5V 2 DATA 3 GND
IR Receiver 1 DATA 2 GND 3 VDD_5V

4 Download Matrix Source Code

All the matrix modules' code samples are open source. They are maintained on GitHub: https://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;

Follow the steps below to get the source code
Install the git utility on a PC running Ubuntu14.04

$ sudo apt-get install git

克隆Matrix配件代码仓库

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

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

5 与NanoPi 2 Fire连接使用

5.1 硬件连接

参考下图连接模块Matrix-Compact_Kit_B和NanoPi 2:
Matrix-Compact_Kit_B_nanopi2

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目录下,硬件驱动模块位于modules目录。
硬件驱动模块位于modules目录下,对应的驱动源码都包含在在NanoPi 2的Linux内核仓库里:https://github.com/friendlyarm/linux-3.4.y.git

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/

5.4 测试LCD显示

将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令。

$ cd /modules
$ insmod fbtft_device.ko name=matrix-st7735s gpios=dc:58,reset:63,cs:59
$ sudo FRAMEBUFFER=/dev/fb-st7735s startx &

fbtft_device是LCD驱动,成功加载驱动后,可以看到LCD被清屏。
startx命令会将1寸屏作为桌面显示设备,运行效果如下:
03

5.5 测试蜂鸣器

将蜂鸣器的跳线接到ON,执行以下命令控制蜂鸣器:

$ cd /modules
$ insmod matrix_pwm.ko
$ matrix-buzzer

运行效果如下:
matrix-buzzer_result
可以听到蜂鸣器在响,默认输出的PWM频率为1KHz,占用比为50%。

5.6 控制LED

LED CPU GPIO Linux索引号 物理索引号
红色LED1 GPIOB28 60 28
绿色LED2 GPIOC7 71 31
蓝色LED3 ALIVEGPIO3 163 37
黄色LED4 GPIOC11 75 35

以LED1为例,执行以下命令控制LED:

$ cd /sys/class/gpio/
$ echo 60 > export
$ echo out > gpio60/direction
$ echo 1 > gpio60/value

1表示点亮LED1,0表示熄灭LED1。

5.7 读按键值

按键 CPU GPIO Linux索引号 物理索引号
KEY1 GPIOC10 74 36
KEY2 GPIOC12 76 38
KEY3 GPIOC9 73 40

以KEY1为例,执行以下命令读取按键值:

$ cd /sys/class/gpio/
$ echo 74 > export
$ echo in > gpio74/direction
$ cat gpio74/value

当KEY1按下时value=0,KEY1弹起时value=1。

5.8 测试AD转换

执行以下命令获得Channel0的AD转换值:

$ cd /modules
$ insmod pcf8591.ko
$ matrix-adc

通过旋转可调电阻可以改变AD转换值,运行效果如下:
matrix-cpt_kit_result_ad

5.9 测试指南针

执行以下命令获得当前方向:

$ matrix-compass

通过改变开发板的朝向可以获得不同的方向值,运行效果如下:
matrix-cpt_kit_result_cps

5.10 测试温度传感器

执行以下命令操作温度传感器:

$ cd /modules
$ insmod w1-gpio.ko
$ insmod w1-gpio-board.ko gpio=72
$ matrix-temp_sensor

gpio=72表示使用引脚GPIOC8,72是该引脚在Linux里的索引号。
运行效果如下:
matrix-temperature_sensor_result

5.11 测试红外接收头

执行以下命令操作红外接收头:

$ cd /modules
$ insmod matrix_ir_recv.ko gpio=92

gpio=92表示使用引脚GPIOC28,92是该引脚在Linux里的索引号。
成功加载驱动后,会在/dev/input/目录下生成一个event设备节点,这里假设生成的设备节点为event1。

开源软件input-utils可以读取event设备的数据,它的使用方法如下:

$ apt-get install input-utils
$ input-events 1

1表示读设备节点event1。

用一个普通的遥控器往模块发送数据,可看到运行效果如下:
matrix-ir_receiver_result

5.12 通过Python控制

6 与NanoPi连接使用

7 与Tiny4412连接使用

8 与RaspberryPi连接使用

9 与Arduino连接使用

10 相关资料