[Guide] ili9341 SPI TFT Screen on Retropie

Various user-contributed guides for hardware-related things
Post Reply
User avatar
moosepr
Posts: 524
Joined: Wed Jan 25, 2017 6:18 am
Has thanked: 69 times
Been thanked: 241 times
Contact:

[Guide] ili9341 SPI TFT Screen on Retropie

Post by moosepr » Sat Jan 28, 2017 2:27 pm

Hi Folks,

Image

I know SPI screens get a bad write up, they are not as fast, they suffer with 'tearing' and they use up your gpio pins, but they have lots of benefits too!

You can get a screen that is ready to roll with no modifying for somewhere in the region of $6, they come in a range of sizes (2.2",2.4",2.8") and you can chop away excess PCB and get it rather small. They have a few more wires, and some slight software tweaks are needed to get them to work. So first off, lets get the wires connected.

Display--------Raspberry Pi
BL--------------pin 12 (GPIO 18)
SCK------------pin 23 (GPIO 11)
MISO----------pin 21 (GPIO 9)
MOSI----------pin 19 (GPIO 10)
CS--------------pin 24 (GPIO 8)
RST------------pin 22 (GPIO 25)
D/C-------------pin 18 (GPIO 24)
VIN-------------pin 17 (3.3v)
GND-----------pin 20 (GND)

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. I am assuming we are working on a fresh install of RetroPie

First off we need to change a few "system" settings on the pi. If you exit emulationstation and in the terminal type

Code: Select all

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

Code: Select all

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

Code: Select all

con2fbmap 1 1
your console should now be on your tft screen!!

Image
hurrahh

you can always type

Code: Select all

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,

Code: Select all

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.

Code: Select all

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

Code: Select all

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)

Code: Select all

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

Code: Select all

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

Code: Select all

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

Code: Select all

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!!!

Image

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

Code: Select all

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

Code: Select all

fbcp&
the ampersand (&) needs to be there to make sure our fbcp program runs in the background. our file will now look something like

Code: Select all

_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!!! :D
Last edited by moosepr on Sun Jan 29, 2017 1:37 pm, edited 1 time in total.
Get a small cheep LCD in your project https://www.sudomod.com/forum/viewtopic.php?f=22&t=2312
Wrap it all round a battery https://www.sudomod.com/forum/viewtopic.php?f=13&t=2292
Or use a custom PCB to make it really small https://www.sudomod.com/forum/viewtopic.php?f=13&t=2512
or make it really really really really tiny!! https://www.sudomod.com/forum/viewtopic.php?f=13&t=2919

User avatar
Mischief
Posts: 225
Joined: Sat May 21, 2016 7:50 am
Location: Wolverhampton, UK
Has thanked: 29 times
Been thanked: 69 times

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by Mischief » Sun Jan 29, 2017 12:11 pm

Nice guide, but some of your images are not showing.

User avatar
moosepr
Posts: 524
Joined: Wed Jan 25, 2017 6:18 am
Has thanked: 69 times
Been thanked: 241 times
Contact:

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by moosepr » Sun Jan 29, 2017 1:18 pm

Mischief wrote:Nice guide, but some of your images are not showing.
That's a pain! The images are not really critical to the guide, but I will get them shifted

edit : i have moved the images to imgur now, should behave better :)
Get a small cheep LCD in your project https://www.sudomod.com/forum/viewtopic.php?f=22&t=2312
Wrap it all round a battery https://www.sudomod.com/forum/viewtopic.php?f=13&t=2292
Or use a custom PCB to make it really small https://www.sudomod.com/forum/viewtopic.php?f=13&t=2512
or make it really really really really tiny!! https://www.sudomod.com/forum/viewtopic.php?f=13&t=2919

kamon
Posts: 32
Joined: Wed Jul 27, 2016 7:29 pm
Has thanked: 4 times
Been thanked: 4 times

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by kamon » Tue Jan 31, 2017 1:56 pm

Thanks for the info!
:D

Looking to put one of these(the 2.8" version) to use in a GBA build.
Do you know where exactly I can chop the PCB to cut down the size of it?

Maybe a picture with some black lines to get an idea?

Thank you!

User avatar
moosepr
Posts: 524
Joined: Wed Jan 25, 2017 6:18 am
Has thanked: 69 times
Been thanked: 241 times
Contact:

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by moosepr » Tue Jan 31, 2017 2:34 pm

kamon wrote:Thanks for the info!
:D

Looking to put one of these(the 2.8" version) to use in a GBA build.
Do you know where exactly I can chop the PCB to cut down the size of it?

Maybe a picture with some black lines to get an idea?

Thank you!
Basically you can prise up the screen, they are stuck down with double sided tape. Then you will be presented with this

Image

The screen is now covering the pins (there is no getting away from those I'm afraid) but pretty much anything to the right of the ribbon cable should be able to be scrapped. You might need to check the other side of the board, the only one I have is stuck down.

You can see the traces really well on these boards, so they are easy to check. Each of the pins will go to one of the 18 pins in the ribbon cable. 18-15 are for touch 14-10 are for the backlight 9-1 power and control the screen (this should help you trace the pins)
Get a small cheep LCD in your project https://www.sudomod.com/forum/viewtopic.php?f=22&t=2312
Wrap it all round a battery https://www.sudomod.com/forum/viewtopic.php?f=13&t=2292
Or use a custom PCB to make it really small https://www.sudomod.com/forum/viewtopic.php?f=13&t=2512
or make it really really really really tiny!! https://www.sudomod.com/forum/viewtopic.php?f=13&t=2919

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2985
Joined: Thu May 05, 2016 8:33 am
Location: Rogers, AR
Has thanked: 1459 times
Been thanked: 3114 times

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by Helder » Tue Jan 31, 2017 2:48 pm

Nice! I was looking into testing some of these screens, so in the initial start of the guide you have the Pi connected to an HDMI monitor?
Chat with me and other members On Discord

Don't contact me about obtaining my board files (as you will not get them). If my Boards or PCB Kits are sold out, they will be restocked as soon as I can get them and there is demand for them. You can join the mailing list on my Website to be notified when they are available.


Helder's Game Tech Website

We will not support any cloned work so don't come to us with technical issues to resolve, go talk to the cloner for help.

User avatar
moosepr
Posts: 524
Joined: Wed Jan 25, 2017 6:18 am
Has thanked: 69 times
Been thanked: 241 times
Contact:

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by moosepr » Tue Jan 31, 2017 3:01 pm

Helder wrote:Nice! I was looking into testing some of these screens, so in the initial start of the guide you have the Pi connected to an HDMI monitor?
Yeah I started with an Motorola atrix lapdock (screen and keyboard in a laptop form factor with USB and HDMI) you can in theory use it as a second screen displaying box art or system status.

I have been playing with getting away from the oversized PCB, the ribbon pretty much has raw SPI pins

Image

I just have a resistor for backlight brightness control to keep things really simple, but it works!

Image
Get a small cheep LCD in your project https://www.sudomod.com/forum/viewtopic.php?f=22&t=2312
Wrap it all round a battery https://www.sudomod.com/forum/viewtopic.php?f=13&t=2292
Or use a custom PCB to make it really small https://www.sudomod.com/forum/viewtopic.php?f=13&t=2512
or make it really really really really tiny!! https://www.sudomod.com/forum/viewtopic.php?f=13&t=2919

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2985
Joined: Thu May 05, 2016 8:33 am
Location: Rogers, AR
Has thanked: 1459 times
Been thanked: 3114 times

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by Helder » Tue Jan 31, 2017 3:30 pm

moosepr wrote:
Helder wrote:Nice! I was looking into testing some of these screens, so in the initial start of the guide you have the Pi connected to an HDMI monitor?
Yeah I started with an Motorola atrix lapdock (screen and keyboard in a laptop form factor with USB and HDMI) you can in theory use it as a second screen displaying box art or system status.

I have been playing with getting away from the oversized PCB, the ribbon pretty much has raw SPI pins

Image

I just have a resistor for backlight brightness control to keep things really simple, but it works!

Image
Nice! I was looking into finding the simplest screen with the least amount of pins on the ribbon. I don't want to bother with 40 or 50 pins when only a handful are used.

Do you have any recommendations? also do you need anything else to make these screens work? I'm trying to find schematics of those boards that come with the screens but there seem to be many variants of the same thing. Do you use a voltage regulator for the screen and backlight?
Chat with me and other members On Discord

Don't contact me about obtaining my board files (as you will not get them). If my Boards or PCB Kits are sold out, they will be restocked as soon as I can get them and there is demand for them. You can join the mailing list on my Website to be notified when they are available.


Helder's Game Tech Website

We will not support any cloned work so don't come to us with technical issues to resolve, go talk to the cloner for help.

User avatar
moosepr
Posts: 524
Joined: Wed Jan 25, 2017 6:18 am
Has thanked: 69 times
Been thanked: 241 times
Contact:

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by moosepr » Tue Jan 31, 2017 3:56 pm

Helder wrote:Do you have any recommendations? also do you need anything else to make these screens work? I'm trying to find schematics of those boards that come with the screens but there seem to be many variants of the same thing. Do you use a voltage regulator for the screen and backlight?
These are the only ones I have tried, all the others seem to have lots of pins.

The screen seems to run well on 3.3v, so I'm just powering it from the Pi's 3.3v pin with no issues. Just added a resistor for the backlight, but it does work straight to 3.3v too!

I couldn't find a schematic for the boards, just a pinout http://s.aliexpress.com/JvYJvAre, so I risked the $2 on my test boards. The 2.4 and 2.8 screens have an extra 4 pins for touch

I have a board where the screen ribbon goes straight to the pi gpio with no other components, I'm just waiting on China Post for some naked screens to test it with (been 4 weeks already :( )
Get a small cheep LCD in your project https://www.sudomod.com/forum/viewtopic.php?f=22&t=2312
Wrap it all round a battery https://www.sudomod.com/forum/viewtopic.php?f=13&t=2292
Or use a custom PCB to make it really small https://www.sudomod.com/forum/viewtopic.php?f=13&t=2512
or make it really really really really tiny!! https://www.sudomod.com/forum/viewtopic.php?f=13&t=2919

kamon
Posts: 32
Joined: Wed Jul 27, 2016 7:29 pm
Has thanked: 4 times
Been thanked: 4 times

Re: [Guide] ili9341 SPI TFT Screen on Retropie

Post by kamon » Tue Jan 31, 2017 4:29 pm

Thank you!!! Ordered one to play with :).

Also, guys.
I followed a project awhile back where someone built a custom PCB for the GBA and used a 3.2" SPI LCD, here's a link to the GH project:

https://github.com/Ryzee119/GBA_Emulator-by-Ryzee119-/

Not only did they release their Eagle files so you can get the boards made, but they also had a SPI breakout board over on oshpark: https://oshpark.com/shared_projects/9tH3I87q

Looks like everything would work.

And, even more interesting to me:
@Helder, would you ever be interested in turning his Eagle files into a more robust one that at least has X/Y buttons, and preferably with some of the features your AIO has?

Maybe even for commission :)?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest