VB6 code for Maestro USB Servo Controller

It took me a while to find out how to drive the Maestro servo controller via USB from VB6 (Visual Basic 6.0). Here is what I finally did to get it to work…

  1. Connect your computer to the Pololu Maestro by USB cable.

  2. Find what port is being used:
    In WinXP - Click Windows Start, Control Panel, System, Hardware, Device Manager, Ports (COM & LPT)
    Look for (depending which Maestro you have) “Pololu Micro Maestro 6-Servo Controller Command Port (COM2)”

  3. NOTE that in VB6 valid port numbers are 0 to 16 only.
    If your Pololu Maestro installs with a port number higher than 16 then you need to reassign it to 16 or less.
    In WinXP - Reassign Pololu’s “Command Port” from Windows Start, Control Panel, System, Hardware, Device Manager,
    Ports (COM & LPT), right-click, Properties, Port Settings, Advanced, then select an available COM Port Number.

  4. Start a new VB6 project.

  5. Add a MSComm control as MSComm1.

  6. Coding…
    'a) To open Port 2…
    MSComm1.CommPort = 2
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.PortOpen = True 'Open the port

    'b) To set Servo 5 speed to 20…
    MSComm1.Output = Chr(135) + Chr(5) + Chr(20 Mod 128) + Chr(20 \ 128)

    'c) To set Servo 5 acceleration to 8…
    MSComm1.Output = Chr(137) + Chr(5) + Chr(8 Mod 128) + Chr(8 \ 128)

    'd) To set Servo 5 target to 1500µs…
    a = 4 * 1500 'convert to quarter micro-secs
    MSComm1.Output = Chr(132) + Chr(5) + Chr(a Mod 128) + Chr(a \ 128)

    'e) To close the port…
    MSComm1.PortOpen = False

Cheers, Dave