SPI comms with RoboClaw in C


I am a rookie, so please be gentle and keep it as simple as possible for me. I am in the midst of building a project for school where I am taking a Power Wheels child toy and converting it into a remote controlled car, with some extras. I plan to create a GUI application that will run on a PC or tablet; the GUI will display stats (speed, position, nearby obstacles, etc.) from the car as well as live video stream. I will also use the GUI as the conduit between a game controller connected to the PC and a microcontroller on the car. I plan to use Wifi (802.11 b/g/n) to connect the PC to the microcontroller, although the video feed will be on a separate network. Obviously, there is a lot to do (maybe more than I can chew).

The hardware as of now consists of:
Steering control - Linear actuator (LACT4P-12V-5 with encoder), controlled by to Jrk 21v3
Drive control - 2 brushed DC motors that are a part of the Power Wheels car assembly, controlled by 2x30A motor controller with USB
Control logic - Freescale Tower system with MCU9S12G128 microcontroller

I decided to start with creating the communication and control code for the connection between the RoboClaw and the MCU. The code for the MCU is written in either C or C++, the compiler I plan to use CodeWarrior (a Freescale product). After reading the RoboClaw user manual I think I would like to use the Packet Serial mode for communications. I have the RoboClassLib, but do not know for sure if it is C or C++ compatible and don’t have a list of the functions or definitions. I looked for some C code examples to get me started (I seem to have writers block at the moment), but was not able to find anything relevant.

I will apologize in advance as I have probably left out some important details or misrepresented something. Any guidance would be greatly


It sounds like you are asking about the RoboClaw C# class library found in the “Resources” tab for the RoboClaw 2x30A. The RoboClawClassLib class is not compatible with either C or C++.

You might consider taking a look at the RoboClaw Arduino library, which should give you an idea on how to send and receive serial data between a microcontroller (such as your Freescale microcontroller) and your RoboClaw. The Arduino library can also be found under the “Resources” tab on the RoboClaw 2x30A’s product page.

- Amanda

Hmm, That’s not good news. I can only use C or C++ to write the code for the microcontroller. I am only really interested in using 2 of the command lines in the advanced serial packet mode, commands 24 and 25, read main and logic battery voltages. After reading the manual a little more closely I don’t think this will be to difficult to figure out.

I have another question about using the IonMotion application with the RoboClaw. Actually better said, I can’t seem to get my PC to connect the RoboClaw through IonMotion. I have used the “install.bat” file to install the drivers on my PC. I have the RoboClaw connected to my computer via a USB port. In IonMotion, I only have the choice of using com 3 or com 4, RIM virtual serial ports v2, to connect. Any guidance?

Thanks Tom

Hi, Tom.

The IonMotion software should automatically detect the COM port of your USB RoboClaw when connected to your computer. However, the RoboClaw is not powered from the USB cable and needs to be externally powered as stated in the “USB Control” section of the RoboClaw user’s guide. You can find the user’s guide under the “Resources” tab of its product page and on the Orion Robotics website. If you have not already done so, could you try powering your RoboClaw from an external source before connecting it to your computer to see if the IonMotion software is able to connect to your RoboClaw successfully?

- Amanda

I have already done so with no success. I have the RoboClaw powered externally (not via the USB cable). I have been able to set the baud rate, mode, and other features, so I am confident that the power is sufficient and the RoboClaw is booted successfully.

Usually when a USB device is connected to the PC an notification window will pop-up (I am running Win 7 OS by the way). However when I connect the RoboClaw (after it has already been powered) it does not appear to be recognized at all. I even watched the Ports in the device manager window, but did not see any change.

Do you have any other suggestions?

Find a linux machine (a Raspberry Pi will do,) plug it into the linux machine, and then run “lsusb” to see what USB devices are visible.
This will let you know whether the RoboClaw USB bus is working at all, which will determine what to try next.
Also, make sure you’re trying a few different cables – some micro-USB cables actually only run the power wires (for charging phones,) not the data wires (to save money.)

It is possible the USB RoboClaw Windows drivers were not installed properly. Could you try reinstalling the drivers and connect your RoboClaw to your computer to see if there is any change?

If you are still having problems, you might consider contacting the manufacturer, Orion Robotics.

- Amanda

I thought there might be a possibility that the driver was not installed correctly as well, so I had already re-installed. That is if I am installing it correctly by running the “install.bat” file that was in the “USB RoboClaw Virtual Comport” folder that I downloaded. Please let know if I should install/update the driver in a different way. I will try another USB cable, but the one I am using communicates with both the Jrk motor controller and my Freescale microcontroller.

I tried to get in touch with Orion Robotics via the forum on their webpage, but there doesn’t seem to be a forum. I will try again through a different means, either call of email tech support.

Hi, Tom.

Running the install.bat file seems like the right way to install the drivers. Once you have a resolution from Orion Robotics, we would be interested to know what the issue was.


I spoke to Orion today. I found out that, at least initially, the USB should connected after the RoboClaw is powered unless the RoboClaw is in Mode 15. If you power the RoboClaw and then connect the USB (with Win 7) you will see the automatic driver connection utility window pop up and assign a virtual com port, in my case the com port was created as Com8.

Thanks for letting us know what you found out from Orion Robotics. It sounds like you were able to get it to work by powering the RoboClaw before connecting it to the computer; is that correct?


I was, however I found out that I received a motor controller with a problem. When I contacted Orion I worked with the tech to determine that there is a definetally a internal problem with the controller. They told me to return it and they would fix or replace and send back to me. Hopefully I will get it back soon.