Unable to access analog pins (Arduino Mega, pyfirmata)

123 Views Asked by At

I'm trying to read some values from analog joystick using my Arduino Mega 2560 board. Since I intend to use my Arduino in a bigger Python project, I am using pyfirmata to write the code. However, I am unable to access all of my analog pins, which the Mega has 16 in total. After declaring my board etc.:

board = pyfirmata.Arduino('COM8')
iterator = pyfirmata.util.Iterator(self.board)
iterator.start()

the statement print(len(board.analog)) returns value of 6 and upon trying to access a pin with index 6 or higher, I get the following error: IndexError: list index out of range. However, when I attempt to read values from those pins by code written in Arduino IDE and not using pyfirmata, everything is in order. So I am wondering if pyfirmata is somehow misinterpreting my board and I should perhaps declare that I am in fact using Mega, which has 16 analog pins, not 6 as it seems to think.

1

There are 1 best solutions below

1
Tim Roberts On BEST ANSWER

There are instructions on the pyFirmata home page that tells you how to configure it for various configurations. You need to use pyfirmata.ArduinoMega, not Arduino.

https://pypi.org/project/pyFirmata/