在Arduino Uno上阅读Usin Pyfirmata的多个模拟销

发布于 2025-02-02 17:31:19 字数 1198 浏览 3 评论 0原文

我试图用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文