EBC Exercise 33 pygame

This is out of date. See EBC_Exercise_12a_2.4_TFT_LCD_display_via_SPI.

Pygame is a framework that can be used to create games, graphics, and more within python. It has the ability to draw sprites, primitives, and handle multiple surfaces. The back end conveniently can work on multiple platforms, but most importantly it can write directly to frame buffers. This has the benefit for ECE497 of being able to control the small SPI LCDs cleanly, without worrying about writing to memory locations directly and developing custom graphics libraries.

Unfortunately, pygame does not come installed for python3. It works great with python 2.7, but no pre-built packages are availible for python3. This raises an issue when python3 is required, such as when rcpy is to be used to read from encoders, drive servos, etc.

To solve this problem, the below shows a method that worked for me to get pygame built and installed.

Installing pygame for python3
From: https://askubuntu.com/questions/97717/how-can-i-get-pygame-for-python3

Note: Create a new folder to put installation in

bone$ sudo apt-get install mercurial python3-dev python3-numpy libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev bone$ sudo apt-get install libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev bone$ git clone https://bitbucket.org/pygame/pygame bone$ cd pygame bone$ python3 setup.py build #This will take a while, and may show many warnings bone$ sudo python3 setup.py install

from a python3 prompt, run  If this executes without error, pygame is installed correctly.

Alternate method for installing pygame for python3
From: https://www.pygame.org/wiki/GettingStarted

bone$ sudo apt install mercurial python3-dev python3-numpy libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev bone$ sudo apt install libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev bone$ sudo apt install libfreetype6-dev bone$ sudo python3 -m pip install pygame This takes almost 9 minutes.

From a python3 prompt, run  If this executes without error, pygame is installed correctly.

Using pygame with beaglebone SPI display
In order to actually use pygame, the below Adafruit tutorial is useful. It automatically grabs the correct frame buffer and uses it to display your graphics on the small SPI LCD Displays:

Pointing Pygame to the Framebuffer

Note that a few things need to be changed from the above:

1. the print statements are incorrect for python3, and need to be removed or modified.

2. a cursor is present, which can be annoying when there is no mouse connected. To disable, add  at around line 41 or so.