ili9341 tft screen guide
-
ok guys, so you all know im an advocate of the ili9341 tft screens. Sure they are not without there flaws, but they are small, light and most importantly they are cheap!! So lets see how to make one work
Firstly I am assuming you have a fully working build of retropie freshly installed, and you have a screen wired as thus.
Display - Raspberry Pi
BL - pin 12
SCK - pin 23
MISO - pin 21
MOSI - pin 19
CS - pin 24
RST - pin 22
D/C - pin 18
VIN - pin 17
GND - pin 20Once you have a screen wired up, you can get on to the good bits
-
So now your pi is wired up, get your pi up and running with a keyboard and a screen, we need to start to get things working...
First off we need to change a few "system" settings on the pi. If you exit emulationstation and in the terminal type
sudo raspi-config
you will be presented with a blue screen and some options. in the advanced options you want to make sure overscan is disabled, and spi is enabled. use the arrow keys to select 'finish' and when prompted, reboot
once you are back up and running again, exit emulationstation once more and get yourself back to a terminal and type
sudo modprobe fbtft_device custom name=fb_ili9341 gpios=reset:25,dc:24,led:18 speed=16000000 bgr=1
the backlight should kick in on your tft screen. This is a good sign!!
now try typing
con2fbmap 1 1
your console should now be on your tft screen!!
you can always type
con2fbmap 1 0
to get the console back onto your normal screen. Go make your self a drink, you are halfway there!!
-
OK so we have proven the screen works, we need to make things more interesting. Firstly, you might have noticed that if you were to restart the pi, you will need to type your modprobe line in again to restart the screen. now this is no fun for a tiny handheld, so lets make the screen work every time.
First off we need to tell the pi to load the screen module at startup. We can do this by editing a file. type this,
sudo nano /etc/modules
this will fire up the text editor nano, with the modules file, so we can add in the bits we need. Add in the following 2 lines, below what is already there.
spi-bcm2835 fbtft_device
Press ctrl+o to save (press enter to confirm file name) and press ctrl+x to close the text editor
You need to add the spi line, so that we are sure the connection port is ready for use, and then the tft device starts the screen. but we need to add in all of those extra settings that we had to type before. there is a place for this and it is another file. type this
sudo nano /etc/modprobe.d/fbtft.conf
and inside the text editor, we neeed to add the following information (the file will probably be empty)
options fbtft_device name=fb_ili9341 gpios=reset:25,dc:24,led:18 speed=16000000 bgr=1 rotate=90 custom=1
Again we need to press ctrl+o to save (press enter to confirm file name) and press ctrl+x to close the text editor
now try restarting the pi (I normally type sudo init 6) and let the pi restart. Fingers crossed your screen will light during the reboot process. If not, check your files for typo's, and check dmesg for any errors.
If your screen is illuminated, you can check it is ready to roll with the good old
con2fbmap 1 1
to check you have the console there on the screen. Now the screen is working on every boot, we can make it do more things....
-
So the screen works, and it loads every time, we now just need to make it do something fun. The main sticking point with these screens is that there is no real 'graphics acceleration' we can use with them. The only way it will work is to install some software to basically copy the current screen over to the ili9341 screen. now this is quite a simple task, we just need to type the following in a fresh terminal
sudo apt-get install cmake git clone https://github.com/tasanakorn/rpi-fbcp cd rpi-fbcp/ mkdir build cd build/ cmake .. make sudo install fbcp /usr/local/bin/fbcp
this will install the software to copy the contents of the screen over to the tft. We now need to test this, you want to type
fbcp
and if all has gone well, the contents of your normal screen will appear on your ili9341 screen!!! hurrah!! i think its time to grab yourself a beer!!!
we just need to make this happen every time we boot. This is actually simple to do. We just need to add our newly installed program into the pi's autostart config file. To do this, we need to fire up the terminal again
sudo nano /etc/rc.local
within this file you will see there is already some text in there. You need to make an addition between the ip address code and the exit line. You need to add in the line
fbcp&
the ampersand (&) needs to be there to make sure our fbcp program runs in the background. our file will now look something like
_IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi fbcp& exit 0
there may be some comments up above, but these are just there for information. If you restart the pi now, you will see the screen initialise, and then it should show the splash screen after a few seconds. before you know it, you will have your pi up and rolling on the tft screen!! Top job!!!
-
Tweaking
So i have been playing around with some of the parameters on the screen to try and get the most out of it.
Firsly there is an FPS setting, which allows you to specify how long the driver waits before sending the next image to the screen. Now this defaults at 20 for most screens, and this is far too slow!! you can in theory set this as high as you want. but in practice you wont get anything above 60fps (i have tried ALOT!)
Speed
Now if you are aiming for higher FPS you will need to make things happen faster. In my initial guide i set the speed at 16000000. now this works, and is reliable, but it limits what you can get on the screen. In theory the faster the better, but there are limits. If you go too fast, the screen wont be able to cope, and you will end up with a garbled mess.
Now i have managed to get as high as 99000000 while still keeping things visible. There are many things that can impact what the screen can cope with, such as cable length and external interference.
So if you push it to the max, magic happens (you might need to squint a bit)
Its still not perfect, there is 'tearing' on the screen, but it is pretty good for a cheap screen
-
@moosepr said in ili9341 tft screen guide:
ili9341 tft screens
Does this work with any other screens such as a 1.8TFT SPI 128*160 V1.1 screen or only with the ili9341
-
@retroprogrammer they are similar, but have dufferent driver chips, so need slightly different config
-
I followed the first few steps, typed con2fbmap 1 1, and my console appeared on my screen. Then I followed the next steps and edited /etc/modules and /etc/modprobe.d/fbtft.config, and rebooted. My screen lit up during boot. I typed con2fbmap 1 1 at the prompt, and the console went away from my HDMI monitor, but nothing appeared on my screen. I typed con2fbmap 1 0 to get the console back. I triple checked all the files, and rebooted. I typed con2fbmap 1 1, and again, nothing on the screen, but the console is gone from HDMI. I typed con2fbmap 1 0 to get back to HDMI. I comment out the lines in /etc/modules and deleted /etc/modprobe.d/fbtft.conf. I rebooted, and now when I type out the whole thing from the start, the screen lights up, but the console never appears there. It's weird because it was working before I edited the files. Any ideas?
Thanks!
-
Hi !!
Super useful.....thanks.
But ili9341 is now included in RASPBIAN STRETCH kernel, so I took off from the fbcp installation and did work.But I noticed that the screen refresh rate is too slow.
In this new scenario, where do I do the tweaks you suggest?
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.