Reading multiple analog pins by usin pyFirmata on Arduino UNO

324 Views Asked by At

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.

0

There are 0 best solutions below