在Arduino Uno上阅读Usin Pyfirmata的多个模拟销
我试图用Pyfirmata阅读来自Arduino Uno的多个模拟引脚,但我有一个问题,可以像以下结果一样阅读它,例如连接了引脚。
if __name__ == '__main__':
board = Arduino('/dev/ttyACM0')
print("Communication Successfully started")
board.analog[0].enable_reporting()
board.analog[1].enable_reporting()
board.analog[2].enable_reporting()
board.analog[3].enable_reporting()
it = util.Iterator(board)
it.start()
analog_0 = board.get_pin("a:0:i")
analog_1 = board.get_pin("a:1:i")
analog_2 = board.get_pin("a:2:i")
analog_3 = board.get_pin("a:3:i")
while True:
button1 = analog_0.read()
button2 = analog_1.read()
button3 = analog_2.read()
button4 = analog_3.read()
print(button1)
print(button2)
print(button3)
print(button4)
print('')
time.sleep(1)
当没有按下按钮时输出:
0.2385
0.2346
0.2336
0.2326
0.1662
0.1642
0.1632
0.1613
输出当我按任何按钮时(仅一个):
0.6491
0.6735
0.6647
0.6569
0.6471
0.6735
0.6628
0.6569
如何将这些读数分开? 在使用Arduino IDE时,我对此没有任何问题。
I'm trying to read multiple analog pins from Arduino UNO with pyFirmata but I have a problem that reading it as below results like the pins are connected.
if __name__ == '__main__':
board = Arduino('/dev/ttyACM0')
print("Communication Successfully started")
board.analog[0].enable_reporting()
board.analog[1].enable_reporting()
board.analog[2].enable_reporting()
board.analog[3].enable_reporting()
it = util.Iterator(board)
it.start()
analog_0 = board.get_pin("a:0:i")
analog_1 = board.get_pin("a:1:i")
analog_2 = board.get_pin("a:2:i")
analog_3 = board.get_pin("a:3:i")
while True:
button1 = analog_0.read()
button2 = analog_1.read()
button3 = analog_2.read()
button4 = analog_3.read()
print(button1)
print(button2)
print(button3)
print(button4)
print('')
time.sleep(1)
Output when none of the buttons are pressed:
0.2385
0.2346
0.2336
0.2326
0.1662
0.1642
0.1632
0.1613
Output when i press any button (only one):
0.6491
0.6735
0.6647
0.6569
0.6471
0.6735
0.6628
0.6569
How can i separate those readings?
I have no problem with this while using Arduino IDE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论