Arduino Asked by Alex028502 on September 25, 2021
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:
"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()
Correct answer by MAXdB on September 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP