Pyfirmata throws error after creating arduino object

Question:

I’m trying to start an arduino project but every time I try running it it throws an error. I think I might have gotten some of the setup wrong?

I’ve uploaded the Standard Firmata Sketch to the Arduino Mega and installed pyFirmata. I can’t really think of what else I could’ve done wrong.

Note that I’d already tried in another computer and, while it didn’t really work, the board was initialized and it didn’t throw any error like this

This is my python code

import pyfirmata as pf

board = pf.ArduinoMega('COM5')

And this is the eror thrown

Traceback (most recent call last):
  File "C:UsersstikyDesktopCodePython CodesArduinotest.py", line 3, in <module>
    board = pf.ArduinoMega('COM5')
            ^^^^^^^^^^^^^^^^^^^^^^
  File "C:UsersstikyAppDataLocalProgramsPythonPython311Libsite-packagespyfirmata__init__.py", line 32, in __init__
    super(ArduinoMega, self).__init__(*args, **kwargs)
  File "C:UsersstikyAppDataLocalProgramsPythonPython311Libsite-packagespyfirmatapyfirmata.py", line 101, in __init__
    self.setup_layout(layout)
  File "C:UsersstikyAppDataLocalProgramsPythonPython311Libsite-packagespyfirmatapyfirmata.py", line 157, in setup_layout
    self._set_default_handlers()
  File "C:UsersstikyAppDataLocalProgramsPythonPython311Libsite-packagespyfirmatapyfirmata.py", line 161, in _set_default_handlers
    self.add_cmd_handler(ANALOG_MESSAGE, self._handle_analog_message)
  File "C:UsersstikyAppDataLocalProgramsPythonPython311Libsite-packagespyfirmatapyfirmata.py", line 185, in add_cmd_handler
    len_args = len(inspect.getargspec(func)[0])
                   ^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?

What am I doing wrong?

Asked By: Sumito

||

Answers:

This is probably a compatibility issue between PyFirmata and your Python version.

getargspec is deprecated since Python 3.11.

An up-to-date PyFirmata version should have replaced this by getfullargspec.

https://github.com/tino/pyFirmata/commit/1f6b116b80172e70c7866d595120413078ae1222

Also the PyFirmata documentations says

It runs on Python 2.7, 3.6 and 3.7.

So I would not necessarily expect 3.11 to run without problems.

Answered By: Piglet