Arduino IDE to Python- problems with the Firmata library

Hello there! I am trying to create a simple blinking LED in python. I am using the firmata library in Arduino IDE and PyCharm to code the LED. First, I installed the firmata library in Arduino IDE and then uploaded the standard example to my Arduino Mega 2560. That worked fine, but when I switched over to pyCharm with the code below, I got the following errors.

from pyfirmata import Arduino
import time
board = Arduino('COM3')

led = board.get_pin(13)
while True:
    led.write(True)
    time.sleep(1)
    led.write(False)
    time.sleep(1)

Errors:

Traceback (most recent call last):
  File "C:\Users\rajik\PycharmProjects\pineapple\mini_projects\von_mysteriouso.py", line 16, in <module>
    board = Arduino('COM3')
            ^^^^^^^^^^^^^^^
  File "C:\Users\rajik\PycharmProjects\pineapple\.venv\Lib\site-packages\pyfirmata\__init__.py", line 19, in __init__
    super(Arduino, self).__init__(*args, **kwargs)
  File "C:\Users\rajik\PycharmProjects\pineapple\.venv\Lib\site-packages\pyfirmata\pyfirmata.py", line 101, in __init__
    self.setup_layout(layout)
  File "C:\Users\rajik\PycharmProjects\pineapple\.venv\Lib\site-packages\pyfirmata\pyfirmata.py", line 157, in setup_layout
    self._set_default_handlers()
  File "C:\Users\rajik\PycharmProjects\pineapple\.venv\Lib\site-packages\pyfirmata\pyfirmata.py", line 161, in _set_default_handlers
    self.add_cmd_handler(ANALOG_MESSAGE, self._handle_analog_message)
  File "C:\Users\rajik\PycharmProjects\pineapple\.venv\Lib\site-packages\pyfirmata\pyfirmata.py", line 185, in add_cmd_handler
    len_args = len(inspect.getargspec(func)[0])
                   ^^^^^^^^^^^^^^^^^^

Is this a problem regarding how I downloaded the firmata library, or is it my code?

Thank you!!! :grin:

The error you encountered stems from the use of deprecated functions in the inspect module of Python, which causes incompatibility with recent versions of Python and the pyFirmata library.

Specifically here, inspect.getargspec() has been deprecated since Python 3.5 (it was removed in Python 3.11).

if the pyFirmata library still references this function then it's an issue...

One option would be to downgrade your Python version to 3.10 or earlier

Alternatively you could consider using another library like PyMata or pyFirmata2, which should be compatible with newer versions of Python.

(I don't use pyFirmata so I can't really recommend one. If you were willing to develop your own Arduino code and your own python code and get rid of the pyFirmata constraints, I've written a small tutorial on interfacing with Python. See Two ways communication between Python3 and Arduino )

Thank you so much!!! PyFirmata2 worked! :grin::grin::grin:

Good to hear

Have fun