Go Down

Topic: Python Firmata trouble (Read 309 times) previous topic - next topic

StuHooper

http://stackoverflow.com/questions/16234776/python-firmata-and-arduino-script-structure-effecting-firmata

When using this script to blink an LED on pin12, the script will not get past line27 where pin12 is set high. There is no error message.
How do I structure this script so that Firmata works on each loop? I am interested to learn why the script doesn't work at all but the LED example script will.

Code: [Select]

    import json
   import urllib
   from firmata import *
   from pprint import pprint
   import time
   import serial

   countTweet = 0
   a = Arduino('COM13') #Insert this before the while loop = it never actually works
   a.delay(2)          

   while True:
       try:
           response = urllib.urlopen('http://search.twitter.com/search.json?q=%23happy&result_type=recent&rpp=1&filter:retweets').read()
       except IOError:
           pprint('no internet connection')
           time.sleep(5)
           continue
       j = json.loads(response)
       if j['results']:
           text = j['results'][0]['text']
           tID = j['results'][0]['id']
       else:
           pprint('bad JSON')
       if countTweet != 0 and lastID != tID:
           pprint('new ID')
           a.pin_mode(12, firmata.OUTPUT)  #Gets stuck here
           a.delay(2)
           a.digital_write(12, firmata.HIGH)
           a.delay(2)
           a.digital_write(12, firmata.LOW)
           pprint('done firmata')
           lastID = tID
           pprint (text)
           pprint ('1')
       else:
           pprint("FLC") #First loop complete: To gather the existing tweet before we start
           lastID = tID
           countTweet += 1
       time.sleep(15)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy