Sabertooth Motor Driver - USB Issue On RPI3

Hi all,

I am trying to get a Sabertooth 2x32 Motor Driver to work on a Raspberry Pi3 on Balena using the pysabertooth 0.3.0 library https://pypi.org/project/pysabertooth/0.3.0/

I am trying to connect to the sabertooth driver via USB to control the driver over USB. I have successfully installed the library however when I try to run the sample code they provide I get the following error:

File “/usr/local/lib/python3.7/site-packages/serial/serialposix.py”, line 531, in write
pusher raise portNotOpenError

serial.serialutil.SerialException: Attempting to use a port that is not open

I have used their sample code to do a first trial so perhaps that is the issue as we need to set it up differently on Balena specifically in regards to that ‘/dev/tty.usbserial’ portion of the code? See below:

from pysabertooth import Sabertooth

saber = Sabertooth(’/dev/tty.usbserial’, baudrate=115200, address=128, timeout=0.1)
saber.drive(1, 50)
saber.drive(2, -75)
saber.stop()

Any help would be greatly appreciated. This is our first time using anything attached to USB on RPI/Balenas so I have no experience and am having trouble finding same issue on the Balena forums

Thanks,
Tofino

Hi there – thanks for getting in touch with us. I agree that it seems likely that the /dev/tty.usbserial portion of the code is meant to be a placeholder; usually, this would look something like /dev/ttyUSB0, /dev/ttyACM0, or similar. The simplest way to find this out would be to connect to the host OS using the dashboard terminal or balena ssh, and look at how ls /dev/tty* changes as you insert and remove the USB serial device.

Next, you’ll need to ensure the serial device is shared with the container. As documented here, single container applications are privileged by default, and so they will see the host devices automatically. If you’re using a docker-compose.yml file, that page shows how to share particular devices with a container, or you can add the privileged flag as described here.

Finally, keep in mind that you will want to consider adding a udev rule in order to bind the serial port to the same device name every time; otherwise, it’s possible it could change (/dev/ttyUSB0 becomes /dev/ttyUSB1, say). You can find examples of how to do this in this repo.

Give that a try, and let us know how it goes!

All the best,
Hugh

Thanks Hugh,

Got it all working with your advice above. All good now.

Tofino