6.2. Binary commands

6.2.1. Binary command reference

This section describes the binary mode commands supported by the Simple Motor Controller G2. These commands are used on the TTL serial port and USB virtual serial port when the “Serial mode” setting is set to “Binary”. The I²C interface only accepts the commands documented here.

Communication is achieved by sending command packets consisting of a single command byte followed by any data bytes that command requires (not all commands require data bytes; some command packets simply consist of a single command byte). Command bytes always have their most significant bits set, while data bytes almost always have their most significant bits cleared:

0x80 (128) ≤ command byte ≤ 0xFF (255)
0x00 (0) ≤ data byte ≤ 0x7F (127)

This means that each data byte can only transmit seven bits of information. The only exception to this is the Mini SSC command, where the command byte is 0xFF, or 255, and the data bytes can have any value from 0x00 to 0xFE (0 to 254).

Some commands are used to read data from the controller, so the controller will generate a response packet. The bytes in the response packet can have any value.

Note: If you are using the TTL serial interface and the motor controller is in auto-detect baud rate mode, you must send the baud rate indication byte 0xAA, or 170, on the RX line before sending any commands. The 0xAA baud rate indication byte can be the first byte of a Pololu protocol command, or it can be transmitted as a single byte. Communication via the controller’s USB virtual serial port or I²C is unaffected by baud rate settings and does not require the transmission of an initial baud rate indication byte.

This guide displays byte values in the format: “hex (decimal)”, where hex is the hexadecimal (base-16) representation of the byte’s value, and decimal is the decimal representation of the byte’s value. The hexadecimal representation starts with the prefix 0x (e.g. 0x10).

Keep in mind that a byte is simply a number between 0x00 (0) and 0xFF (255). For these protocols, the important thing about a byte is its value, not the notation (e.g. hex, decimal, or binary) you use in your source code to write the byte.

The following three sub-protocols are available in binary serial mode:

Compact Protocol

In general, this is the protocol that you should use if a single Simple Motor Controller G2 is the only device that will receive the bytes in your command packets (which is always the case if you are using the I²C or virtual USB serial port). The compact protocol command packet is simply:

command byte (MSB set) [data byte 1] [data byte 2] [data byte n]
1XXXXXXX [0XXXXXXX] [0XXXXXXX] [0XXXXXXX]

For example, if we want to set the motor speed to 3200 (full speed) forward, we could send the following byte sequence:

Hex notation: 0x85, 0x00, 0x64
Decimal notation: 133, 0, 100

The byte 0x85 is the Set Motor Forward command, and the last two bytes contain the speed.

Pololu Protocol

This protocol is compatible with the serial protocol used by our other serial motor and servo controllers. As such, you can daisy-chain a Simple Motor Controller on a single serial line along with our other serial controllers (including additional Simple Motor Controllers) and, using this protocol, send commands specifically to the desired controller without confusing the other devices on the line.

To use the Pololu protocol, you must transmit 0xAA (170 in decimal) as the first (command) byte, followed by a device number data byte. The default device number for the Simple Motor Controller is 0x0D (13 in decimal), but this is a setting you can change. Any controller on the line whose device number matches the specified device number accepts the command that follows; all other Pololu devices ignore the command. The remaining bytes in the command packet are the same as the compact protocol command packet you would send, with one key difference: the compact protocol command byte is now a data byte for the command 0xAA and hence must have its most significant bit cleared. Therefore, the command packet is:

0xAA (170) device number command byte (with MSB cleared) [data byte 1] [data byte 2] [data byte n]
10101010 0XXXXXXX 0XXXXXXX [0XXXXXXX] [0XXXXXXX] [0XXXXXXX]

For example, if we want to set the motor speed to 3200 (full speed) forward, we could send the following byte sequence:

Hex notation: 0xAA, 0x0D, 0x05, 0x00, 0x64
Decimal notation: 170, 13, 5, 0, 100

The byte 0x05 is the Set Motor Forward command (0x85) with its most significant bit cleared.

Mini SSC protocol

The Simple Motor Controller G2 also responds to the Scott Edwards Mini SSC protocol, a simple, three-byte serial protocol commonly used by servo controllers. Since it only takes three serial bytes to set the speed of one motor, this protocol is good if you need to send many commands rapidly to multiple motor controllers. The Mini SSC protocol is to transmit 0xFF (255 in decimal) as the first (command) byte, followed by a device number byte and an 8-bit motor speed byte. If you think of the available motor speeds as ranging from -127 to +127, the motor speed byte is this signed speed value offset by 127. Therefore, a speed byte of 0 results in full-speed reverse, a speed byte of 127 results in speed 0 (motor stopped), and a speed byte of 254 results in full-speed forward. The command packet is:

0xFF (255) device number (0-254) speed byte (0-254)
11111111 XXXXXXXX XXXXXXXX

For example, if we want to set the speed of device 13 to approximately half-speed forward (63+127=190), we could send the following byte sequence:

Hex notation: 0xFF, 0x11, 0xBE
Decimal notation: 255, 13, 190

The device number byte and speed byte can be any value except 255, though the Simple Motor Control Center G2 will not let you set the controller’s device number to a value greater than 127. If the device number byte matches the motor controller’s device number or if the device number byte is 254, the motor controller will respond to the command (all controllers respond to Mini SSC commands addressed to Device Number 254).

The Simple Motor Controller G2 identifies the Pololu, Compact, and Mini-SSC protocols on the fly; you can freely mix commands in the three protocols.

Trying the Binary Serial Interface

If you are having trouble using the Binary protocols, it can help to first use a program like the Pololu Serial Transmitter utility for Windows to send bytes to the Simple Motor Controller G2’s virtual COM port. This program makes it easy send packets of arbitrary bytes, which can help you identify if your problems are with your control software or with the bytes you are trying to send. The Serial Transmitter Utility can even automatically append the appropriate CRC7 byte to the end of the transmitted command packet.

Sending Binary (Compact Protocol) commands to the Simple Motor Controller with the Pololu Serial Transmitter utility.

Related Products

High-Power Simple Motor Controller G2 18v15 (Connectors Soldered)
High-Power Simple Motor Controller G2 18v15
High-Power Simple Motor Controller G2 24v12 (Connectors Soldered)
High-Power Simple Motor Controller G2 24v12
High-Power Simple Motor Controller G2 18v25
High-Power Simple Motor Controller G2 24v19
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors