Roboclaw Raspberry Pi 3 USB communication problem

Hi. I am trying to control a 2x30A roboclaw using Rasberry Pi 3. The two are connected using a USB-microUSB cable, and I tried to run this sample code via RPI terminal ($ python simplePWM.py):

import time
from roboclaw import Roboclaw

#Linux comport name
rc = Roboclaw("/dev/ttyACM0",115200)

rc.Open()
address = 0x80

while(1):
	rc.ForwardM1(address,32)	#1/4 power forward
	rc.BackwardM2(address,32)	#1/4 power backward
	time.sleep(2)
	
	rc.BackwardM1(address,32)	#1/4 power backward
	rc.ForwardM2(address,32)	#1/4 power forward
	time.sleep(2)

	rc.BackwardM1(address,0)	#Stopped
	rc.ForwardM2(address,0)		#Stopped
	time.sleep(2)

	m1duty = 16
	m2duty = -16
	rc.ForwardBackwardM1(address,64+m1duty)	#1/4 power forward
	rc.ForwardBackwardM2(address,64+m2duty)	#1/4 power backward
	time.sleep(2)
	
	m1duty = -16
	m2duty = 16
	rc.ForwardBackwardM1(address,64+m1duty)	#1/4 power backward
	rc.ForwardBackwardM2(address,64+m2duty)	#1/4 power forward
	time.sleep(2)

	rc.ForwardBackwardM1(address,64)	#Stopped
	rc.ForwardBackwardM2(address,64)	#Stopped
	time.sleep(2)

but got this error:

Traceback (most recent call last):
File “simplePWM.py”, line 2, in
from roboclaw import Roboclaw
File “/home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/roboclaw/init.py”, line 1, in
from .roboclaw import RoboClaw
File “/home/pi/.virtualenvs/cv/local/lib/python2.7/site-packages/roboclaw/roboclaw.py”, line 9, in
from roboclaw.roboclaw_cmd import Cmd
ImportError: No module named roboclaw_cmd

I am using python 2.7 on Raspberry Pi and installed roboclaw library using “pip install roboclaw” command. Any help regarding this would be appreciated!

Hello.

It sounds like you are using this library. From the README.md, it says the library was tested for Python 3.5 and 3.6 and will probably not work for Python 2. If there is no particular reason for you to use Python 2, I suggest trying the library with Python 3.5 or Python 3.6 instead. Otherwise, you can try contacting the author of that library and asking for help on getting the library to work with Python 2.

- Amanda

1 Like

Hello, I’m hoping you can help me. I’ve tried a lot of forums.

I bought a Roboclaw 2x15, and so far all I have is a very expensive piece of useless hardware. :(:slightly_frowning_face::weary:

I have downloaded and tried the python (2.7 they tell me) examples, no luck. I can do some python but have no idea about packages, directories, etc. Much more familiar with C/C++/Java.

I have also tried looking at the suggested arduino C++ code but then starts the problem of where to get the arduino headers… I am trying to do this on a Raspberry Pi 3 B , Raspbian , the latest.

My error with the python is:

**AttributeError: Roboclaw instance has no attribute '_port'.**

I’m told I need pyserial. Except I’ve done the following:

sudo apt-get install python-serial

and also tried

sudo apt-get install python3-serial

no luck

my dpkg says the following:

dh-python					install
libpython-stdlib:armhf				install
libpython2.7-minimal:armhf			install
libpython2.7-stdlib:armhf			install
libpython3-dev:armhf				install
libpython3-stdlib:armhf				install
libpython3.5:armhf				install
libpython3.5-dev:armhf				install
libpython3.5-minimal:armhf			install
libpython3.5-stdlib:armhf			install
python						install
python-apt-common				install
python-minimal					install
python-pip-whl					install
python-serial					install
python2.7					install
python2.7-minimal				install
python3						install
python3-apt					install
python3-cffi-backend				install
python3-crypto					install
python3-cryptography				install
python3-dbus					install
python3-dev					install
python3-gi					install
python3-idna					install
python3-keyring					install
python3-keyrings.alt				install
python3-minimal					install
python3-pip					install
python3-pkg-resources				install
python3-pyasn1					install
python3-secretstorage				install
python3-serial					install
python3-setuptools				install
python3-six					install
python3-wheel					install
python3-xdg					install
python3.5					install
python3.5-dev					install
python3.5-minimal				install

I separately tried an “unofficial python library” from :

but when I run a very simple script, I get an import error. I know a lot of this might be just my ignorance… but I’ve not gotten any answers anywhere…

Traceback (most recent call last):
  File "myprog.py", line 1, in <module>
    from roboclaw import RoboClaw
ImportError: No module named 'roboclaw'

all I did for the one directly above was:

pip3 install roboclaw

any tips / help very much appreciated.

thank you
–Eli

Thanks for your responses. I had to contact RoboClaw and they told me pip install roboclaw does not install roboclaw library. I simply had to download the library from roboclaw website and copy it to the same folder as my program :slight_smile:

1 Like

Hello, Eli.

I noticed you posted on Basic Micro’s Roboclaw Motor Controllers forum here and received a few responses. You should probably continue troubleshooting with them.

- Amanda