Raspberry Pi + Adafruit PiTFT Display

Recently we had the chance to work on an interesting standalone Raspberry Pi project for a client. For user interaction we decided on good ol' Lady Ada's 2.8" PiTFT display with capacitive touch. 

At first glance everything looked remarkably easy, as things often do. Adafruit's team was kind enough to offer an easy way to download a new kernel for the display, along with a few prebuilt Raspbian Jessie images for quickly testing out the product. We ordered a few up and quickly ran into an issue : the display worked great, but touch input was not working. If you're seeing something similar, you can verify that you're not going insane by checking the values using 'evtest' :

  1. sudo nano /etc/udev/rules.d/95-ft6206.rules
  2. sudo rmmod ft6x06_ts
  3. sudo modprobe ft6x06_ts
  4. ls -l /dev/input/touchscreen
  5. sudo evtest /dev/input/touchscreen

At the end, you should be able to move your fingers across the touch screen and watch the raw values on screen change. If not, you're in the same boat we were. Adafruit's support team mentioned that they were seeing similar issues with the touchscreen that were not being supplied enough voltage. Check your 3.3V and 5V rails and make sure that they're not dipping too low. If so, you more than likely need a beefier power supply. This fixed up our first round of issues.

While Adafruit's Jessie images are great for a general purpose Pi, our Pi would only be doing one thing : running a custom python app with Kivy. As usual the internet had beat us to this idea, and a prebuilt Kivy installation running on top of PipaOS had already been built out. Perfect! PipaOS is very lightweight, boots up in about 4 seconds, and has a power fault tolerant file system. Our customer would get a very fast device, that wouldn't mind having the power rug pulled out from underneath its feet. 

If you're looking to get the KivyPie image up and running with a PiTFT here's what we needed to do.

  1. Write the KivyPie Image to our Pi's SD card
  2. After booting up, run 'sudo pipaos-config' and go ahead and expand the file system.

  3. After rebooting, open up /usr/bin/raspi-config' in your favorite editor, and change out any references to 'pi' in the autologin section to 'sysop' (the default KivyPie username). 
  4. Rerun 'sudo pipaos-config' and tell the Pi to automatically login to the console, but don't start the GUI.
  5. Walk through Adafruit's helper installation (raspberrypi-bootloader, and adafruit-pitft-helper)
  6. Be sure to specify the home directory when running the PiTFT Helper, 'adafruit-pitft-helper -t 28c -u /home/sysop'
  7. Run 'sudo apt-get install xserver-xord-video-fbdev'
  8. Run 'export FRAMEBUFFER=/dev/fb1'
  9. Install rpi-fbcp : https://github.com/tasanakorn/rpi-fbcp
  10. Edit '/home/sysop/.kivy/config.ini' and change the resolution to 320 x 240, change the [input] section to match : 
    [input]
    
    mouse = mouse
    
    %(name)s = probesysfs,provider=hidinput
    
    pitft = mtdev,/dev/input/touchscreen,max_position_x=240,max_position_y=320,invert_y=0,invert_x=1,rotation=90
  11. Now open '/boot/config.txt' in your favorite editor and add : 

    hdmi_force_hotplug=1
    
    hdmi_group=2
    
    hdmi_mode=87
    
    hdmi_cvt=320 240 60 1 0 0 0
  12. Reboot!

  13. Run 'fbcp &'

  14. You should now see the console text on the Pi display, you can run your Kivy app now and it should show up beautifully!