Skip to content

Instantly share code, notes, and snippets.

@fermuch
Created August 27, 2011 05:40
Show Gist options
  • Save fermuch/1175037 to your computer and use it in GitHub Desktop.
Save fermuch/1175037 to your computer and use it in GitHub Desktop.
Script para obtener resultados de Arduino
# -*- coding: utf-8 -*-
import sys
import time
from commands import getoutput
from arduino import Arduino
# definir dispositivo
out = getoutput("ls /dev/ | grep -i ttyUSB").split()
out[0] = "/dev/" + out[0]
try:
out[0]
print ">> Utilizando dispositivo: %s" % (out[0])
boardDev = out[0]
except IndexError:
print "No se pudo encontrar ningún dispositivo utilizable"
sys.exit()
board = Arduino(boardDev, 9600) # = baudios
board.output([0])
print ">> " + str(board)
pin = 0
i = 0
ilimit = 100 # total de impresiones necesarias
LED = 13
try:
while(i<ilimit):
#print "Procesando"
board.setHigh(LED) # Activar led para pruebas
print board.analogRead(pin) # imprimir la lectura del analógico
#time.sleep(1)
i+=1
if (i == ilimit):
board.setLow(LED) # Desactivar led al terminar
board.close()
except KeyboardInterrupt:
board.turnOff()
board.close()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment