Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting python to interact with the real world(robotics/physical computing)
#1
As always this is brought to you by my blog http://bsdpunk.blogspot.com

[yt]http://www.youtube.com/watch?v=Hp30GKStna4[/yt]

For hardware you will need an arduino:
http://www.arduino.cc/

Arduino's are fairly cheap for getting into robotics/physical computing, you could spend as little as 20 dollars.

You need pygame and the python firmata installed. If you are on a yum based system you can install pygame by doing a:
yum -y install pygame

To install python firmata you will have to download it, untar it. Navigate to to directory in the terminal and then run this as root(or with the sudo command first):
python setup.py install
or
sudo python setup.py install

If you can't run them as root run each one with sudo in front of it:
PHP Code:
yum -y install git
git 
clone http://github.com/lupeke/python-firmata.git
cd python-firmata
python setup
.py install 
or
PHP Code:
sudo yum -y install git
sudo git 
clone http://github.com/lupeke/python-firmata.git
cd python-firmata
sudo python setup
.py install 


It is located here:
http://github.com/lupeke/python-firmata



Your biggest challenge, may be getting everything installed, from there it should be pretty easy.


This is how to get started, with python and your arduino, bringing up the beginning 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.
Reply
#2
Sweet, I can't wait till I get my arduino board Tongue
Reply
#3
There fun to work with for sure.
Reply
#4
Thanks for making this bsdpunk ^__^
[Image: sig.php]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 1,773 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 8,355 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,224 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 760 02-12-2010, 09:07 PM
Last Post: Kharnage
  "==" and "is" in Python Canoris 1 742 02-07-2010, 03:55 PM
Last Post: uber1337

Forum Jump:


Users browsing this thread: 1 Guest(s)