< async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"">

Sunday, July 20, 2014

Quickly test an IL9341 2.2 inch 2.2" SPI TFT display on Raspbmc media-center on raspberry pi

ADVERTISEMENT

It is a cool idea to hook up a small tft display to the raspberry pi for portable operations. I usually use raspbmc and here is a quick guide to setup an il9341 tft module to the gpio pins on the raspberry pi via spi. The module has 9 connections for the display and 4 for the SD card. Here we use the display pins.
In order to get the raspbmc/xbmc display on the pi, we use the fbtft driver by norto.

GPIO pins on the raspberry pi

TFT MODULE  

The module is 2.2" one with the following connections and an il9341 controller. Data sheet here and more details on the module can be read here.

  • SDO: Serial clock output
  • LED: 3.4V Power Supply pin
  • SCL: Serial clock input
  • SDA / SDI: Serial data input
  • DC: Data / Command selection
  • RST: Reset, Low level active
  • CS: Chip Selection, Low level active
  • GND: Ground
  • VDD33: 3.3V Power Supply pin

CONNECTION TO GPIO on PI


The connection to GPIO are summarised in the figure below. More on GPIO can be read at elinux.org/RPi_Low-level_peripherals

il9341 connection to GPIO on raspberry pi
Pin Mapping

+------------+--------+
|  LCD-PIN   |  GPIO  |
+------------+--------+
| SDO (MISO) | MISO   |
| LED        | GPIO18 |
| SCK        | SCLK   |
| SDI(MOSI)  | MOSI   |
| D/C        | GPIO24 |
| RESET      | GPIO25 |
| CS         | CE0    |
| GND        | GND    |
| VCC        | 3.3v   |
+------------+--------+
Note: Add a 50 ohm resistor to the LED pin

Software

1) Install Raspbmc (instruction can be seen at here)

2) ssh into the pi and follow the rest on the pi, one by one (user:pi password:raspberry)

sudo apt-get install ca-certificates -y
sudo apt-get install git-core binutils -y
sudo wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
sudo -E RPI_UPDATE_UNSUPPORTED=0 REPO_URI=https://github.com/notro/rpi-firmware BRANCH=next rpi-update
sudo reboot

3) Now edit the modules file by

sudo nano /etc/modules

and add

fbtft dma
fbtft_device name=adafruit22a rotate=270 speed=48000000 fps=50 debug=32

The debug can be later removed after debug (as it output stuff to dmesg and can be turned off later by adding  verbose=0 in place of debug

Now reboot the pi and we are ready to go. If you see a dark display, things are fine and need a small step to get the raspbmc in to the tft. But if the display stays white, something is wrong! may be the display name need to be changed to match the one you have.

Get /compil a small program called fbcp, which copies the framebuffer to the tft

sudo cp /boot/fbcp /usr/local/bin/
sudo chmod 755 /usr/local/bin/fbcp

and finally run fbcp and you have the raspbmc on the tft!!

fbcp&

fbcp can be found here  or a compiled version at here

wget https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true

Video Demo


A working solution can be watched after a break



44 comments:

  1. Very good ! Thanks. Now I'm looking to make this permanent and autostart at boot.

    ReplyDelete
  2. Thanks soo much. Any way to reduce the flickering ?

    ReplyDelete
    Replies
    1. You're welcome. try playing around with the frame rate and if i try low frame rate videos, they works fine. have a look at https://github.com/notro/fbtft/wiki/Performance to get an idea.

      Delete
  3. Thanks i'll try it out

    ReplyDelete
  4. Have you tried a dual screen setup with raspbmc showing the same image on both the small lcd and a hdmi screen?

    ReplyDelete
    Replies
    1. Haven't checked it. Ideally it should show on both the screens as fbcp is just copying the frames from fb0 to fb1. I will check it soon. See https://github.com/notro/fbtft/wiki/Framebuffer-use#framebuffer-mirroring

      Delete
    2. Any progress here?

      Delete
    3. Yes, it works on both the crenns :)

      Delete
  5. Thanks for your reply. I would like to be able to see XBMC on the small TFT when playing music so there's no need to turn my TV on then. My screen is on it's way so I'm curious how it will work.

    ReplyDelete
  6. I think it is possible to change the gpio pin used by lirc. There is some settings by which the deafult pin can be changed for tsop/ir receivers

    ReplyDelete

  7. Add this to your /etc/modules file:

    lirc_dev
    lirc_rpi gpio_in_pin=23 gpio_out_pin=22

    #tweak gpio_in_pin to suite your need

    ReplyDelete
  8. Yes, that worked! Adding the following to /etc/modules file did it!

    lirc_rpi gpio_in_pin=22

    Now I can try to set up the display.

    Thanks!

    ReplyDelete
  9. After step 2) of your tutorial there is a annoing noise (over HDMI) during the XBMC startup but also afterwards.
    After about 2 minutes of running the noise diappears.
    Is this "normal"?

    ReplyDelete
  10. Hi!, i have some problems on Step 2: when i installed all the certificates and i'm ready to start the sudo -E RPI_UPDATE_UNSUPPORTED=0 REPO_URI=https://github.com/notro/rpi-firmware BRANCH=next rpi-update
    command, my pi says there's an error: http://subefotos.com/ver/?b0fce8cb03df985daccaa22f48d81fe3o.jpg
    where's the problem, i rebooted the pi and reinstall the ca-certificates command, help please

    ReplyDelete
    Replies
    1. sudo apt-get install ntpdate
      sudo ntpdate -u ntp.ubuntu.com
      sudo apt-get install ca-certificates

      Delete
    2. Also do a sudo apt-get install curl

      if still fails , do a sudo apt-get update and fresh install of git-core

      Delete
    3. Hi!, i keep with the same problem, after all your commands i'm having the same error

      Delete
    4. As a last try,
      first do a
      sudo apt-get remove --purge git-core
      sudo apt-get update

      then
      sudo apt-get install git-core
      sudo apt-get install binutils

      and try again

      Delete
    5. Hi!!! i think with the sudo apt-get install curl the problem has gone!! hurray!!!!, i will tell if i solved it

      Delete
    6. New problem!!, when i finally install the screen on the Pi, and start XBMC the lcd don't work, i mean, the screen doesn't glow or anything, in Putty i type the commands: sudo cp /boot/fbcp /usr/local/bin/
      sudo chmod 755 /usr/local/bin/fbcp but an error says to me boot/fbcp isn't at system what i do now?

      Delete
    7. either compile fbcp or try
      wget https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true
      sudo cp fbcp /usr/local/bin/
      sudo chmod 755 usr/local/bin/fbcp

      Delete
    8. Hi, again, i did all the new steps, i downloaded manually FBCP from my Laptop, and copied to the pi with a pendrive, then in the pi with command line i moved to the usb drive, and i CP the fbcp to it's new location, maded an chmod and then tried again fbcp& but surprise!!, nah, don't do anything, i will check my homemade GPIO cable for any problem, but i don't think so, well, i will check around

      Delete
    9. Hi, again, i did all the new steps, i downloaded manually FBCP from my Laptop, and copied to the pi with a pendrive, then in the pi with command line i moved to the usb drive, and i CP the fbcp to it's new location, maded an chmod and then tried again fbcp& but surprise!!, nah, don't do anything, i will check my homemade GPIO cable for any problem, but i don't think so, well, i will check around

      Delete
    10. After the fourth checking of my wires and my wires setup onto the breadboard i can't find the solution, i'm trying now on Raspbian but in that OS i cannot even install ca-certificates Now i don't know what i should do, i'm starting to think that my pi is just broken or my LCD is the one who broke, or All the group is broken or malfunctioning, Ah! almost forgot it, in XBMC when i used fbcp& a number like 1360(maybe?) appeared onto the ssh terminal, does this mean anything?? Thanks for all your help

      Delete
    11. I dont know if you are familiar with arduinos/atmega328 micro controllers (see : http://forum.arduino.cc/index.php?topic=200126.0) . If you have one (working at 3.3v), you can test your lcd module by hooking on to it. When i tested mine for first time, the back light was turning on and remains white for a while and later turns black (while booting ) As you have changed the kernel etc, it is unlikely that there is problem with spi or other entities.

      Delete
    12. i have an arduino but as in rpi, i didn't found the way for use that screen, i will check your new link.

      Delete
    13. i have read your link and i didn't understand anything, my arduino is the UNO R3, i'm sorry but i only know a few concepts about Arduino, It's why I use more raspberry pi, works with Linux is an operating system and I understand much more than C, and also the GPIO is easier than the Digital outputs of the arduino

      Delete
  11. Guten Tag,
    thank you for your tutorial. I am not so familar with RasPi, programming and Linux, but nevertheless I would like to run my display with RasPi.
    I followed all steps, but "sudo cp /download/fbcp /usr/local/bin/" (I downloaded fbcp to my download-directoy) failed as follows :
    cp: call of stat for "/download/fcbp" not possible: file or directory not found.
    When I tried to copy "fcbp" from one directory to the other by using "strg+c" and "strg+v" the error message was as follows : "fcbp: error during opening of file "/usr/local/bin/fcbp":no authorization.
    Up to now the display remains dark – the wiring is correct.
    Thank you for help.
    Bernd.

    ReplyDelete
    Replies
    1. wget https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true

      the above command will download a copy of pre compiled fbcp

      if it succeed , typing ls will show fbcp among other files and then follow the same as above

      ie
      wget https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true
      sudo cp fbcp /usr/local/bin/
      sudo chmod 755 usr/local/bin/fbcp

      and after this you will be able to run

      fbcp&





      and double check all connections (loose contacts)




      Delete
    2. Thank you so much for your answer.
      In the meantime I made the following :
      -- checked ALL connections again
      -- start of PuTTY from my PC
      -- then all commands from „sudo apt-get install ca-certificates –y“ to
      „fbcp&“ are successfully done (fbcp was downloaded as compiled version)

      Nevertheless there was no reaction of the display.

      At least I tried your proposal :
      -- „wget https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true“
      result : ok
      -- sudo cp fbcp /usr/local/bin/
      result : file or directory not found

      Nevertheless I tried „fbcp&“ again with the following result :
      [2] 2662
      [1] Exit 127 fbcp

      If you have time and hope to help me, I would be glad to get another reply.

      Bernd.

      Delete
    3. Hmm seems wget download fbcp as fbcp?raw=true, so do the following

      wget https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true
      mv fbcp\?raw\=true fbcp
      sudo cp fbcp /usr/local/bin/


      otherwise download fbcp on a computer from above link ( https://github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true) and copy to raspberry pi/sd card

      Delete
    4. Hello,
      today I did my last effort to solve the problem.
      After „wget https:// github.com/riyas-org/rpi-fbcp/blob/master/fbcp?raw=true“
      the connoction was ok, but waiting for answer failed mit „404 Not Found“.

      Downloading fbcp on my Windows-Pc was successful. But I’m not able to copy
      this file to my RasPi, because I cannot access the PI-directory under NETWORK (Windows).
      The password is denied, even though I can acccess my RasPi with PuTTy; in
      this case my password is accepted.

      I think it will be the best, to dispose of my display now.
      Thank you for your help and
      Goodbye

      Bernd.

      Delete
    5. I performed all steps described here and my display was black as well. You have to enable SPI by adding dtparam=spi=on into config.txt

      sudo nano /boot/config.txt

      add dtparam=spi=on on the last line

      Delete
  12. Hi!, since i tried the last time i haven't got any image from the screen, but today i retried the installation of the screen on Raspbian, and all goes so well, but the screen doesn't show anything, or power the backlight, when i type on the command line, FBCP& the terminal, responds me with a [1] and a number, if i type again the fbcp& command the terminal, says me the SAME number but now with another line saying "Exit", ¿Where is my problem?. Thanks

    ReplyDelete
  13. Hi all

    This is a great tutorial. Is there any1 who used this screen as a secondary screen? I would like to use it with this way.
    If any1 has exeprience with this usage please feel free to share it with me.

    Regards
    Balazs

    ReplyDelete
  14. Hi, just wondering, as I cant find Raspbmc, so using an Image of OSMC... what are the step changes for this?

    Many thanks

    ReplyDelete
    Replies
    1. Hi!, to find Raspbmc, you just need to download NOOBS from Raspberry pi page, when you downloaded it, copy to SD and Ready to go

      Delete
  15. Will these steps work the same on Raspian in stead of Raspbmc or are there some things I should be aware of?

    ReplyDelete
    Replies
    1. I havent tried but my best guess is that it should work aslong as it can update the firmware from norto and has spi enabled

      Delete
  16. Yes, I can confirm that it works very well with Raspian as well thanks!

    ReplyDelete
  17. Thank you great tutorial. It got me started with the screen!

    ReplyDelete
  18. Hi, I was wondering if I could use this display to extend monitor in my PC. I'm asking this because I wanted to emulate a flight simulator Gauge in an small lcd monitor so I can accommodate it to the real world position on the panel.

    ReplyDelete
  19. why the 50 ohm resistor to the LED pin?

    ReplyDelete
    Replies
    1. Ideally there should be a current limiting resistor for the backlight and is often lacking in some of the ebay boards.So to be on safe side add a limiter between 10 og 50 ohm

      Delete