Arduino + Firmata + Pyduino (Python)

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

Right, I think that I almost know what's going on now...maybe
The iterate and sleep should definitely be in init - that's my fault. The iterate after get_firmata_version() grabs the bytes sending the version, everything I've done before has been looping over iterate so I didn't notice.
I think that the problem setting the digital pin is in the 0010 version of firmata, although it does compile. I'm going to take a guess that the compile errors in rev 1.3 are to do with port_to_input_PGM not being found. If so try putting
#include <pins_arduino.h> after the EEPROM include in firmata. I think it should compile then and (hopefully) work with 57600 bitrate. If it compiles and doesn't work then we're back to it being my fault. If it doesn't compile then can you post up the errors - I remember I had to do a little tweaking to get 1.30 to compile with 0010 (probably just the include), but I thought it was my fault botching the new versions of everything.
Cheers
Joe

You might want to try the version of Firmata in the processing-arduino library from the Interfacing w/ Processing page on the playground. That's the one I've been using (I created the Processing library), and I believe it's the most recent stable version.

BTW, dylpkls91: when you upload a sketch (e.g. led blink), do you have to wait about 6 seconds or so after uploading it before it starts running? You may have gotten a Diecimila that was accidently burned with the NG bootloader, which works fine, but has a longer initial delay (so requires a longer sleep in the pyduino code).

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

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

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

Brilliant! Over the next couple of days I'll put up a new version of Pyduino which has your changes in, and contains the working firmware so we don't have this problem again. Thanks for all of your help dylpkls91 and mellis.
Joe

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.

Yeah, that'd be great if you could. My email's in the linky thing at the bottom of the posts.

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.

Yeah, I get this too - I've got a fix for analog, just need to get a free hour to look at digital. What happens is that there is a delay between activating a pin and getting values out, so it just returns zero (a default value). I think I should be able to have a look this afternoon.
Joe

Great, once that's fixed, it'll be set! ;D

Right - half success...
Analog works fine afaik, and is not too bad code wise. Digital is however pretty sketchy I'm afraid. Anyway, here's a new version of pyduino: http://rafb.net/p/u9u2QP86.html
...and a rough idea of how it should work: http://rafb.net/p/FjOkxU38.html

As you can see, the analog iterates until it does not return -1 (i.e. a value has been assigned to the analog pin). This would be OK to do with digital, but there is no way of knowing whether the digital pin has been activated or not, as it only signals on a change. This is in the TODO for firmata, so will hopefully be in the next version. For now you can work around it by iterating for a while after the pin is activated so it has time to get a value.

On the plus side this has helped me find a big old bug in the digital handling, so it's all been good and worthwhile :slight_smile:
Let me know how this one goes
Joe

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.

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?

Links are broken...

http://rafb.net/p/FjOkxU38.html and http://rafb.net/p/u9u2QP86.html are both 404 for me....

Sorry, they were just up for a day or so for testing. I'll get a proper tarball out over the next couple of days. For now here's the links:
http://pyduino.pastebin.com/f2b76d85e
http://pyduino.pastebin.com/m69d01f2d

Joe

Hey

Did that tarball ever get released? If so, please update the link on the Firmata page, under Host Implementations:

http://www.arduino.cc/playground/Interfacing/Firmata

Also, let me know if you want any help updating pyduino to work with Firmata v2.0. It is slated to be included in Arduino 12 and we are working towards making it the default firmware that Arduinos ship with, so it would be good to have pyduino working with it.

Oh gawd, it never did. I'll have a look this weekend and see what sort of state it's in and give a go at making a version which works with 2.0. If I have any problems I'll drop an email to the ML.
Cheers
Joe

The link on the firmata site is still code from 2007.04.09. Any chance you could put the pyduino code on berlios or sourceforge so that we can help you get it up and running.

Today i wrote orphans a mail asking if he can send me his newest pyduino version.
He was super-reactive and published it.
The link is in the next post from me, since this is my first, and some spam eater in this forum software doesnt want a link to show up in a first post.

This works very well with Firmata 2.0, wow!
I am using the Firmata sketchbook included in arduino-012, btw.

So, huge thanks to orphans!