Difference between revisions of "EBC Exercise 33 pygame"

From eLinux.org
Jump to: navigation, search
m (Fixed Formatting)
m (fixed formatting)
Line 2: Line 2:
 
{{YoderHead}}
 
{{YoderHead}}
  
[https://www.pygame.org/news] (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.  
+
[https://www.pygame.org/news 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.
 
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.

Revision as of 09:53, 10 October 2017

thumb‎ Embedded Linux Class by Mark A. Yoder


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: [1]

sudo apt-get install mercurial python3-dev python3-numpy libav-tools \

   libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
   libsdl1.2-dev  libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev

hg clone https://bitbucket.org/pygame/pygame cd pygame python3 setup.py build sudo python3 setup.py install

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: [2]

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 pygame.mouse.set_visible(False) at around line 41 or so.




thumb‎ Embedded Linux Class by Mark A. Yoder