0

enter image description here

I have connected pin D2 on my arduino nano to high, and tried it out with an arduino c program and it works. However, when I load standard firmata onto the the controller from the arduino IDE and try the following python program:

import pyfirmata

board = pyfirmata.Arduino('/dev/ttyUSB0')

for x in range(2,14):
    print("%s %s" % (x, board.get_pin("d:%s:i" % x).read()))

I get this:

$ venv/bin/python test.py 
2 None
3 None
4 None
5 None
6 None
7 None
8 None
9 None
10 None
11 None
12 None
13 None

I can write digital pins with fermata and pyfirmata, but I can't read.

I have also tried this:

import pyfirmata

board.digital[2].mode = pyfirmata.INPUT
board.digital[3].mode = pyfirmata.INPUT

for x in range(2,14):
    print("%s %s" % (x, board.digital[x].read()))

and other combinations, and always get None

(disconnecting the wire in the picture doesn't change anything either)


I have also just repeated the experiment with an arduino uno and get the same result


so I guess my questions are:

  • Can anybody spot anything obvious that I am doing wrong?
  • Can anybody confirm that pyfirmata input ever works?
  • What did you do that I am not doing?
  • what should the resistor do? – Juraj Jul 20 at 19:02
  • Unless I have done something totally wrong, it is a pull down resistor in case I want to disconnect the yellow wire to see a low signal on D2. It was necessary when I tested the set-up with arduino-c. – Alex028502 Jul 21 at 6:02
1

"None" indicates that there is no data to be found by read() because the incoming serial stream has never been serviced. Launch an Iterator to start a new Python thread that services the serial port in the background.

it = pyfirmata.util.Iterator(board)
it.start()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.