Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Controlling SMC G2 24v19 using Python on Raspberry Pi

I have connected two x SMC G2 24v19 via USB to my Raspberry Pi 4b. I am trying to control them as per the provided instructions, however I always see the error:

Traceback (most recent call last):
  File "run_motors.py", line 83, in <module>
    error_status = smc.get_error_status()
  File "run_motors.py", line 59, in get_error_status
    return self.get_variable(0)
  File "run_motors.py", line 40, in get_variable
    .format(len(result)))
RuntimeError: Expected to read 2 bytes, got 0.

It looks like reading from the SMC times out before a response is received.

If I try the example bash script, everything works as expected.

Any thoughts?

Hello.

Can you confirm you are using the original Python code from the “Example serial code in Python” section and that the code still specifies /dev/ttyACM0 as the port name? Can you run ls -l /dev/serial/by-id and post the results here?

- Amanda

Hi Amanda,

Thank you for your response :slight_smile:

I am using the original python code with no edits, and so it still specifies /dev/ttyACM0.

My output for ls -l /dev/serial/by-id:

lrwxrwxrwx 1 root root 13 Jul  6 20:17 usb-Pololu_Corporation_Pololu_High-Power_Simple_Motor_Controller_G2_24v19_36FF-6C06-5046-3539-1841-2543-if00 -> ../../ttyACM0
lrwxrwxrwx 1 root root 13 Jul  6 20:17 usb-Pololu_Corporation_Pololu_High-Power_Simple_Motor_Controller_G2_24v19_36FF-6D06-5046-3539-3543-2543-if00 -> ../../ttyACM1

Can you also post the settings files for both of your SMCs? You can save a copy of the settings using the command-line utility, smcg2cmd, or from the File menu in the Simple Motor Control Center G2.

Can you confirm running the Bash shell script succeeded in moving a motor?

- Amanda

Hi Amanda,

Attached are the settings files of the two controllers.

Using the bash script resulted in successful running of each of the motors.

smc_settings1.txt (2.2 KB)
smc_settings2.txt (2.2 KB)

Your settings files look fine. Can you try increasing the timeout specified on line 77 in the Python code just to be sure there’s nothing slowing down your system and causing the timeouts to happen? Specifically, please change the read_timeout and the write_timeout both to 10.

If increasing the timeouts does not change anything, can you try running the example C code under the “Example serial code for Linux and macOS in C” section so that we can rule out issues with Python and pySerial?

- Amanda