Before diving in to this tutorial, first follow the setup instructions for your PiTFT. Make sure to choose the correct guide particularly for resistive vs capacitive displays and carefully follow the section on PiTFT Pygame Tips - in particular you really need SDL 1.2!

You can also grab all the tutorial source code from git:

git clone https://github.com/jerbly/tutorials.git

To test the display you can run through these steps in the python console:

pi@raspberrypi ~ $ sudo python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> import os
>>> os.putenv('SDL_FBDEV', '/dev/fb1')
>>> pygame.init()
(6, 0)
>>> lcd = pygame.display.set_mode((320, 240))
>>> lcd.fill((255,0,0))
<rect(0, 0, 320, 240)>
>>> pygame.display.update()
>>> pygame.mouse.set_visible(False)
1
>>> lcd.fill((0,0,0))
<rect(0, 0, 320, 240)>
>>> pygame.display.update()

you may also need to try

os.putenv('SDL_VIDEODRIVER', 'fbcon') # Force PyGame to PiTFT

in the beginning, if pygame isn't appearing

You can also run this test (with a one second sleep) from the pygamelcd project:

sudo python test1.py

OK now you're ready!

This guide was first published on Feb 01, 2016. It was last updated on Mar 08, 2024.

This page (Overview) was last updated on Mar 08, 2024.

Text editor powered by tinymce.