Help with simple program for 18v15


I have an 18v15 Simple Motor Controller connected via mini-USB to my PC, in turn connected to a 12V DC reversible motor with its 12V power supply.
I have been using Microsoft Visual Studio 2013 to look at the code in the Pololu USB SDK and I’ve changed one of the examples provided (one where on clicking the ‘Forward’ button, the motor drives forward, likewise in reverse) to the following;

Imports Pololu.UsbWrapper
Imports Pololu.SimpleMotorController
Imports System
Imports System.Text
Imports System.ComponentModel

Public Class MainWindow
    ''' <summary>
    ''' This function runs when the user clicks the Forward button.
    ''' </summary>
    Sub forwardButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles forwardButton.Click
            Using device As Smc = connectToDevice() ' Find a device and temporarily connect.
                device.resume()                     ' Clear as many errors as possible.
                device.setSpeed(1600)               ' Set the speed to half forward (+50%).

            End Using
        Catch exception As Exception     ' Handle exceptions by displaying them to the user.
        End Try
    End Sub

What I am looking for it to do, is on clicking ‘Forward’, it executes a series of motions (as opposed to just going forward and nothing else) that are timed.

So instead of;
device.setSpeed(1600) ‘drive the motor forward at half speed’

I am looking to make it go forward for say, 2s, then reverse for 2s, then forward again for 4s etc.

However I’ve been through all the code examples (and the auto-fill functions in Visual Studio) and can’t find something that is pointing me in the right directions in terms of code that would allow me to set the durations while going from forward to reverse, without clicking on the other buttons designed to stop and reverse it.

Any assistance would be greatly appreciated, I’ve spent quite a few hours trying to figure this out and I feel like I’m going around in circles at this point.


I have a Simple Motor Controller (18v15) connected via USB to a PC. Also connected to the controller is a DC reversible 12V motor and a 12V power supply.

I have downloaded the USB SDK from Pololu’s website and have successfully executed the code examples through Microsoft Visual Studio. I am trying to modify ‘Smcexample1’ to do what I want to do as opposed to writing a program from scratch as I am a relative beginner at coding.

What I am trying to do, is on clicking the ‘Forward’ button in the example, for the motor to execute a series of actions with timed durations. E.g. instead of simply going forward, to go forward at 50% speed for 0.5s, 50% speed reverse for 0.5s, forward at 100% speed for 1s, reverse at 100% speed for 1.5s etc. I understand each action is terminated when conditions are met but I just don’t know how to write that line of code. The code I am looking at is;

/*  SmcExample1:
 *    Simple example GUI for the Pololu Simple Motor Controller,
 *    written in Visual C#.
 *    Features:
 *       Native USB connection using Smc class
 *       Forward button
 *       Reverse button
 *       Stop button
 *  NOTE: The Input Mode of your Simple Motor Controller must be set to Serial/USB
 *  for this program to work properly.  You must also connect USB, motor power,
 *  and your motor.  If this program does not work, use the Pololu Simple Motor
 *  Control Center to check what errors are occurring.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using Pololu.UsbWrapper;

namespace Pololu.SimpleMotorController.SmcExample1
    public partial class MainWindow : Form
        public MainWindow()

        /// <summary>
        /// This function runs when the user clicks the Forward button.
        /// </summary>
        void forwardButton_Click(object sender, EventArgs e)
                using (Smc device = connectToDevice())  // Find a device and temporarily connect.
                    device.resume();         // Clear as many errors as possible.
                    device.setSpeed(3200);   // Set the speed to full forward (+100%).
<font color="#FF0000">Would here be a delay command? What would that look like?</font>
<font color="#0000BF">Then I assume if I wanted reverse it would be device.setSpeed(-3200) here or something similar?</font>
            catch (Exception exception)  // Handle exceptions by displaying them to the user.

I would greatly appreciate any assistance as I have been looking at this for quite a few hours now and I feel like I’m going around in circles.


A good first step would be to call Thread.Sleep inside the subroutine you are modifying. For example, you could set the speed to be forward, sleep for 2000 milliseconds, and then set it to be something else. The drawback of this approach is that the main thread of your application will be occupied, and you will not be able to interact with the user interface during this time. I do not know if that will be a problem for you.

A more advanced approach would be to use a timer to schedule events to happen in the future. When the timer fires, you can check to see whether the motor speed should be updated, and then update it if needed. Between timer events, the main thread would be free to perform other tasks. You can see an example of this in MaestroAdvancedExample, in the Maestro folder of the Pololu USB SDK. That example was written for another product, so you should probably just look at how the timing was done and copy the timing code into your project.


Hi David,

That’s great information, thanks.
As it turns out I discovered the Thread.Sleep command last night and got it to work with some success. I did notice however that it wouldn’t always work.

What I mean by that is that sometimes it would execute the sequence flawlessly, and other times it would stop partway through. I’m not sure why this is, but I suspected the power supply. For some more information, the motor has the following characteristics;

12V no load current: 1.8A
Max. current: 16A

The power supply is 12V, 120W, 5A max.
Is it possible that when the motor is switching from reverse to forward in quick succession that it sometimes draws more current than the power supply is capable of delivering?

I understand the 18v15 can supply up to 15A of continuous current without a heat sink, so I’m thinking of putting in a 10A supply that I have lying around to see if that improves it. Am I heading down the right track here?

Well the higher power supply definitely made a difference, it executes without stopping no problems now! :astonished:

I currently have the code sequence executing when I click a form button. Does anybody know if there’s a way to link it to the opening of a file? For example, if I wanted to open sample.wav and have the code execute simultaneously. Is this possible?

I am glad you were able to solve your problem. When you quickly switch a motor from full-speed forward to full-speed reverse, it will briefly draw twice the stall current of the motor. The Simple Motor Controller lets you set acceleration and deceleration limits, which can help give you a gradual transition from forward to reverse.

To link the movement to the opening of a file, I would probably try making a Windows batch script that starts the sound playing in the background using START, and then does motor movements with delays. You could use SmcCmd (the command-line utility that comes with the Simple Motor Controller software) to command the motors, and use ping to implement delays between the motor commands. If you use SmcCmd, you would not need to develop the Visual Basic program you have been working on. If you want a better scripting language, some alternatives are AutoHotkey and Bash.

We would be interested in seeing a video of this project once you have it working. Is this for Halloween?