Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Troubleshooting / Arduino + Firmata + Pyduino on: December 30, 2007, 08:47:16 pm
Has anyone had luck using Firmata + Pyduino, the Python library?  
 
The Firmata sketch is located here: http://www.arduino.cc/playground/Interfacing/Firmata but the download link is broken so I had to copy/paste from the CVS site. Only later did I find that Firmata is already located in a folder in the Arduino IDE (I'm on WinXP).
 
I've had no luck getting the Pyduino library and example to work. PySerial can connect to the Arduino's serial port without errors, but any attempt at one- or two-way communication (for example, getting the firmata version number stored in the sketch on the arduino) produces nothing. Other serial communication to my board using other sketches works fine.
2  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 07, 2008, 03:14:22 pm
P.S. - Hopefully the next version of Firmata is out soon, to fix the digital input problem. Do you have any idea how active Firmata development is?
3  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 07, 2008, 03:10:07 pm
Thanks, I'll let you know how it goes.

I almost forgot, do you want to add the extra Diecimila pwm pins 3, 5, and 6 to the constant PWM_PINS? You may not want to, though, because AFAIK there's no way to tell which type of board Firmata is running on.
4  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 07, 2008, 01:10:17 pm
Great, once that's fixed, it'll be set!  ;D
5  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 05, 2008, 03:25:56 pm
Hmmm...

I've been playing around some more, and it seems like reading analog and digital inputs only works in a "while True" loop like the one in the pyduino example. I can't just grab an input's value once, it returns a 0.
6  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 04, 2008, 02:33:49 pm
Great! Why don't I just e-mail you the two files or something?

Through trial and error, I found that the shortest possible sleep time without data/command loss is 1.5 seconds for Diecimilas.
7  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 04, 2008, 01:58:06 pm
Breaking:

I am now using Firmata 1.29 and Pyduino (with sleep and iterate in __init__ and a baudrate of 57600).

The Processing examples work (input, output, and pwm).

Better yet, as far as I can tell, Pyduino is now working just fine!!!

Thank you, thank you, thank you, both!

;D ;D ;D
8  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 04, 2008, 01:29:09 pm
Here's where I'm at right now.

I just tried Firmata 1.30, applying orphans' suggestion of including pins_arduino.h. At first, it didn't compile and I got the same error, but it worked after I poked around and changed the method calls in lines 164 and 165 of Firmata from "port_to_input" to "port_to_input_PGM".

I'm using pyduino.py modified in the following ways: I added a six-second sleep and self.iterate() to __init__, and set the baudrate to 57600, which matches the speed set in Firmata's setup() function.

But I'm still at the same point: Python can connect to the board via serial, pin 13 verifies being set active, I can get the version number, but any attempt to write a 1 to the pin does nothing. The rx light flickers, but that's it.  :'(

Mellis: Thanks, I'll try using that Firmata and let you know how it goes. No, when I upload a regular sketch (like the hello world led test) the board starts the program only a couple seconds after the transfer is complete. I put a six-second sleep in pyduino.py so that no data would be sent until after Firmata does its initial pin13-version-blink thing. Thank goodness my Arduino doesn't suffer from bootloader issues!

Thank you both again for all your help. It just goes to show that open-source communities have more than one advantage over the big guys.  ;D
9  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 03, 2008, 08:16:48 pm
Thank you both again for your help, but I regret to say that pyduino still isn't working.

Here's what I was able to find out:
  • The firmata included in Arduino 0010 does compile for me, whereas revision 1.3 doesn't.
  • Changing the baudrate in pyduino.py doesn't affect my results (I'm using the included firmata, which uploads w/o errors). I tried rates of 9600, 57600, and 115200.
  • I was finally able to get a two-value tuple from the get_firmata_version() function, by appending "self.iterate()" to __init__ in pyduino.py's Arduino class.
  • The above fix only works when pyduino.py sleeps for 6 or more seconds after beginning the serial connection. ("import time; time.sleep(6)")
  • The code I posted in an earlier post, to just turn on the LED at digital pin 13, still doesn't work, although "a.digital[13].get_active()" returns 1 (which must mean that the pin was successfully set active).
10  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 02, 2008, 06:24:03 pm
Well, I just added a sleep of two seconds right after pyduino initializes the serial connection, but nothing changed in the behavior of my arduino. I even fixed the mistake in my test code where I forgot to call board.iterate() before writing to the pin, but that didn't change anything either.  :'(
11  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 02, 2008, 06:13:04 pm
Ohhh... yep, I've got a Diecimila. I'll try putting a time.sleep(2) in pyduino.py and see if that works. I'll let you know how it goes. Thanks for the tip!  smiley
12  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Firmata + Pyduino (Python) on: January 02, 2008, 05:17:19 pm
Thanks for the response, sounds like you're the person to talk to.

I'm not trying to do anything fancy, just turn on the LED at pin 13 of my Diecimila. This is the code I was using after changing the serial rate in pyduino.py like you suggested:

Code:
import pyduino
a = pyduino.Arduino("com5")
a.digital[13].set_active(1)
a.digital[13].set_mode(pyduino.DIGITAL_OUTPUT)
a.digital[13].write(1)

The firmata sketch uploads fine, the rx/tx lights blink while it runs, and I don't get any errors in Python, but nothing else happens. I know it's not a communication issue; I have sent and received serial data from my Arduino in several other instances. PySerial and the FTDI drivers are installed (I'm on Python 2.5). Any idea as to what's going wrong? Thanks again for your help.
13  Forum 2005-2010 (read only) / Interfacing / Arduino + Firmata + Pyduino (Python) on: December 29, 2007, 03:53:01 pm
Has anyone had luck using Firmata + Pyduino, the Python library?

The Firmata sketch is located here: http://www.arduino.cc/playground/Interfacing/Firmata but the download link is broken so I had to copy/paste from the CVS site. Only later did I find that Firmata is already located in a folder in the Arduino IDE (I'm on WinXP).

I've had no luck getting the Pyduino library and example to work. PySerial can connect to the Arduino's serial port without errors, but any attempt at one- or two-way communication (for example, getting the firmata version number stored in the sketch on the arduino) produces nothing. Other serial communication to my board using other sketches works fine.
14  Forum 2005-2010 (read only) / Interfacing / Re: Arduino-Python bridge on: January 17, 2008, 05:32:20 pm
I'm really sorry, but I'm afraid I don't have the answers to your questions!!!

I'm really a novice Python programmer; I only made this solution as a workaround to Firmata and Pyduino, which wasn't working for me. But it's working now, see this link for details:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1198961581/all-0

This is a much more robust Python<->Arduino solution, which I recommend you use  smiley
15  Forum 2005-2010 (read only) / Interfacing / Arduino-Python bridge on: January 01, 2008, 08:38:56 pm
Here is a Python library that I cooked up to replace Firmata/Pyduino, which I could not get working with my Diecimila. The library is based on the Simple Message System protocol, an Arduino library intended to facilitate simple i/o control between computer and microcontroller (it can be found here: http://www.arduino.cc/playground/Code/SimpleMessageSystem). My Python library is pretty self-explanatory (just make sure you have the SMS example sketch loaded on your Arduino), feel free to use it with whatever you want  smiley

Code:

# Pyduino SMS
# by Dylan V, free to copy/edit/distribute
# A simple[r] Python-Arduino bridge, based on the Simple Message System protocol.
# Requires SMS library and SMS example sketch to be loaded on board.
# For USB Arduinos, please change baudrate in sketch to 115200.

import serial, atexit

__version__ = "0.2"
# This is alpha code, written by a novice. Syntax/structure changes are extremely welcome.
debug = True
global comm

class arduino:
   def __init__(self, port, baudrate=115200):
      try: self.comm = serial.Serial(port, baudrate, timeout=0.25)
      except: print "Could not connect to Arduino at specified port."
      if debug: print "Serial connection established at port %s." % port
      atexit.register(self.disconnect)

   def read_digital(self, pin):
      if pin in range(2, 14):
         self.comm.write("r d\r")
         result = self.comm.readline().split()[1:][pin - 2]
         if debug: print "Read digital pin %s, value was %s" % (str(pin), result)
         if result == "": return None
         else: return int(result)

   def read_analog(self, pin):
      if pin in range(6):
         self.comm.write("r a\r")
         result = self.comm.readline().split()[1:][pin]
         if debug: print "Read analog pin %s, value was %s" % (str(pin), result)
         if result == "": return None
         else: return int(result)

   def write_digital(self, pin, val):
      if pin in range(2, 14) and val in [0, 1]:
         self.comm.write("w d %s %s\r" % (pin, str(val)))
         if debug: print "Wrote value %s to digital pin %s" % (str(val), pin)

   def write_analog(self, pin, val):
      if pin in [3, 5, 6, 9, 10, 11] and val in range(256):
         self.comm.write("w a %s %s\r" % (pin, str(val)))
         if debug: print "Wrote value %s to pwm pin %s" % (str(val), pin)

   def disconnect(self):
      if self.comm: self.comm.close()
      if debug: print "Serial connection closed."

Pages: [1] 2 3