pygame + arduino + lolshield = pylolgraph
(Video Note: The flickering you see is based on the camera capture, it doesn’t actually do that…)
There are two main parts to the library:
- The Python module pylolgraph.py for sending graphics to the Arduino\lolshield.
- The Arduino sketch pylolgraph.pde for receiving serial data, and displaying it.
- It requires the lolshield library.
And, I’ve made an example Pygame application illustrating usage:
You can also download all three in a zip here pylolgraph.zip
How to use:
- My system is WinXP. Not tested on anything else.
- Download pylolgraph.pde, and upload it to your Arduino. Make sure the BAUD variable matches that in your Python module (below).
- Download pylolgraph.py, put it in your Python path.
- Download example01.py: Set it’s BAUD variable to match that in pylolgraph.pde, and set its PORT variable to be the port your Arduino is on (will vary depending on your OS).
- Start pylolgraph.pde on the Arduino. Run example01.py from the command-line or double-click the icon: You should see a small Pygame window pop up: When you click the LMB, a white donut will appear in the Pygame window. The same donut should then appear on the lolshield.
Inspect the documentation in pylolgraph.py for more details on implementation. Here is example pseudo-code for writing your own Pygame application with the code:
import pygame import pylolgraph # Setup some constants: # Create a resolution that corresponds to the lolshield. # See docs on the pylolgraph.LOLShield.setSurface() method # for acceptable resolutions. WIDTH, HEIGHT = (448, 288) # Baud rate must be the same as setup in pylolgraph.pde BAUD = 28800 # Port the Arduino is on, on my WinXP box. PORT = 'COM4' # Start Pygame application: # Make surface that will have its data sent to lolshield: screenSurf = pygame.display.set_mode((WIDTH, HEIGHT)) # Setup lolshield object: lolshield = pylolgraph.LolShield(port=PORT, baudrate=BAUD) # Set the surfcae that will have its pixel data sent to the Arduino\lolshield: lolshield.setSurface(screenSurf) # inside main loop: # Draw stuff to screenSurf. Then: lolshield.sendData()