Problems with C# code for USB Servo


I have done a modest amout of programming in C++ and am making my first steps into robotics.

I purchased a USB 16 Servo controller, installed it, and am running servos through the Pololu Serial Transmitter and getting an expected response from the Servo.

My question is related to getting code to work with the Servo. The “Controlling Servo Motors” tutorial by Colin Karpfinger.
Step 8 says "Take note that once you have added the serialport class to your project, turning the servos takes only 3 lines of code for both protocols: "
I have gotten C# downloaded, but, do not have any idea as to what the serialport class should look like, or where in the code it should be put.

Can anyone offer suggestions?

Thank You,

Hi Steve,
Did you follow Step 7? That’s where you download the code.


Hi Paul,

Yes, I downloaded the PololuServoExample. When I did Build -> Build Solution, the program compiled with no errors.

SerialPortClass serialPort1 = new SerialPortClass();
was added after “Application.Run(new Form1());” in
static void Main(), the program still compiled.

serialPort1.Pololu(comPort, baudRate, 7, servo, servospeed);

was added after
SerialPortClass serialPort1 = new SerialPortClass();
the program would not compile. Errors given included:
Error 1 The name ‘comPort’ does not exist in the current context C:\pavillion\Rubik\RubikCNet\PololuServoExample\PololuServoExample\Program.cs 26 32 PololuServoExample

Error 1 The name ‘comPort’ does not exist in the current context \PololuServoExample\Program.cs 26 32 PololuServoExample
Error 2 The name ‘baudRate’ does not exist in the current context \PololuServoExample\Program.cs 26 41 PololuServoExample

Error 3 The name ‘servo’ does not exist in the current context PololuServoExample\Program.cs 26 54 PololuServoExample

Error 4 The name ‘servospeed’ does not exist in the current context \PololuServoExample\Program.cs 26 61 PololuServoExample

I’m fairly certain that something obvious is missed. Any hints would be greatly appreciated.


OK, I’ve found silly problem number one.

In the previous post I referred to errors when using the following line:
serialPort1.Pololu(comPort, baudRate, 7, servo, servospeed);

In hindsight this was a silly error. comPort, baudRate, 7, etc needed to have a number assigned to them and this was not done!!

The above line was changed to:

serialPort1.Pololu(“Com3”, 9600, 1, 100, 100);

… and the program builds properly. When F5 is pressed, the “Pololu Servo Controller Example by Colin” popup appears. When a number is entered into Servo Coordinates in Pololu Protocol and the Send button is pressed, the servo does not move.
Previously, I had gotten both servos 0 and 1 to move by using Pololu Serial Transmitter v1.2. So I’m sure that the servo and batteries are connected properly.

Any suggestions?

Thank You,

I am not sure if you got your answers for this or not…

I use his code with the 8 servo controller all the time. I had the problem like you are stating and it was because the board supported 2 modes miniSSC and another. in my case you have to remove the jumper to switch between the modes. if the jumper is wrong the code still compiled, but did nothing.

Hi Tim,

Thanks for the reply.

I found out that I made “Silly mistake number 2”, which was leaving in the line that calls up Colin’s control panel. Once this line was deleted it worked well.