I'm having trouble reading digital inputs in Python(pyfirmata) from
my UNO loaded with StandardFirmata 2_2 on Ubuntu 10.4. Writing to the digital pins
works perfectly yet reading digital or analog inputs return "none".
When UNO is loaded with a simple button sketch the digital pins work therefore
I know the hardware is good.
My code is as follows:
I'm in the same board. Using an Arduino Duemilanove, Ubuntu 11.04, standardfirmata. I tested with the same sketch, and Ran the same code as above, and it doesn't register my button presses.
Update: I also tried it with OldStandardFirmata, and got the same response. Read() doesn't appear to be assigning any variable at all... I'll try looking through pyfirmata's code to get a sense for what's going on.
pvanstam is correct. You need to use the iterate method to take care of all incoming messages. You also need to run it more than once, as the arduino is constantly sending information. The easiest way to do this is using the Iterator class from the util module:
from pyfirmata.util import Iterator
iterator = Iterator(board)
iterator.start()
When you have done this, a seperate thread is running that updates the board continuously. Now your reads should be correct.
Thanks TiNo! I really appreciate you taking time out of your day to answer this question for us. We recognize that you're doing this on your own time, and it is highly appreciated.
Now I can read the analog input pins using the Iterator() method
yet digital input pins return "None". I remember seeing something about
enabling a port for digital inputs, would this have any effect in reading
inputs?