Difference between revisions of "Matrix - 2'8 SPI TFT"

From FriendlyELEC WiKi
Jump to: navigation, search
(Feb-25-2016)
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Matrix - SPI TFT/zh|查看中文]]
+
[[Matrix - 2'8 SPI TFT/zh|查看中文]]
  
 
==Introduction==
 
==Introduction==
[[File:Matrix-SPI_TFT.png|thumb|]]
+
[[File:Matrix-2'8_SPI_TFT.png|thumb|]]
*
+
* The Matrix - 2'8 SPI TFT module is a 2.8" TFT LCD with resistive touch. It uses the ST7789S IC and the XPT2046 resistive IC. The LCD's resolution is 320 * 240 and communicates via SPI.
 +
* Here is the spec:
 +
{| class="wikitable"
 +
|-
 +
|LCD Dimension||2.8"
 +
|-
 +
|Display Area|| 57.6mm * 43.2mm
 +
|-
 +
|Driver IC||ST7789S
 +
|-
 +
|Resolution||320 * 240(RGB)
 +
|-
 +
|Interface ||SPI
 +
|-
 +
|Supply Voltage ||5V
 +
|-
 +
|Backlight Voltage ||5V
 +
|-
 +
|Touch ||Resistive, Tempered glass LCD
 +
|-
 +
|}
 +
 
 
==Features==
 
==Features==
 
* PCB dimension(mm):
 
* PCB dimension(mm):
Line 13: Line 34:
 
|Pin || Description
 
|Pin || Description
 
|-
 
|-
| ||  
+
|GND        || Ground
 
|-
 
|-
 +
|5V        || Supply Voltage 5V
 +
|-
 +
|LED_EN    || Backlight
 +
|-
 +
|LCD_RESET  || Reset
 +
|-
 +
|LCD_D/C    || LCD data/command selection
 +
|-
 +
|LCD_CS    || LCD chip selection
 +
|-
 +
|SPICLK    || SPI clock
 +
|-
 +
|SPIMOSI    || SPI MOSI
 +
|-
 +
|SPIMISO    || SPI MISO
 +
|-
 +
|T_CS      || Touch chip selection
 +
|-
 +
|T_IRQ      || Touch IRQ
 +
|-
 
|}
 
|}
  
Line 20: Line 61:
  
 
==Download Matrix Source Code==
 
==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>
+
All the matrix modules' code samples are open source. They are maintained on GitHub - https://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>
 
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with。<br>
 
* The nanopi branch contains the matrix modules' code samples for the NanoPi
 
* The nanopi branch contains the matrix modules' code samples for the NanoPi
 +
* The nanopi2 branch contains the matrix modules' code samples for the NanoPi 2
 
* the tiny4412 branch contains the matrix modules' code samples for the Tiny4412
 
* the tiny4412 branch contains the matrix modules' code samples for the Tiny4412
 
* the raspberrypi branch contains the matrix modules' code samples for the RaspberryPi
 
* the raspberrypi branch contains the matrix modules' code samples for the RaspberryPi
Line 34: Line 76:
 
Clone the matrix code from GitHub
 
Clone the matrix code from GitHub
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ git clone git://github.com/friendlyarm/matrix.git
+
$ git clone https://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.
 
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
  
 +
==Connect to NanoPi 2==
 +
===Hardware Connection===
 +
Please refer to the following connection diagram to connect the Matrix-2'8 SPI_TFT to the NanoPi 2:<br>
 +
[[File:Matrix-2'8_SPI_TFT_nanopi2.jpg|frameless|600px|Matrix-2'8_SPI_TFT_nanopi2]]
 +
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-2'8_SPI_TFT || NanoPi 2
 +
|-
 +
|GND        || Pin6
 +
|-
 +
|5V        || Pin2
 +
|-
 +
|LED_EN    || Pin11
 +
|-
 +
|LCD_RESET  || Pin7
 +
|-
 +
|LCD_D/C    || Pin22
 +
|-
 +
|LCD_CS    || Pin24
 +
|-
 +
|SPICLK    || Pin23
 +
|-
 +
|SPIMOSI    || Pin19
 +
|-
 +
|SPIMISO    || Pin21
 +
|-
 +
|T_CS      || Pin26
 +
|-
 +
|T_IRQ      || Pin18
 +
|-
 +
|}
 +
 +
===Compile Test Program===
 +
Please login the matrix hub and enter the nanopi2 branch
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ git checkout nanopi2
 +
</syntaxhighlight>
 +
 +
Compile the Matrix code
 +
<syntaxhighlight lang="bash">
 +
$ make CROSS_COMPILE=arm-linux- clean
 +
$ make CROSS_COMPILE=arm-linux-
 +
$ make CROSS_COMPILE=arm-linux- install
 +
</syntaxhighlight>
 +
Note: please 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>
 +
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>
 +
 +
===Load Driver===
 +
Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.<br>
 +
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the driver, library and test program to the card.<br>
 +
<syntaxhighlight lang="bash">
 +
$ cp modules /media/rootfs/ -r
 +
$ cp install/lib/* /media/rootfs/lib/ -d
 +
$ cp install/usr/bin/* /media/rootfs/usr/bin/
 +
</syntaxhighlight>
 +
 +
Insert this TF card to your NanoPi 2, power on and run the following commands to load the driver<br>
 +
<syntaxhighlight lang="bash">
 +
$ cd /modules
 +
$ insmod fbtft_device.ko name=matrix-st7789s gpios=dc:97,reset:60,cs:94
 +
$ insmod matrix_ads7846.ko
 +
</syntaxhighlight>
 +
"fbtft_device" is the LCD's driver. "matrix_ads7846" is the touch driver. If they are successfully loaded the LCD will be cleared and reset.<br>
 +
 +
===Test LCD Display===
 +
Please run the following commands to set the display device to the Matrix-2'8_SPI_TFT:
 +
<syntaxhighlight lang="bash">
 +
$ sudo FRAMEBUFFER=/dev/fb-st7789s startx &
 +
</syntaxhighlight>
 +
"&" schedules the program to run background and you will see the following messages:<br>
 +
<syntaxhighlight lang="bash">
 +
Log file: "/var/log/Xorg.2.log"
 +
</syntaxhighlight>
 +
Here the message shows that the X window's DISPLAY value is 2.<br>
 +
 +
===Calibrate Touch===
 +
Please run the following commands to calibrate touch:
 +
<syntaxhighlight lang="bash">
 +
$ DISPLAY=:2.0 xinput_calibrator
 +
</syntaxhighlight>
 +
After you click on the four points highlighted on the LCD you will get calibration done and observe the following messages:
 +
<syntaxhighlight lang="bash">
 +
Section "InputClass"
 +
        Identifier      "calibration"
 +
        MatchProduct    "ADS7846 Touchscreen"
 +
        Option  "Calibration"  "196 3825 3887 358"
 +
        Option  "SwapAxes"      "0"
 +
EndSection
 +
</syntaxhighlight>
 +
Save these calibration data to the "/usr/share/X11/xorg.conf.d/99-calibration.conf" file and reboot the system your touch will be ready to go.
 
==Connect to NanoPi==
 
==Connect to NanoPi==
 
===Preparations===
 
===Preparations===
Line 51: Line 187:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===硬件连接===
+
===Hardware Connection===
参考下图连接模块Matrix-SPI_TFT和NanoPi <br>
+
Please refer to the following connection diagram to connect the Matrix-SPI_TFT to the NanoPi <br>
 
[[File:Matrix-SPI_TFT_nanopi.jpg|frameless|600px|Matrix-SPI_TFT_nanopi]]
 
[[File:Matrix-SPI_TFT_nanopi.jpg|frameless|600px|Matrix-SPI_TFT_nanopi]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 64: Line 200:
 
|}
 
|}
  
===加载驱动模块===
+
===Load Driver===
启动NanoPi,在其Debian的shell终端上加载芯片对应的驱动模块
+
Power on the NanoPi and run the following command in Debian's terminal to load drivers:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ modprobe fbtft_device name=matrix-spi_tft gpios=dc:161,reset:162,cs:163
 
$ modprobe fbtft_device name=matrix-spi_tft gpios=dc:161,reset:162,cs:163
 
$ modprobe matrix_ads7846
 
$ modprobe matrix_ads7846
 
</syntaxhighlight>
 
</syntaxhighlight>
模块fbtft_device是芯片ili9341的驱动,模块matrix_ads7846是芯片xpt2046的驱动
+
The "fbtft_device" module is the driver for the ili9341 chip and the "matrix_ads7846" module is the driver for the xpt2046 chip.
  
===安装软件包===
+
===Install Package===
在NanoPi的shell终端上安装软件包qtembedded和matrix-tslib
+
Please run the following commands in Debian's terminal to install "qtembedded" and "matrix-tslib"
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ apt-get update
 
$ apt-get update
Line 79: Line 215:
 
$ apt-get install matrix-tslib
 
$ apt-get install matrix-tslib
 
</syntaxhighlight>
 
</syntaxhighlight>
qtembedded是qt相关的库,matrix-tslib则用于触摸屏校准。
+
The "qtembedded" library is what qt applications rely on and the "matrix-tslib" library is what screen calibration relies on.
  
===运行测试程序===
+
===Run Test Program===
启动Qt应用程序
+
Start Qt applications
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ . /usr/bin/matrix-setqt4env
 
$ . /usr/bin/matrix-setqt4env
 
$ /usr/local/Trolltech/QtEmbedded-4.8.5-arm/examples/tetrix -qws
 
$ /usr/local/Trolltech/QtEmbedded-4.8.5-arm/examples/tetrix -qws
 
</syntaxhighlight>
 
</syntaxhighlight>
matrix-setqt4env用于设置环境变量,第一次运行该脚本时,会出现触摸校准的界面,根据提示点击5个点后完成校准。
+
The matrix-setqt4env script sets the environmental variables which Qt and tslib rely on. If it is run on a platform for the first time a screen calibration GUI will be launched. Users need to go through a five-point calibration process to calibrate the screen.
tetrix是一个qt4编写俄罗斯方块小游戏,点击start按钮后就可以开始娱乐了。
+
The tetrix application is a game developed in Qt4.
 +
 
 +
==Connect to Tiny4412==
 +
 
 +
==Connect to RaspberryPi==
  
==与Tiny4412连接使用==
+
==Connect to Arduino==
  
==与RaspberryPi连接使用==
+
==Resources==
  
==与Arduino连接使用==
+
==Update Log==
 +
===Feb-24-2016===
 +
* Added the driver's source code location in Section 5.2
  
==相关资料==
+
===Feb-25-2016===
 +
* Added details for Sections 1 and 2

Latest revision as of 03:09, 25 February 2016

查看中文

1 Introduction

  • The Matrix - 2'8 SPI TFT module is a 2.8" TFT LCD with resistive touch. It uses the ST7789S IC and the XPT2046 resistive IC. The LCD's resolution is 320 * 240 and communicates via SPI.
  • Here is the spec:
LCD Dimension 2.8"
Display Area 57.6mm * 43.2mm
Driver IC ST7789S
Resolution 320 * 240(RGB)
Interface SPI
Supply Voltage 5V
Backlight Voltage 5V
Touch Resistive, Tempered glass LCD

2 Features

  • PCB dimension(mm):

File:Matrix-SPI TFT PCB.png

  • Pin Description:
Pin Description
GND Ground
5V Supply Voltage 5V
LED_EN Backlight
LCD_RESET Reset
LCD_D/C LCD data/command selection
LCD_CS LCD chip selection
SPICLK SPI clock
SPIMOSI SPI MOSI
SPIMISO SPI MISO
T_CS Touch chip selection
T_IRQ Touch IRQ

3 Basic Device Operation

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 nanopi branch contains the matrix modules' code samples for the NanoPi
  • The nanopi2 branch contains the matrix modules' code samples for the NanoPi 2
  • the tiny4412 branch contains the matrix modules' code samples for the Tiny4412
  • the 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 https://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 Connect to NanoPi 2

5.1 Hardware Connection

Please refer to the following connection diagram to connect the Matrix-2'8 SPI_TFT to the NanoPi 2:
Matrix-2'8_SPI_TFT_nanopi2

Connection Details:

Matrix-2'8_SPI_TFT NanoPi 2
GND Pin6
5V Pin2
LED_EN Pin11
LCD_RESET Pin7
LCD_D/C Pin22
LCD_CS Pin24
SPICLK Pin23
SPIMOSI Pin19
SPIMISO Pin21
T_CS Pin26
T_IRQ Pin18

5.2 Compile Test Program

Please login the matrix hub and enter the nanopi2 branch

$ cd matrix
$ git checkout nanopi2

Compile the Matrix code

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

Note: please 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.
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" directory.
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git

5.3 Load Driver

Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the driver, library and test program to the card.

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

Insert this TF card to your NanoPi 2, power on and run the following commands to load the driver

$ cd /modules
$ insmod fbtft_device.ko name=matrix-st7789s gpios=dc:97,reset:60,cs:94
$ insmod matrix_ads7846.ko

"fbtft_device" is the LCD's driver. "matrix_ads7846" is the touch driver. If they are successfully loaded the LCD will be cleared and reset.

5.4 Test LCD Display

Please run the following commands to set the display device to the Matrix-2'8_SPI_TFT:

$ sudo FRAMEBUFFER=/dev/fb-st7789s startx &

"&" schedules the program to run background and you will see the following messages:

Log file: "/var/log/Xorg.2.log"

Here the message shows that the X window's DISPLAY value is 2.

5.5 Calibrate Touch

Please run the following commands to calibrate touch:

$ DISPLAY=:2.0 xinput_calibrator

After you click on the four points highlighted on the LCD you will get calibration done and observe the following messages:

Section "InputClass" 
        Identifier      "calibration" 
        MatchProduct    "ADS7846 Touchscreen" 
        Option  "Calibration"   "196 3825 3887 358" 
        Option  "SwapAxes"      "0" 
EndSection

Save these calibration data to the "/usr/share/X11/xorg.conf.d/99-calibration.conf" file and reboot the system your touch will be ready to go.

6 Connect to NanoPi

6.1 Preparations

Please install a Debian on a NanoPi and an appropriate cross compiler on a PC. Please refer to wiki:NanoPi
Compile a NanoPi kernel. Note: please use the kernel's source code from the nanopi-v4.1.y-matrix branch.

$ 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

6.2 Hardware Connection

Please refer to the following connection diagram to connect the Matrix-SPI_TFT to the NanoPi
Matrix-SPI_TFT_nanopi

Connection Details:

Matrix-SPI_TFT NanoPi

6.3 Load Driver

Power on the NanoPi and run the following command in Debian's terminal to load drivers:

$ modprobe fbtft_device name=matrix-spi_tft gpios=dc:161,reset:162,cs:163
$ modprobe matrix_ads7846

The "fbtft_device" module is the driver for the ili9341 chip and the "matrix_ads7846" module is the driver for the xpt2046 chip.

6.4 Install Package

Please run the following commands in Debian's terminal to install "qtembedded" and "matrix-tslib"

$ apt-get update
$ apt-get install qtembedded
$ apt-get install matrix-tslib

The "qtembedded" library is what qt applications rely on and the "matrix-tslib" library is what screen calibration relies on.

6.5 Run Test Program

Start Qt applications

$ . /usr/bin/matrix-setqt4env
$ /usr/local/Trolltech/QtEmbedded-4.8.5-arm/examples/tetrix -qws

The matrix-setqt4env script sets the environmental variables which Qt and tslib rely on. If it is run on a platform for the first time a screen calibration GUI will be launched. Users need to go through a five-point calibration process to calibrate the screen. The tetrix application is a game developed in Qt4.

7 Connect to Tiny4412

8 Connect to RaspberryPi

9 Connect to Arduino

10 Resources

11 Update Log

11.1 Feb-24-2016

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

11.2 Feb-25-2016

  • Added details for Sections 1 and 2