Pages: [1]   Go Down
Author Topic: Python Firmata trouble  (Read 291 times)
0 Members and 1 Guest are viewing this topic.
Reading, Berkshire
Offline Offline
Full Member
***
Karma: 2
Posts: 132
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    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)
Logged

Pages: [1]   Go Up
Jump to: