Uncategorized

ILI 9341 Touch Screen Kernel Building Notes

Asked 
Active 4 months ago
Viewed 1k times
3

It is possible to connect this LCD TFT screen to the raspberry 3 model B please ? I don’t understand the schematic for SPI connection. Any help is welcome thank you.

I have follow this answer but it does not help me.

Probably this library can help me for the driver, but I do not know how to connect that.

products

vma412_diagram

enter image description here

UPDATE PROGRESS: enter image description here vma412_diagram / datasheets – ILI9341

enter image description here

enter image description here data-sheet 74LVC_LVCH245A enter image description here

PCB screen side enter image description here

  • the SPI could be used only for the SD card …. what does the user manual say? – jsotola May 13 at 22:00
  • @jsotola, Thank you for your answers. Sorry for the “anymore” word , I’m not really English and I meant: “did not help me more than that”. For SPI I have read SPI can be use for preserve GPIO pin . For SPI I read that SPI can be used to preserve GPIO pins. But I start so I can also misinterpret. In the user manual I have not found any specification about SPI, except in the diagram. – Ephemeral May 14 at 7:30
  • @jsotola, Finally, the features of SPI are in manual mode: serial interface 3 lines / 4 lines, but only for SD cards? good question. – Ephemeral May 14 at 7:35
  • Many thanks for the very detailed signal routing chart. I am glad to have found one more missing jigsaw piece – the relation between the signals “DC” and “SCL”. I never have guessed that these two logical signals share the same physical line! – tlfong01 May 16 at 4:57   
  • @tlfong01, You’re welcome, for my part I can not understand why there is D/CX (SCL) but also WRX (D / CX), I suspect what is noted parenthetically to be the definitions for the serial line but for the moment I’m not sure. For SDO and SDA, I can not find the relationship on the pinout of my LCD. NC / SPI_SDA … where is this pin on my LCD screen 🙂 If I follow your CON1 and your last schema (Update 2019may15hkt1519) this seems to be SD_DO for SPI_SDO and SD_DI for SPI_SDA but I’m not sure for the moment. – Ephemeral May 16 at 7:41
  • There are two separate controlling methods: using 8 pins, Using SPI. If use SPI, only use wires in CON1. You module is an Arduino shield and every pin fits OK when you insert the shield. My module has the same situation. It is for STM32, so I need to double check my guesses are correct. For the 8 pin interface, you might like to take a look of a 4 pin interface for reference – Appendix D of the following raspberrypi.stackexchange.com/questions/98611/…, I am going to gym again. See you late evening or tomorrow. – tlfong01 May 16 at 7:49   
  • @jsotola, Thank you, I’m going to read this. Have a nice gym 🙂 – Ephemeral May 16 at 8:02
  • @jsotola, I have two units named U2 and U3, looking for U1 .. I tried to take off the screen to see if it was not below. Unfortunately I was too brutal and I broke the screen in two, that serve me as a lesson, I’m stupid. I did not find U1 and I do not see correctly where these famous pins SPI_SDA and SPI_SDO are physically connected at the level of the circuit . From your old answer you say ‘NC’ mean ‘No Connection’ , does this mean that there is no associated output pin? So is it probably possible to directly solder wires for SPI_SDA and SPI_SDO in this case. Waiting to buy the same screen . – Ephemeral May 16 at 12:25
  • Sorry to hear the bad news. But don’t buy the same touch screen again, because it is an Arduino shield and you are not using Arduino, are you? – tlfong01 May 16 at 13:00   
  • @jsotola, yes you are right , but I also use Arduino. I just have to make a choice. – Ephemeral May 16 at 13:09
  • @Ephemeral Ah, so you are using Arduino and Rpi at the same time. Then there is no problem buying an touch screen Arduino shield. Earlier I checked the Arduino 2560 pinout and found that the pins don’t seem to match exactly with the LCD shield. But I have not touched Arduino Uno or 2560 for a couple of years. So I guess my Arduino knowledge is a bit out of date. – tlfong01 May 18 at 13:39   
  • @tlfong01, Yes, sometimes I learn on arduino, sometimes on rpi. For LCD pins, this is not really a problem, because you can find in the library code the pin numbers in the source file (maybe not for all screens?). I used my screen with Arduino to do it like that and everything worked fine. But I just followed the pin numbers with a code that did not really help me understand SPI. – Ephemeral May 21 at 11:02

5

Question

ILI9341 SPI 2.8″ Touch TFT LCD Arduino Shield

Rpi3B+ OK? How to connect?

Short Answer

Yes, it is OK to use the ILI9341 Arduino Shield for Rpi. The following is the wiring for using SPI mode interface.

ILI9341 Touch LCD Arduino/STM32 Shield to Rpi3B+ GPIO Wiring V0.1

ici9341 wiring

The following GitHub driver by juj has a comprehensive tutorial with detail description on the following:

  1. Introduction to the touch LCD driver.
  2. How to build the kernel module.

ILI9341 Touch LCD SPI Based Driver for Rpi3B+ stretch – juj 2019apr19

Some research notes and more references can be found in the long answer below.

Long Answer

Contents

Research Notes …

Figures …

References …

Appendices …

Research Notes

First thing first – check out spec and schematic.

touch screen 01

touch screen 2

The OP’s question is clear, and his reference web links are very good. So I followed his links and jot down a picture of the wiring.

touch screen wiring

The drive/library referred by the OP is a couple of years old, and no longer supported. So I need to google to catch up.

so I googled and found everybody is using the ILI19341 de facto standard. That means all ILI19341 are more or less the same and can be used with any such driver. I searched AliExpress and found the following typical goody.

ILI19341 touch screen

I google to catch up and the the found the following tutorial looking good.

ILI9341 Raspberry Pi guide – pi0cket 2019feb26

It gives a clear wiring (see Reference below), and the detailed instructions and commands to switch between HDMI mon and TFT screen.

One thing I am not that happy is the following:

You cannot use HDMI monitor and TFT touch screen at the same time!

Figures

Fig 1 Fig 1 - Touch LCD

Fig 2 Fig 2 - 2.8" touch screen pinout

Fig 3 Fig 3 - STM32 LCD Module 32 pin socket

Fig 4 Fig 4 - Rpi spi pinout

Fig 5 Fig 5 - Touch lcd wiring

Fig 6 Fig 6 - Touch screen module

Fig 7 – Con 1 – 9 pin x 2 = 18 pin Connector

Con 1 - 9 pin x 2 = 18 pin connector

Fig 8 – vm412 Touch LCD signals

velleman lcd 01

Fig 9 – stm32 Touch LCD signals

stm32 signals

Fig 10 Arduino Mega 2650 Pinout

Arduino Mega 2650 Pinout

arduino mega 2650 shield

Now I have my US$300, 4 channel, 50MHz, 1GSa/s Digital Storage Oscilloscope Rigol Ds1504Z ready to check out the SPI waveforms.

Fig 11 – SPI waveform

spi waveform

Fig 12 – SPI Signal Routing Cable

spi signal cable

Now I am testing Back Lit. I found that my guess was wrong. The pin BL is not LED anode, but Low level on. I used a multimeter to check that the current from BL pin to ground is 2.5mA. So I now guess BL is not a signal pin but a pull down LED power pin, sinking 2.5 mA to switch on Back Lit LED. Anyway, I am glad that now I have a huge size 2.8″ white LED! 🙂

bak lit test

Now I have loaded the kernel module fbtft_device name = ici9341. I can also listed the module. But I found that I made another wrong guess – four SPI signal wires are not enough, I also need 3 more GPIO wires RST, DC (select Data or Command mode), and BL (back lit), … 😦

fbtft_module_loading

My ICI9341 SPI cable V2.0 does not work, because the signals Touch LCD RST and RS (Register Select) or DC (Data Command Mode Select) are missing. So I have assembled V3.0.

ici9341 cable

I will be using GPIO Gen 0 (BCM17), 1 (BCM27) , 2(BCM22) for the ICI9341, so the modprobe command is:

modprobe fbtft_device name=ici9341 gpios=reset:17,dc:27,led:22

Update 2019may19hkt1520

I just found that my Rpi3B+ with Raspbian 2019Apr version already has a fbtft kernel driver which sadly is not the ici I ma using. So I need to build a driver myself. I found the following driver tutorial but found it very tedious. Trying it this Sunday afternoon might corrupt my Rpi OS. So I decided to stall this part of project for a couple of days, to allow me to go through slowly the tutorial.

A blazing fast display driver for SPI-based LCD displays for Raspberry Pi A, B, 2, 3 and Zero

I am still studying the juj driver document on how to build the kernel module. I have no experience of building any linux kernel module. So I am going very slowly. I have also diverted to a test on controlling a LCD 20 char x 4 line module using 4 bit interface. This is a warm up and memory refreshing exercise in case I need to switch from SPI mode to 8bit mode for faster response.

lcd2004 test 1

LCD2004 2

/ to continue, …

References

Velleman SPI 2.8″ TFT LCD ILI9341 Spec – Velleman

Velleman SPI 2.8″ TFT LCD ILI9341 Schematic – Velleman

Wiring up a ILI9341 TFT Touch Screen – Rpi Forum Discussion 2015

Wiring up a ILI9341 TFT Touch Screen Post – Lallafa 2013

MI0283QT-9A 320x240px Touch Screen with ILI9341 display driver spec – Mikroe

MI0283QT-9A 320x240px Touch Screen with ILI9341 display driver User Manual – Mikroe

Linux Framebuffer drivers for small TFT LCD display modules (development ceased) – 2015

AliExpress 240 x 320 2.8″ SPI TFT LCD Touch Screen (Touch Pen) ILI9341 White SPI Series – US$10

AliExpress ILI9341 240 x 320 2.8″ SPI TFT LCD Touch Screen

2.8 ” SPI, 36.72mm W X 48.96 mm H, 8.5 x 4.8 cm/ Conductive element: active matrix a-si TFT IC Driver: ILI9341, Backlight: White LED

Visualization direction: 6 hours, Depth of color: 262 K / 65 K

Resolution): 240 RGB * 320 5V, use with 3.3 V or 5 V logic

ILI9341 Raspberry Pi guide – pi0cket 2019feb26

Moduole Power = 3V3

Wiring (BCM Mode)

SCK – Rpi SPI Clok (GPIO 11)

MISO – Rpi SPI MISO (GPIO 9)

MOSI – Rpi SPI MOSI (GPIO 10)

CS – Rpi SPI CE0N (GPIO 8)

RST – Rpi GPIO GEN 6 (GPIO 25)

BL – Rpi GPIO GEN 1 (GPIO 18)

DC – Rpi GPIO GEN 5 (GPIO 24)

Touch Screen VMA412 User Manual

Ilitek ILI9341 a-Si TFT LCD Driver 240 RGB x 320 262K Color V1.02

AdaFruit 2.8″ TFT LCD with Touchscreen Breakout Board User Guide

AdaFruit 2.8″ TFT LCD with Touchscreen Breakout Board Pin Out / SPI Mode

AdaFruit 2.8″ TFT LCD with Touchscreen Breakout Board w/MicroSD Socket – ILI9341 US$30

A blazing fast display driver for SPI-based LCD displays for Raspberry Pi A, B, 2, 3 and Zero – Last commit 2019Apr

User Manual For 2.8″ TFT Touch Shield for Arduino with Resistive Touch Screen (TF028)

User Manual For 2.8″ TFT Touch Shield for Arduino with Resistive Touch Screen

ILI9341 Raspberry Pi guide – pi0cket 2019feb26

Wave Share 3.2 inch 320×240 Touch LCD User Manua

SPI – Serial Peripheral Interface Pinout

SPI – raspberrypi.org

Using SPI0 and SPI1

WaveShare 5″ Touch LCD Setup Question and tlfong01’s Answer

WaveShare 7″ Touch LCD Setup Question and tlfong01’s Answer

Hitachi HD44780U Dot Matrix LCD Controller Datasheet Rev. 0.0

HD44780U 4×20 LCD Controller 4-bit Interface Python Program Example

AdaFruit PiTFT Plus Assembled 320×240 2.8″ TFT + Resistive Touchscreen $35 https://www.adafruit.com/product/2298

[SPI Loopback test] How to check if SPI is enabled and functional on Raspi 3b+?

Arduino Meaga 2560 Pinout

Why is SPI not working on any of my Raspis?

Display and controller Experiments – WeatherStation+

ILI9341 -Single-chip SOC driver for a-TFT liquid crystal display with resolution of 240RGBx320 dots.

ILI9341 supports parallel and serial peripheral interface (SPI). The moving picture area can be specified in internal GRAM by window address function. The specified window area can be updated selectively, so that moving picture can be displayed simultaneously independent of still picture area.

Using the AdaFruit 2.8 inch TFT display

fbtft_device GitHub – Will Price Sep 18, 2017

fbtft_device has device information for all the displays it supports, with default values. These values can be changed with module parameters.

Usage

There is one required module parameter, and that is name. It specifies which display (device) to register.

eg, sudo modprobe fbtft_device name=adafruit22

fbtft_device prints information to the kernel log

$ dmesg

fbtft_device: SPI devices registered: fbtft_device: spidev spi0.0 500kHz 8 bits mode=0x00 fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00

fbtft_device: ‘fb’ Platform devices registered: fbtft_device:
bcm2708_fb id=-1 pdata? no

fbtft_device: Deleting spi0.0

fbtft_device: GPIOS used by ‘adafruit22’: fbtft_device: ‘reset’ = GPIO25 fbtft_device: ‘led’ = GPIO23

fbtft_device: SPI devices registered: fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00 fbtft_device: fb_hx8340bn spi0.0 32000kHz 8 bits mode=0x00

graphics fb1: fb_hx8340bn frame buffer, 176×220, 75 KiB video memory, 16 KiB buffer memory, fps=20, spi0.0 at 32 MHz

First it lists all SPI devices and platform devices with a name containing ‘fb’ (framebuffer) that was registered before the module was loaded.

Then it deletes the device connected to spi0.0 (spidev) so we can register a new one.

Then it tells which GPIOs that is associated with this display.

Then it lists which SPI devices that are currently registered (spi0.0 means SPI busnum.chipselect).

And lastly the driver is loaded.

Supported devices

The special name list will write the supported devices to the kernel log.

sudo modprobe fbtft_device name=list; dmesg | tail -30

ERROR: could not insert ‘fbtft_device’: Operation canceled

fbtft_device: SPI devices registered: fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00 fbtft_device: ‘fb’ Platform devices registered: fbtft_device: bcm2708_fb id=-1 pdata? no fbtft_device: Supported displays: fbtft_device: adafruit18 fbtft_device: adafruit18_green fbtft_device: adafruit22 …

Parameters

busnum SPI bus number (default=0)

cs SPI chip select (default=0)

speed SPI speed in Hz (default varies among displays)

mode SPI mode (default SPI_MODE_0)

rotate Angle to rotate display counter clockwise: 0, 90, 180, 270

bgr Set BGR bit (supported by some drivers). Use if Red and Blue is swapped. Default is don’t touch.

> gpios Most displays need GPIOs for signaling. To simplify configuration, pins with the same functionality has been given names:

reset – Hardware reset

dc – Data/Command (sometimes called RS) [no wonder I got confused – tlfong01]

led – Backlight

> GPIO only displays [not used for SPI mode tlfong01 2019may18]

db00-15 – Databus

cs – Chip Select

wr – Write strobe

fbtft_device have default values for these pin names (a few don’t). The values can be changed with the gpios parameter. This is a comma separated array of pin/signal names and GPIO numbers. gpios=pin_name:gpio_number[,pin_name:gpio_number]

When overriding the defaults using gpios, all gpios must be specified.

Example showing the default gpio values of itdb28fb

> modprobe fbtft_device name=itdb28 gpios=reset:17,dc:1,wr:0,cs:21,db00:9,db01:11

Explaining Linux kernel modules, devices, and drivers

How to setup an LCD Touch Screen on Rpi – Waveshare

Raspberry PI OLED Library Driver

Appendices

Appendix A – ILI9341 Touch Screen Wiring V0.1 tlfong01 2019oct19hkt2217

ili9341 wiring

  • Thank you very much, I have already seen (hover over) all the tutorials provided but I do not understand how to connect “BL” (from ILI9341 Raspberry Pi guide – pi0cket) for example, I can not see it on the diagram (that you kindly highlighted me). Another remark is for pin SPI_SDO, SPI_SDA there is NC / SPI_, the NC scares me … – Ephemeral May 14 at 7:47
  • Ah, no problem. Perhaps I can draw a diagram to explain it better. – tlfong01 May 14 at 7:50   
  • It would be with great pleasure but I would not want to take up too much of your time. – Ephemeral May 14 at 7:51
  • Ah I see your problem. They are using hard to understand geek language. “NC” usually means “No Connection”. “BL” usually means “Back Lit”. The module has 4 white LED which can back light the background. No problem for me drawing anything. It take me very littl time. – tlfong01 May 14 at 8:20   
  • Thank you very much again for all your explanations. I think at this time, GPIO9 -> LCD_RD , GPIO10 -> LCD_WR, GPIO8 -> LCD_CS but for RESET and RS (Register Select ?) no definition on pinout shematic for the raspberry. Maybe these pins can be any pin gpio (declared in the driver source file?) raspberry pinout – Ephemeral May 14 at 8:27
  • Yes, it is confusing. I am trying to make some educational guesses, as in the coming updated picture. BTW, my answer is not just for you, but a follow up of other touch screens answers for newbies. For me it is just like a jigsaw puzzle, which is my hobby of playing electronics toys. Now I am going to meet a friend for supper. So see you tomorrow. Have a nice project! – tlfong01 May 14 at 8:59   
  • I can not thank you enough. Have a good dinner. I will work with the elements of your updated answer. – Ephemeral May 14 at 9:07
  • @Ephemeral I googled more touch LCD user guides and found all of them similar. So I have drafted a basic wiring diagram as updated. I think you can find the SPI signal lines at the Arduino shield plug CON 1, and one more CS signal line for micro SD card at the bottom side of the PCB. (Main SPI line are shared between LCD and sd card。) I could not find any BL line in your board. Perhaps your board has no back lit. Or you can try searching for it. I am going to gym then supper. See you late evening or tomorrow. Good luck! – tlfong01 May 15 at 7:29   
  • Again, thank you very much. For ‘BL’, I can see LEDA on pin 16 and LEDK on pin 17 (LEDA seems to be the only pin needed on the diagram), but I really do not understand the pin mapping for the final board. And then what would LEDK be used for ? … Have a good supper. – Ephemeral May 15 at 9:01
  • For SPI it means that I can not make a display request and a request to access the SD card at the same time ? Can we say that this works in half-duplex ? – Ephemeral May 15 at 9:22
  • Ah. LEDA means LED Anode, which means Positive. LEDK means LED Cathode, Negative side. So if you connect Anode (to be very safe, use 1k in series to limit current) to 3V3, and Cathode to Gnd, the back lit LED should light up. – tlfong01 May 15 at 10:29   
  • Ah, let us consider one device at a time. A SPI operation is almost always write and read at the same time, sort of mouth talking and ears listening at the same time. So it is full duplex, if you wish to use this term half/full duplex. Same for SD card, you write and read at the same time. Now you can read a byte from LCD and then write the byte to SD. But this has nothing to do with half or full duplex, I think, not very sure, again. You need to wiki for SPI, and also google Rpi newbit tutorials on SPI and I2C etc, to clarify. – tlfong01 May 15 at 10:35   
  • Thank you for all your clarifications. For the lighting the schema of the diodes watches a schema with a pin named ‘A’ and 4 Leds in parallel. It seemed to me that LEDA could have been used for this pin. Yes, you’re right, I’m going to read the ILI9341 data sheet provided by adafruit to read a bit more about SPI and I2C. But I do not know if it will allow me to find the connection for the spi clock, the back light etc … because everything is on the diagram of the screen finally. – Ephemeral May 15 at 10:46
  • Ah, the four most important spi wires you want is located in CON1. Look for this plug in my picture updated yesterday. – tlfong01 May 15 at 11:14   
  • Yes I will look even more carefully. After thinking, in fact, I should not rather look at your last schema which is much clearer for me and my level because I can not find a match for the clock for example apart from in your last scheme. If I understand what you told me before then I just miss the pin for the back light. But I am beginning to doubt my ability to properly configure the outputs in the driver source since I can not easily understand a simple connection and associate the technical terms. – Ephemeral May 15 at 11:23
  • Yes, I agree. If you cannot guess the meaning of terms BL = Back Lit, and LEDA, LEDK mean Anode and Cathode, then it is very difficult to do it all by yourself. But then if you read AdaFruit’s newbie tutorials on touch LCD, you might find things not that difficult. Or if you search Amazon’s touch LCD for Rpi, you might also find it easy. Your problem is now you want to change an Arduino shield to Rpi compatible, that is indeed very difficult. Suggestion: watch what I do this weekend, then decide to give up for now and come back later, after learning SPI basics. – tlfong01 May 15 at 11:42   
  • Thank you. I understand you, but I am simply confused because I have a little experience of programming with SPI. On the original vellman diagram, you have highlighted 5 ‘wires’, on the diagram of lallafa’s 4 ‘wires’ are highlighted. When I program an ATtiny (which happened to me once or twice) with SPI I use 4 ‘wires’. I do not try to make all the features of the screen, touchscreen, access to the SD card etc but rather to do a simple SPI link is to write text to start,I have this screen on hand so I thought maybe it’s possible to just connect to the raspberry. – Ephemeral May 15 at 11:57
  • Ah, you only need 4 wires for the LCD – CLK, MOSI, MISO, CS. The 5th wire is CS for the SD card. So actually we don’t need to bother the SD card, or even the back lit, just play with LCD to start with. As I said, you can just sit back, do nothing and watch how do I test the very basic SPI thing over the weekend, … – tlfong01 May 15 at 12:45   
  • Thank you very much for everything. – Ephemeral May 15 at 12:55
  • @Ephemeral Now I have added Fig 8, 9 for vm412 and stm32 signals. Next is to test BL and then SPI. – tlfong01 May 17 at 1:43   
  • yes I see that . I follow your updates. This is a complete LCD tut’s 🙂 – Ephemeral May 17 at 19:51
  • @Ephemeral Ah you remind me another user commenting that my very long answer to his short questions is like a blog. My reply was that I used to hesitate to give an answer which I am not very sure correct. So I usually say, pretty sure, 60% chance and so on. If it happens that the question is related to my own project, then I would do some research as in this touch LCD case. Actually I am at the same time researching on 20 char x 4 line LCD with buttons. I know 20×4 LCD very well, but only using Arduino C++, so I need to try on Rpi python to make sure, otherwise I am misleading the OP. – tlfong01 May 18 at 13:48   
  • Some clarifications: (1) There are two types of ILI9341 Arduino shields, one for Arduino Uno or similar, another for Mega 2560. You board is for 2560, which might not fit if you are using Uno. (2) There are two SPI wiring methods, 3 wires method does not use DC signal. (3) MISO is always not used. The details can be found in the driver tutorial below: github.com/juj/fbcp-ili9341 – tlfong01 May 19 at 7:31    
  • Thank you very much again for all this information. – Ephemeral May 21 at 11:14
  • You are welcome. I am still studying the juj driver document on how to build the kernel module. I have no experience of building any linux kernel module. So I am going very slowly. I have also diverted to a test on controlling a LCD 20 char x 4 line module using 4 bit interface. This is a warm up and memory refreshing exercise in case I need to switch from SPI mode to 8bit mode for faster response. You might like to come back from time to time to see my progress. – tlfong01 May 21 at 13:03   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: