Raspberry-ili9340spi
ILI9340 SPI TFT Library for Raspberry Pi.
This may works with other boards like OrangePi/NanoPi.
You can show a chart to ILI9340/ILI9341/ILI9163C/ST7735 SPI TFT.
You can choose bmc2835 library/WiringPi library.
I tested these TFT.
1.44 inch 128x128 ST7735
1.44 inch 128x128 ILI9163C
1.8 inch 128x160 ST7735
2.2 inch 240x320 ILI9340
2.4 inch 240x320 ILI9341
2.4 inch 240x320 ILI9341
Wirering
TFT | Rpi/Opi | |
---|---|---|
VCC | -- | 3.3V |
GND | -- | GND |
CS | -- | Pin#24(SPI CS0) |
RES | -- | Pin#5(*) |
D/C | -- | Pin#3(*) |
MOSI | -- | Pin#19(SPI MOSI) |
SCK | -- | Pin#23(SPI SCLK) |
LED | -- | 3.3V |
MISO | -- | N/C |
(*) You can change any pin.
#define D_C 2 // GPIO2=Pin#3
#define RES 3 // GPIO3=Pin#5
Build using bcm2835 library
RPi Only, Very fast
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.56.tar.gz
tar zxvf bcm2835-1.56.tar.gz
cd bcm2835-1.56
./configure
make
sudo make check
sudo make install
* This tool require 1.56 or later.
* Because this tool uses bcm2835_spi_write.
cd $HOME
git clone https://github.com/nopnop2002/Raspberry-ili9340spi
cd Raspberry-ili9340spi
cc -o demo demo.c fontx.c ili9340.c -lbcm2835 -lm -DBCM
Build using WiringPi library
This project uses the wiringPiSetupGpio() function to initialize GPIOs.
Then use the wiringPiSPISetup() function to initialize the SPI.
If you use it on a board other than the RPI board, you may need to change the GPIO number.
#define D_C 2 // GPIO2=Pin#3
#define RES 3 // GPIO3=Pin#5
#define C_S 8 // GPIO8=Pin#24
As far as I know, there are these libraries.
- WiringPi for OrangePi
- WiringPi for BananaPi
- WiringPi for NanoPi
- WiringPi for Pine-64
git clone https://github.com/nopnop2002/Raspberry-ili9340spi
cd Raspberry-ili9340spi
cc -o demo demo.c fontx.c ili9340.c -lwiringPi -lm -DWPI
Note:
Opi have only 1 SPI.
OPi-PC have CE0 and GPIO8.
OPi ZERO have CE1 and GPIO8.
TFT resolution and GRAM offset
TFT resolution is set to tft.conf.
If your TFT doesn't use a memory from 0th address in GRAM, It use GRAM offset which set to tft.conf.
This library can use ILI9341 TFT.
From left 2.8" ILI9341,2.4" ILI9341, 2.2" ILI9340.
This library can use ILI9163C/ST7735 TFT.
From left to right.
2.2 inch 240x320 ILI9340
1.44 inch 128x128 ST7735
1.44 inch 128x128 ILI9163C
1.8 inch 128x160 ST7735
XPT2046 Touch Screen
There is a TFT equipped with XPT2046.
A library of XPT2046 Touch Screen is included in this library.
I ported from here.
There is a TFT equipped with HR2046.
XPT2046 and HR2046 are very similar. But HR2046 does not work properly.
Wirering
TFT | Rpi | ||
---|---|---|---|
T_IRQ | -- | Pin#22 | (*1) |
T_OUT | -- | Pin#21(SPI MISO) | (*2) |
T_DIN | -- | Pin#19(SPI MOSI) | (*2) |
T_CS | -- | Pin#26(SPI CE1) | |
T_CLK | -- | Pin#23(SPI SCLK) | (*2) |
MISO | -- | N/C | |
LED | -- | 3.3V | |
SCK | -- | Pin#23(SPI SCLK) | (*2) |
MOSI | -- | Pin#19(SPI MOSI) | (*2) |
D/C | -- | Pin#3 | (*1) |
RES | -- | Pin#5 | (*1) |
CS | -- | Pin#24(SPI CS0) | |
GND | -- | GND | |
VCC | -- | 3.3V |
(*1) You can change any pin.
(*2) SPI is shared by TFT and XPT2046.
cc -o xpt xpt.c xpt2046.c -lbcm2835
sudo ./xpt
If you touch screen, point will show.
cc -o touch touch.c fontx.c ili9340.c xpt2046.c -lbcm2835 -lm -DBCM
sudo ./touch
If you touch area, number will show.