There was an error in this gadget
There was an error in this gadget

Saturday, December 12, 2009

Very Simple Tutorial for pygame and arduino, to get started making a gui for arduino part 1




This is how to get started, with python and your arduino, brining up the begginings of a GUI. It's just a taste of what you can do and I hope to go further on the subject. You need pygame, and the python firmata installed(explained
here), and your arduino must have the firmata software on it as explained here. Here is the code I stole/wrote for getting the arduino to blink when you click within pygame. This outline should get you started with fun stuff:


#! /usr/bin/env python

import pygame
from firmata import *

proArduino = Arduino('/dev/ttyUSB0')
proArduino.pin_mode(13, firmata.OUTPUT)
proArduino.delay(2)

LEFT = 1
x = y = 0
screen = pygame.display.set_mode((640, 480))
running = 1

def blinky(pin_n):
proArduino.digital_write(pin_n, firmata.LOW)
proArduino.delay(2)
proArduino.digital_write(pin_n, firmata.HIGH)
proArduino.delay(2)


while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
blinky(13)

screen.fill((100,0,0))
pygame.display.flip()




Right now I am experimenting with a lot of diffrent things(forking etc.), to see how the arduino and pygame can best interoperate.

No comments:

Post a Comment

There was an error in this gadget
There was an error in this gadget