Show Posts
Pages: [1] 2 3 ... 9
1  Using Arduino / Interfacing w/ Software on the Computer / Python Firmata trouble on: April 26, 2013, 08:09:43 am

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.

    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

    while True:
            response = urllib.urlopen('').read()
        except IOError:
            pprint('no internet connection')
        j = json.loads(response)
        if j['results']:
            text = j['results'][0]['text']
            tID = j['results'][0]['id']
            pprint('bad JSON')
        if countTweet != 0 and lastID != tID:
            pprint('new ID')
            a.pin_mode(12, firmata.OUTPUT)  #Gets stuck here
            a.digital_write(12, firmata.HIGH)
            a.digital_write(12, firmata.LOW)
            pprint('done firmata')
            lastID = tID
            pprint (text)
            pprint ('1')
            pprint("FLC") #First loop complete: To gather the existing tweet before we start
            lastID = tID
            countTweet += 1
2  Using Arduino / Interfacing w/ Software on the Computer / Re: A fatal error with Arduino and Python on: April 14, 2013, 06:52:23 am
I hope this will provide a better idea of what I need. I'm not even sure it is possible though.

I'm running this script to test the Serial connection between an Arduino and Python before I try to send and receive information between the two.

If the Arduino is unplugged/re-plugged during while, it will never restart from where it left off due to never receiving anything but a '1' from the Arduino>Serial.

What is a better way to write this that ensures the Serial connection can restart the script from the beginning after being unplugged?

from pprint import pprint
import time
import serial

while True:
    #the connection to the arduino
        ser = serial.Serial('COM13',9600)
    except IOError:
        connected = False
        pprint('Arduino not connected to COM13')
    serin =
    connected = True
    pprint('connected to arduino')
    while == '1':
    pprint ('Arduino has finished flash')

    pprint('connection closed')

3  Using Arduino / Motors, Mechanics, and Power / Servo recommendations on: April 12, 2013, 12:52:49 pm
 I need to control a steel cylinder and an egg shaped agitator with servo driven belts.

The cylinder is water melon sized.

The agitator is about the size of an iphone and made of rubber.

I want the single servo to drive both units.
I want as much control as I can get out of the servo.
I imagine it has to be 12V mains power (UK) integrated into the control circuit.

I would like to know any recommended servos that I can control with the Arduino.
Also, anything I should be looking for in buying a strong, compact servo.
4  Using Arduino / Interfacing w/ Software on the Computer / Re: A fatal error with Arduino and Python on: April 10, 2013, 11:13:13 am
I have been forwarded the error message from the python script. It looks like you might be right.

Traceback (most recent call last):
  File "C:\Users\3d Exposure\Desktop\", line 19, in <module>
    ser = serial.Serial('COM3',9600)
  File "C:\Python27\lib\site-packages\serial\", line 31, in __init__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\", line 261, in __init__
  File "C:\Python27\lib\site-packages\serial\", line 71, in open
  File "C:\Python27\lib\site-packages\serial\", line 186, in _reconfigurePort
    raise ValueError("Cannot configure port, some setting was wrong. Original message: %s" % ctypes.WinError())
ValueError: Cannot configure port, some setting was wrong. Original message: [Error 31] A device attached to the system is not functioning.
5  Using Arduino / Interfacing w/ Software on the Computer / Re: A fatal error with Arduino and Python on: April 10, 2013, 10:36:05 am
Do you think

while !='0'
    pprint('waiting for arduino')


while == '0'

would work?
6  Using Arduino / Interfacing w/ Software on the Computer / Re: A fatal error with Arduino and Python on: April 10, 2013, 08:07:04 am
It reads ser
if ser is a 1 it reads ser again
if ser is a 0 it exits the while loop
I did consider there might be a chance that it would miss the 0 coming from the Arduino. However, I set it running for a two day test and it worked. If the Serials are both set to 9600bps they must catch every '1' or '0' that comes their way.

it would be the same as writing

while != '0':

Basically saying keep checking ser until you find a '0', do not progress with the script until Arduino has finished it's function.

The 'While True' infinite loop contains a 'connected = False' statement before the 'while not connected' but after 'ser.close()'

I'll add that time.sleep(2) but I must state that it works for an extended period as is. I imagine if it wasn't going to connect this way, it wouldn't work 99% of the time?

Slightly unrelated additional information:

The Arduino is connected to a MOSFET on pin 12 which controls a Solenoid. I built this circuit for it.

I don't know if there could be an issue here but as above, it works 99% of the time.

The Json feed has a 0.1% error rate when calling it every 15 seconds over two days. This has been handled in the code. Sometimes it would lack the 'results:' . So I loop around again, leaving a total of 30 second gap as to not call on twitter too often.

7  Using Arduino / Interfacing w/ Software on the Computer / A fatal error with Arduino and Python on: April 10, 2013, 04:58:12 am
There is a possibility that this error is not caused by an Arduino issue, therefore this post will serve as a learning curve for myself and others.

 I am currently making pin12 go HIGH and LOW after receiving a new tweet on Python.
The program will run for a couple of days and then Python will crash. I have yet to see the Error code as the unit is very far away from myself. Until I am sent the error code, I'm trying to understand possible problems.

I have two queries.
  • How can I ensure the Python script will not crash if Serial connection is temporarily lost?
At the moment, using a Try / Except doesn't seem to cut it as once unplugged, the computer doesn't recognise the COM port again.

  • Does disconnecting and reconnecting to the Arduino from a PC use more memory each time or does it reset the Arduino?

Here is the python code (with the COM port Try/Except removed):
import json
import urllib
from pprint import pprint
import time
import serial

#to collect the first tweet without vending
countTweet = 0
tweet= 0
noTweet= 0

#the infinate loop
while True:
    #the connection to the arduino
    ser = serial.Serial('COM3',9600)
    #not connected to arduino before connection is made
    connected = False

    #loop until the arduino is connected
    while not connected:
        serin =
        connected = True
    #debug arduino connection
    if connected == True:
        pprint('connected to arduino')
        response = urllib.urlopen('')
    except IOError:
        pprint ('internet or twitter is down. This program will continue working when the connection opens again.')
    j =json.loads(
    #Check that j contains the correct json, else twitter has sent another broken one.
    if j['results']:
        text = j['results'][0]['text']
        id = j['results'][0]['id']
        tweet+= 1
        #How many times the Json is false
        noTweet += 1

    #to isolate the first loop, if the first ID has been stored already (countTweet == 1)
    if countTweet != 0:
        pprint ("new tweet")
        #if lastID is not equal to ID
        if lastID != id:
        #Tell Arduino to Vend
            #loop until the arduino tells us it is done vending by sending us a '0'
            while == '1':
            #Make lastID equal to ID
            lastID = id
            pprint ('lastID updated')
        #if no new tweets, print     
            pprint ('no new tweets')
    #If it's the first loop, confirm by printing to the screen
        pprint("First loop complete")
        lastID = id
        countTweet += 1

    #make count not equal to 0 after first loop

    pprint ('closing arduino connection')

    pprint('waiting 15 seconds')
    pprint ('Number of Tweets')
    pprint (countTweet)
    pprint('Working JSON')
    pprint('Broken JSON')

And here is the simple Arduino sketch:
void setup(){
  pinMode(12, OUTPUT);
  //Tell python we are done with setup

void loop(){

  if(Serial.available() >0){
    //Vend pin high
    //Tell Python we have flashed
8  Using Arduino / Project Guidance / Re: Charlieplexing MOSFET? on: April 01, 2013, 08:39:58 am
Thanks CrossRoads,
I started looking about and stumbled across this PWM shield that allows control of 32 PWM pins.

Do you think this is a good route to take?
9  Using Arduino / Project Guidance / Charlieplexing MOSFET? on: April 01, 2013, 07:28:04 am
I'm planning to create a project in which 20 or so household lamps are triggered by infrared sensors. Fading up as you walk towards them and slowly fading off again if the infrared sensors detected value is less than it was in the loop before.

I understand most of what I need to do, The main issue is that I'll need to control 20 MOSFETs with PWM.

Is this possible with any of the Arduino? I can only see up to 12 PWM pins on the MEGA.

Is it possible to use PWM while charlieplexing MOSFETs? Would this solve the issue?
10  Using Arduino / Project Guidance / 64 analog reads on: March 02, 2013, 10:41:04 am
I'm looking to read about 64 Analog temp sensors every loop. I'm not sure if any of the arduinos are capable of this due to limited analog inputs.
 Do you know of anything that could handle this?
11  Using Arduino / Audio / Arduino as an internet radio station? on: December 12, 2012, 05:02:43 pm
Would it be possible to use an arduino as an internet radio station that plays the sound picked up by a microphone?
12  Using Arduino / Project Guidance / Methods of wireless internet connection in remote locations. 3G or Dongle hack? on: December 06, 2012, 05:57:52 pm
I understand there is a 3G/GPS shield for the arduino now and that is a method of connecting to the internet when on the move. I was just wondering how reliable it is and if anyone can give me feed back on it?
I'm considering a new project involving lights in remote locations controlled by social media. I would not have any wifi signal and I would need a fairly regular refresh rate, so feedback on that is welcome.

I'm not sure if it is possible to use a mobile broadband dongle with an arduino. Has anyone attempted this?
13  Using Arduino / Programming Questions / Re: Twitter triggered arduino, open to the public? - Question about method. on: October 23, 2012, 07:16:39 am
I'm after reading mentions. The idea is to open up the device by allowing anyone to tweet at it instead of it just reading my twitter account for commands in the tweets.

Obviously this opens up security issues with certain devices... like anyone in the world tweeting someones coffee maker all day until it boils dry and breaks.

14  Using Arduino / Programming Questions / Twitter triggered arduino, open to the public? - Question about method. on: October 23, 2012, 06:45:50 am

I've used the Ethernet shield to control an arduino with twitter. This happens by monitoring the XML of a single twitter account.
What I would like to do is make this device open to public interaction from other peoples twitter accounts. The problem being the XML feed doesn't seem to include any information about people tweeting at my twitter account.

For example...

X-RateLimit-Limit: 150
X-RateLimit-Remaining: 54
X-RateLimit-Reset: 1350990236
X-RateLimit-Class: api
Content-Type: application/xml;charset=utf-8
Last-Modified: Tue, 23 Oct 2012 10:52:18 GMT
Expires: Tue, 31 Mar 1981 05:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
Set-Cookie: guest_id=v1%3A135098953799518156; Expires=Thu, 23-Oct-2014 10:52:18 GMT; Path=/;
Status: 200 OK
X-Transaction: 2aba7e893832e539
X-Frame-Options: SAMEORIGIN
Date: Tue, 23 Oct 2012 10:52:18 GMT
Content-Length: 2736
Server: tfe

<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
    <created_at>Tue Oct 23 10:49:31 +0000 2012</created_at>
    <text>Something else</text>
    <source>&lt;a href=&quot;; rel=&quot;nofollow&quot;&gt;Twitter for Android&lt;/a&gt;</source>
      <name>stuart hooper</name>
      <location>northam, devon</location>
      <created_at>Wed Apr 25 19:20:23 +0000 2012</created_at>
HTTP/1.1 200 OK

No where in here does it mention any mentions like @hooperstuart.
I have seen something on hack-a-day that prints these with a dot-matrix printer and a BeagleBone. Is it possible with an Arduino and Ethernet shield?
I'm guessing I need a different GET. Probably a search for mentions of my user name. Am I on the right track?
15  Using Arduino / General Electronics / Re: UK Power supply issue, recommendation needed. on: October 18, 2012, 10:02:55 am

one of these USB plugs and a normal usb cable got it working, I'm just wondering what power adapter I should use.. In case I ever need to use the USB for something else.
Pages: [1] 2 3 ... 9