Blog

Raspberry Pi + Adafruit PiTFT + XBMC

Introduction

This is a project I’m working on for quite some time. A few months ago I got my Raspberry Pi delivered. My initial thought was to use it as a multimedia PC connected to the TV in the living room. This has been working as a charm for quite some time. But then I decided to take it to the next level. What if I just want to listen to the music I still need to turn on the TV. So I’ve bought an LCD touchscreen from adafruit. That goes into the GPIO slot on raspi. This way I can have fully operational XBMC running withouth having to turn on the TV to controll it. What’s even more awesome I shouldn’t need a mouse or a keyboard to controll it because the LCD comes with a touchscreen so I can even take it with me if I want to and all I need is just the small box.

I had so much trouble getting the screen to work with any of the linux distros that have the XBMC already running. I didn’t want to install XBMC on top of a Raspbian because this distribution comes with so many stuff in it that it makes the CPU cry. I want something lightweight and fast. The idea is to have both screens (TV and LCD) to display the same image as a clone on a dual monitor setup.

The next issue I’ve had is that I found most of the setups pretty harsh to do while most of the solutions to get the driver working involved recompiling both the kernel and the XBMC. But with a little digging I found a perfect solution for me that’s quick and easy to do. What’s even better it can be teoreticaly done on any of the ditros with XBMC in it. I’m currently running Raspbmc but I want to try Xbian as well maybe Openelec whenever I find some time to do so.

UPDATE: For whatever reason this doesn’t work on Xbian 1.0 BETA 2 for now.

There is no complete tutorial for this I had to improvise a bit go get it running. So this is what I had to do.

Installation steps
  1. install raspbmc as instructed on the official page
  2. SSH into the system
  3. make a directory to work in 
     mkdir rpilcd 
  4. jump inside it
     cd rpilcd 
  5. from the adafruit site download just the kernel and the driver. You can choose the released driver or the new beta driver with DMA (I will be using the new beta driver for this purpose). For the beta driver do:
     wget http://adafruit-download.s3.amazonaws.com/raspberrypi-bootloader-adafruit-20140227-1.deb 
    or for the stable driver:
     wget http://adafruit-download.s3.amazonaws.com/raspberrypi-bootloader-adafruit-112613.deb 
  6. next extract the downloaded .deb file
     ar p raspberrypi-bootloader-adafruit-20140227-1.deb data.tar.gz | tar zx 
  7. we need to remove the usr directory
     rm -rf usr 
  8. go into the boot directory and delete everything but the kernel.img
     cd boot 
  9.  rm bootcode.bin 
  10.  rm fixup.dat 
  11.  rm fixup_cd.dat 
  12.  rm fixup_x.dat 
  13.  rm kernel_emergency.img 
  14.  rm start.elf 
  15.  rm start_cd.elf 
  16.  rm start_x.elf 
  17. now this is optional but I strongly recomend to do this. We need to rename the kernel.img file to something else so we can jump back to the original one if something goes wrong. So:
     mv kernel.img kern_lcd.img 
  18. go back to the working directory
     cd ~/rpilcd 
  19. create a new tar file to use as an installation file for the new kernel and drivers
     tar cvzf pitftkern.tgz lib boot 
    you can store this file somewhere outside of the pi if you want to to use it anytime you want to reinstall the pi completly
  20. copy the newly created file to the root directory
     cp pitftkern.tgz / 
  21. now extract the file
     cd /; sudo tar xvzf pitftkern.tgz 
  22. next thing we need to tell the pi to boot using the new kernel
     sudo nano /boot/config.txt 
  23. and change the line kernel=kernel.img to kernel=kern_lcd.img
  24. we are done with the kernel and driver installation so we just need to reboot
     sudo reboot 
  25. after the PI starts ssh back to it
  26. now we can continue the installation as shown in the adafruit tutorial 
      sudo nano /etc/modules 
  27. and add two lines:
    spi-bcm2708
    fbtft_device 
  28. for the modprobe configuration do
     sudo nano /etc/modprobe.d/adafruit.conf 
  29. add this line: options fbtft_device name=adafruitts rotate=90 frequency=32000000
  30. Next I’m not sure if this is necessary because I don’t have the touchscreen working yet properly but anyhow:
     sudo mkdir /etc/X11/xorg.conf.d; sudo nano /etc/X11/xorg.conf.d/99-calibration.conf 
  31. add this to the file

    Section "InputClass"

    Identifier "calibration"

    MatchProduct "stmpe-ts"

    Option "Calibration" "3800 200 200 3800"

    Option "SwapAxes" "1"

    EndSection

  32. next we need to install a small tool called fbcp that is able to copy the main screen which is the HDMI output to the newly installed framebuffer that is the LCD display so we have a working double header. I have already a bin file made from this so you just need to download it.
     cd ~; wget http://sernato.sk/?ddownload=5192 
  33. extract the fbcp
     tar xvf fbcp.tar 
  34. we need to make the fbcp application to start after the xbmc starts so we can see the xbmc screen on the LCD for this there is a nice tool that can run shell commands from the xbmc called xbmc callbacks
     wget https://github.com/pilluli/service.xbmc.callbacks/archive/v0.5.zip 
  35. now we need to install these. For that go into the XBMC screen using the HDMI output for now. And install the plugin from the zip file we just downloaded: service.xbmc.callbacks-0.5.xip
  36. After it’s installed go to programs and settings for the XBMC callbacks program. You will see a screen showing a couple of callbacks that you can use to run commands. The one we are interested in is XBMC Starts.
  37. press enter on that setting and it will open a filemanager now navigate to your home folder and choose the fbcp file and confirm.
  38. after this everything is set and we can restart again.
  39. when the XBMC starts it should show up on the main HDMI screen as well as on the LCD screen.

As of now this is the most I’ve been able to achieve currently I’m looking for a solution to get the touchscreen working. It’s seems it’s not calibrated and I’m trying all the solutions I can find online but with no success so far. And I’m avoiding the once that involve any sort of compiling there has to be a solution for this and I WILL FIND IT 😉

Feel free to ask questions and I will try to help you out with your issues if I can.

Now this is a proof that It’s working for me.

 

25 Comments

  1. Alex

    Hi,
    Thanks for the tuto, I arrived here through a forum post talking about fbcp.
    I installed my pitft following adafruit’s tutorial, I was able to make XBMC show on my piTFT thanks to you and fbcp, and I do have tactile input calibrated nicely.

    But, as soon as I start XBMC the calibration goes crazy, and only a part of the screen reacts, I searched a long time for a calibration that could work but still have no clue.

    Did you make any progress about the touchscreen on your side?
    Thanks.

    1. mufty

      Hi Alex

      Right now I’m basically stuck at pretty much the same point as you are only small part of screen reacts. My guess is that I would need to do a fix for this directly in the fbtft driver even adafruit themself are using their own version of this: https://github.com/notro/fbtft

      But I’m not very good at C thought I’m a developer but I don’t specialize in C in that matter. I can understand the code when I read it but if I had to change something I might not be successful. I tried to fix it thought but was not able to build it. I have a friend of mine that I want to ask for help as he is pretty good in this kind of stuff. Unfortunately he will be able to take a look at this in about a month because he is abroad right now.

  2. kelly

    Hello !
    I can’t tar the deb file (step 6). I’m with ssh connexion but nothing happend. Have you an idea ? No problem with previous step.

    1. mufty

      Hi

      Are there any errors in the console when entering the command? Or what’s the output of that command?

  3. Chris

    Hi, I have the same problem as Kelly….here’s the output….

    tar: This does not look like a tar archive
    tar: Skipping to next header
    26.1MB 0:00:01 [17.1MB/s] [========================>] 100%
    tar: Exiting with failure status due to previous errors

    It’s the same problem with both the stable and beta debs. Any ideas?

    Cheers.

    1. mufty

      OK seems I might have it wrong there can you try this:

      ar -vx raspberrypi-bootloader-adafruit-20140227-1.deb

      or

      dpkg -x raspberrypi-bootloader-adafruit-20140227-1.deb ~/rpilcd

      Let me know if eighter of these worked so I can update the guide.

      1. mufty

        BTW I’m sorry if there are some things that doesn’t work I didn’t write the guide as I was actualy doing it but rather after I did it so I might have forget something. But hopefuly I can fix it with your help.

    2. carson

      When i type tar cvsf pitftkern.tgz lib boot it says this: tar: –same-order option cannot be used with -c. Can i fix that?

  4. Michael

    Hey, I seem to be having a similar problem to the one Chris was having, and at first I thought entering the dpkg version had fixed the problem, but after it finishes, and I type in “cd data”, it says “-bash: cd: data: No such file or directory”
    Sorry if there’s an easy fix to this staring me in the face, I’m a bit new to the RasPi scene and I don’t quite know what I’m doing just yet.

    1. mufty

      Check if there is a usr and boot directory after the dpkg by running ls command. If so you can skip step 7 and continue. For whatever reason on some systems the deb file doesn’t have a data directory only the content of the data directory.

      Or you can try:

      dpkg -x raspberrypi-bootloader-adafruit-20140227-1.deb ~/rpilcd/data

      Let me know if that worked.

  5. Kyar

    Hello, I tried but when I launch the program with the PiTFT I don’t have the raspbian screen in my display only on HDMI and I have a poor quality now.
    I launch the program with “xbmc” in my pitft terminal.

    Do you use the pitft with an other program as MAME? Because it’s very hard to use the PiTFT as a real TV.

    Thanks!

    1. mufty

      Hey Kyar

      You use the PiTFT with the genuine raspbian distribution do you? If so you don’t need my guide for it to work. If I understand you right you have a raspbian installed on your system not Raspbmc (or any of the preinstalled XBMC distributions) because you want to run other applications not just XBMC. Until I figured out how to make the PiTFT to work on Raspbian distro I’ve had it running on raspbian but as I remember it worked fine just by following the official guide from adafruit, then I installed xbmc over the raspbian and start it with “xbmc” from terminal just like you describe.

      But with that approach you would need to run the fbcp everytime after the xbmc starts either by hand or by using the plugin service.xbmc.callbacks as I am and making it to run fbcp on xbmc startup to be able to see the xbmc on the touchscreen as well as the HDMI output.

      I believe the same goes to any other application like MAME I didn’t try it thought but you should be able to do it. If you have the fbcp you can copy the main framebuffer which is the HDMI output onto the touchscreen for any program but you need to do it in the correct order first run the program and then start the fbcp to copy the screen output.

      The only issue that you may see is if the application you are trying to run doesn’t use framebuffer to render the screen but xserver (like the raspbian desktop) but if that’s so you don’t need to fbcp at all and just follow the official guide to get the xserver running from that point you should see all xserver applications running on the touchscreen.

  6. Kyar

    Thanks for your answer. I installed fbcp and now I launch xbmc with “fbcp & xbmc” but the touchscreen doesn’t works and when I want quit xbmc I use “escape” and “exit” but raspberry bug and doesn’t want to quit the page…

    1. mufty

      Well as you can see in my answer to Alex’s question above I don’t have the touchscreen working in xbmc yet.

      Regarding the exit I assume that it only looks like it didn’t exit the xbmc so you still see the xbmc on the LCD as if it was running but in fact it’s not that’s only the fbcp running still and it’s displaying the last screen it displayed before you closed xbmc so the xbmc doesn’t run but the fbcp is. You need to stop fbcp as well to stop it.

  7. Alex W

    Hey I just used step 6 but it seemed to just go down a layer and go blank, I only just did this so it could just be taking a while to extract but I just wanted to know if it was suppose to happen or not? Even though this is a old thread I hope you will still reply 🙂

    1. mufty

      Hi. You should have no problem extracting the deb file. But yes it may take a while in some cases. BTW you are right of this guide being pretty old.

      I can’t guarantee that it will work with newer version of xbmc there is also a new version of the adafruit driver. Also the official kernel now supports pitft driver by default so this guide might be obsolete.

      Anyway I’m currently working on a different approach which is using yocto and bitbake to make a personalized linux build with xbmc and pitft. I’m not sure if I will make a guide for this yet. Because even in early stages I had to do stuff that applies only to my setup so it’s highly unlikely that it’ll work for anyone else. But if you put the time into it and figure out how yocto works you might be able to do the same as well but it takes much more effort than this guide did and you need experience with linux and c++ builds. Which not everyone has.

  8. Alex W

    well im pretty new to having a pi, like I got it the other day :/ so atm im relying on guides like this one. all I want is the screen to work so it’s not obsolete, atm I don’t really care about the touchscreen. do you reckon you could make another guide like this but more updated? If you do I would really appreciate it!

    1. mufty

      I’m aware that there is many ppl like you around that only rely on guides. I’m sorry but I don’t think I will be making another updated guide. All of the PI related guides do tend to change a lot over the time. There is a new PI2 that I don’t have the XBMC has been also updated the recent version is KODI. There is another XBMC branch called OSMC which I really like but I wasn’t able make the screen work with it at all (they use much heavily modified kernel then the original XBMC). What I might do is release the stuff I work on currently as an opensource project but as I’ve said it would need to be modified for each user. Primary due to a network setup. And I would need help from somebody more experienced with yocto them I am at the moment.

  9. Ralph

    Thanks for this great guide. Before I embark on what might be a very long project, would this work with KODI? I know XBMC became kodi, just wondering if you see any major roadblocks?
    thanks in advance.
    -rp

    1. mufty

      It is working with kodi as well. In fact I might post a new guide for xbian I got it working there a few weeks ago and It was much easier then all this here. The latest kernel has the pitft support build in so a lot of this guide is made obsolete by that.

      1. Ralph

        Thank you for the reply. Im stuck on step 6. 🙁
        I did a fresh install from NOOBS, apt-get update, apt-get upgrade, the wget work, file downloaded, the tar command, doesn’t do anything. No cpu usage, just get the newline, after hitting return and nothing. (tried on both releases)
        Suggestion?

        1. mufty

          Try this:

          raspberrypi-bootloader-adafruit-20140227-1.deb data.tar.gz | tar zx

          Let me know if this helps. I have updated the guide accordingly.

          1. Ralph

            That worked…thanks.
            Got to step 21…
            boot/
            boot/kern_lcd.img
            tar: boot/kern_lcd.img: Cannot change ownership to uid 1000, gid 1000: Operation not permitted
            tar: boot: Cannot change ownership to uid 1000, gid 1000: Operation not permitted
            tar: Exiting with failure status due to previous errors

            Sorry to be a bother, maybe this is too complex for a noob linux guy. My background is mainframes…you know, the big iron…lol

      2. Wim

        Have you by any chance had the time to get the procedure together for that newest Xbian an a PiTFT?

  10. Ralph

    Hey mufty. Disregard last reply. I found the fix. I needed –no-same-owner added to tar command.
    https://www.krenger.ch/blog/linux-tar-cannot-change-ownership-to-permission-denied/

Leave a Reply