Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Pyfirmata PDF
Pyfirmata PDF
Puesta a punto 'olcar en Ar#uino el sketch (tan#ar#&irmata. (tan#ar#&irmata )nstalar p% irmata: irmata
$ hg clone https://bitbucket.org/tino/pyfirmata $ cd pyfirmata; python setup.py install
(i necesitas servos:
*ste ejemplo hace parpa#ear el le# enchu a#o al pin #igital 1+ A#emas #e digital tambi,n ha% analog- % a#em.s #e write tambi,n ha% read :-/
import time from pyfirmata import !rduino board " !rduino#$/dev/tty%&'0$( )hile *: board.digital+*,-.)rite#*( time.sleep#*( board.digital+*,-.)rite#0( time.sleep#*(
Lecturas
$ara evitar 0ue el Ar#uino nos est, man#an#o cont1nuamente #atos en los pines #e lectura- se utili2a un )terator:
it " util..terator#board( it.start#( board.analog+0-.enable_reporting#( board.analog+0-.read#(
*l )terator es un threa#- por lo 0ue ha% 0ue matarlo al salir. 3o m.s acil es romper la cone4i"n con el puerso serie- el threa# se suici#a el solito.
board.exit#(
Ventilador (Digital)
/0 /1 /2 /3 /4 /6 ,0 ,* ,/ ,, ,0
def start#self(: )hile self.loop: ne)value " self.board.analog+self.pot_pin-.read#( print ne)value if self.value 5" ne)value: if ne)value 7 0.1: self.board.digital+self.motor_pin-.)rite#*( else: self.board.digital+self.motor_pin-.)rite#0( self.value " ne)value time.sleep#0.1(
GISA Elkartea Ales Zabala
PC Speaker (PWM)
2 *3 /2 /3 /4 /6 ,0 ,* ,/ ,,
def __init__#self8 port8 pot_pin8 motor_pin(: +...self.board.digital+self.motor_pin-.mode " 9:; +...def start#self(: )hile self.loop: ne)value " self.board.analog+self.pot_pin-.read#( print ne)value if self.value 5" ne)value: self.board.digital+self.motor_pin-.)rite#ne)value( self.value " ne)value time.sleep#0.1(
GISA Elkartea Ales Zabala
Ser os
2 *3 /2 /3 /4 /6 ,0 ,* ,/ ,, ,0
Hackmeeting 2011
def __init__#self8 port8 pot_pin8 motor_pin(: +...self.board.digital+self.motor_pin-.mode " &<=>? +...def start#self(: )hile self.loop: ne)value " self.board.analog+self.pot_pin-.read#( if #ne)value is not @one( and #self.value 5" ne)value(: angle " int#*40 A ne)value( printBCs "7 CsB C #ne)value8 angle( self.board.digital+self.motor_pin-.)rite#angle( self.value " ne)value time.sleep#0.1(
GISA Elkartea Ales Zabala
!tro e"emplo
5epresentacion #el esta#o #el Ar#uino con una 67) en $%89 :e igual manera po#r1amos usar sockets- la carga #el or#ena#or- consultas http...
Comentarios
*s mu% .cil #e usar. !on la consola #e p%thon po#emos hacer pruebas #irectamente en Ar#uino. 9ambi,n e4iste p%#uino- pero parece 0ue es un pro%ecto aban#ona#o. *n p% irmata ha% un #esarrolla#or ;un tanto espor.#ico/- % una persona 0ue env1a parches ;a#em.s #el m1o :-/. 9iene sus limitaciones ;:H911/. 9o#av1a le altan cosas para implementar completamente irmataaun0ue lo m.s t1pico %a est..
GISA Elkartea Ales Zabala