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
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)
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.

http://stackoverflow.com/questions/15998425/python-serial-arduino-surviving-loss-of-connection

Quote
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 ser.read(), 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?

Code:
from pprint import pprint
import time
import serial

while True:
    #the connection to the arduino
    try:
        ser = serial.Serial('COM13',9600)
    except IOError:
        connected = False
        pprint('Arduino not connected to COM13')
        time.sleep(3)
        continue
    serin = ser.read()
    connected = True
    pprint('connected to arduino')
    ser.write('1')
    while ser.read() == '1':
        pass
    pprint ('Arduino has finished flash')

    ser.close()
    pprint('connection closed')

    time.sleep(5)
3  Using Arduino / Motors, Mechanics, and Power / Servo recommendations on: April 12, 2013, 12:52:49 pm
Hello,
 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.

Code:
Traceback (most recent call last):
  File "C:\Users\3d Exposure\Desktop\M001.py", line 19, in <module>
    ser = serial.Serial('COM3',9600)
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 31, in __init__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\serialutil.py", line 261, in __init__
    self.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 71, in open
    self._reconfigurePort()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", 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

Code:
while ser.read() !='0'
    pprint('waiting for arduino')


or


Code:
while ser.read() == '0'
    break


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
Code:
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

Code:
while ser.read() != '0':
ser.read()


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
Hello.
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):
Code:
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 = ser.read()
        connected = True
    #debug arduino connection
    if connected == True:
        pprint('connected to arduino')
   
    try:
        response = urllib.urlopen('http://search.twitter.com/search.json?q=%23happy&result_type=recent&rpp=1&filter:retweets')
    except IOError:
        pprint ('internet or twitter is down. This program will continue working when the connection opens again.')
        time.sleep(15)
        continue
    j =json.loads(response.read())
    #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']
        pprint(text)
        pprint(id)   
        tweet+= 1
    else:
        #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
            ser.write('1')
            ser.write('0')
            #loop until the arduino tells us it is done vending by sending us a '0'
            while ser.read() == '1':
                ser.read()
               
            #Make lastID equal to ID
            lastID = id
            pprint ('lastID updated')
        #if no new tweets, print     
        else:
            pprint ('no new tweets')
    #If it's the first loop, confirm by printing to the screen
    else:
        pprint("First loop complete")
        lastID = id
        pprint(lastID)
        countTweet += 1
   

    #make count not equal to 0 after first loop
 

    pprint ('closing arduino connection')
    ser.close()

    #wait
    pprint('waiting 15 seconds')
    pprint ('Number of Tweets')
    pprint (countTweet)
    pprint('Working JSON')
    pprint(tweet)
    pprint('Broken JSON')
    pprint(noTweet)
    time.sleep(15)
   
       


And here is the simple Arduino sketch:
Code:
void setup(){
  Serial.begin(9600);
  pinMode(12, OUTPUT);
  //Tell python we are done with setup
  Serial.write('1');
}

void loop(){

  if(Serial.available() >0){
    //Vend pin high
    digitalWrite(12,HIGH);
    delay(1000);
    digitalWrite(12,LOW);
    //Tell Python we have flashed
    Serial.write('0');
  }
}
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 http://practicalmaker.com/tutorials/pwm-shield-documentation 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
Hello,
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
Hello,
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?
thanks
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.

https://dev.twitter.com/docs/api/1/get/statuses/mentions

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
Hi,

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...

Code:
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=/; Domain=.twitter.com
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">
  <status>
    <created_at>Tue Oct 23 10:49:31 +0000 2012</created_at>
    <id>260694435908681729</id>
    <text>Something else</text>
    <source>&lt;a href=&quot;http://twitter.com/download/android&quot; rel=&quot;nofollow&quot;&gt;Twitter for Android&lt;/a&gt;</source>
    <truncated>false</truncated>
    <in_reply_to_status_id></in_reply_to_status_id>
    <in_reply_to_user_id></in_reply_to_user_id>
    <in_reply_to_screen_name></in_reply_to_screen_name>
    <user>
      <id>563128171</id>
      <name>stuart hooper</name>
      <screen_name>HooperStuart</screen_name>
      <location>northam, devon</location>
      <profile_image_url>http://a0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png</profile_image_url>
      <profile_image_url_https>https://si0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png</profile_image_url_https>
      <url>http://stuarthooper.tumblr.com</url>
      <description>http://stuarthooper.tumblr.con</description>
      <protected>false</protected>
      <followers_count>0</followers_count>
      <profile_background_color>C0DEED</profile_background_color>
      <profile_text_color>333333</profile_text_color>
      <profile_link_color>0084B4</profile_link_color>
      <profile_sidebar_fill_color>DDEEF6</profile_sidebar_fill_color>
      <profile_sidebar_border_color>C0DEED</profile_sidebar_border_color>
      <friends_count>1</friends_count>
      <created_at>Wed Apr 25 19:20:23 +0000 2012</created_at>
      <favourites_count>0</favourites_count>
      <utc_offset></utc_offset>
      <time_zone></time_zone>
      <profile_background_image_url>http://a0.twimg.com/images/themes/theme1/bg.png</profile_background_image_url>
      <profile_background_image_url_https>https://si0.twimg.com/images/themes/theme1/bg.png</profile_background_image_url_https>
      <profile_background_tile>false</profile_background_tile>
      <profile_use_background_image>true</profile_use_background_image>
      <geo_enabled>true</geo_enabled>
      <verified>false</verified>
      <statuses_count>148</statuses_count>
      <lang>en</lang>
      <contributors_enabled>false</contributors_enabled>
      <is_translator>false</is_translator>
      <listed_count>0</listed_count>
      <default_profile>true</default_profile>
      <default_profile_image>true</default_profile_image>
      <following></following>
      <follow_request_sent></follow_request_sent>
      <notifications></notifications>
    </user>
    <geo/>
    <coordinates/>
    <place/>
    <contributors/>
    <retweet_count>0</retweet_count>
    <favorited>false</favorited>
    <retweeted>false</retweeted>
  </status>
</statuses>
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