4.c. Command Protocols

Once the qik has entered the normal operation phase, you can control it by issuing serial commands. If your qik is set to automatically detect the baud, you must first send it the byte 0xAA (170 in decimal) in order to exit autodetect mode and enter normal operation.

The qik serial command protocol is fairly simple. Communication is achieved by sending command packets consisting of a single command byte followed by any data bytes that command requires. Command bytes always have their most significant bits set (i.e. they range from 128 – 255, or 0x80 – 0xFF in hex) while data bytes always have their most significant bits cleared (i.e. they range from 0 – 127, or 0x00 – 0x7F in hex). This means that each data byte can only transmit seven bits of information.

One significant improvement over earlier Pololu serial controllers is the qik’s error handling, which allows the user to specify responses to serial errors (including unknown commands, incorrectly formatted commands, and hardware-level serial errors), motor fault errors, and motor over-current errors. The qik has a configuration parameter that determines if the motors shut down when various errors occur, but the qik itself continues running and accepting commands.

The qik responds to two sub-protocols:

Compact Protocol:

This is the simpler and more compact of the two protocols; it is the protocol you should use if your qik is the only device connected to your serial line. The qik compact protocol command packet is simply:

command byte (with MSB set), any necessary data bytes

For example, if we want to set motor M1 to full speed forward using the compact protocol, we could send the following byte sequence:

    in hex: 0x8D, 0x7F
    in decimal: 141, 127

The byte 0x8D is a command for M1 forward, and the data byte contains the motor speed. Note that every qik command byte starts with 0x8_ or 0x9_ when using the compact protocol.

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 qik on a single serial line along with our other serial controllers (including additional qiks) and, using this protocol, send commands specifically to the desired qik without confusing the other devices on the line.

The Pololu protocol is to transmit 0xAA (170 in decimal) as the first (command) byte, followed by a device-number data byte. The default device number for the qik is 10, but this is a configuration parameter you can change. Any qik 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, device # byte, command byte with MSB cleared, any necessary data bytes

For example, if we want to set motor M1 to full speed forward for a qik with device number 10, we could send the following byte sequence:

    in hex: 0xAA, 0x0A, 0x0D, 0x7F
    in decimal: 170, 10, 13, 127

Note that 0x0D is the command 0x8D with its most significant bit cleared. Since all compact-protocol command bytes start with 0x8n or 0x9n, these bytes all turn into data bytes 0x0n or 0x1n, respectively.

The qik responds to both the Pololu and Compact protocols on the fly; you do not need to use a jumper or configuration parameter to identify which protocol you are using.

Procedure for Daisy-Chaining

Daisy-chaining multiple qiks together on the same serial line is simple. Individually assign each qik a different device ID using the set configuration parameter command (see Section 5.d), and then connect your TTL serial transmit line to each qik’s RX line or your RS-232 serial transmit line to each qik’s SIN line. If you wish, you can connect all of the qiks’ ERR lines to a single input on your controlling module. When you issue your first Pololu-protocol command, the qiks all automatically detect the baud from the initial 0xAA byte.

Connecting multiple serial outputs to one serial input is more complicated. Each device only transmits when requested, so if each unit is addressed separately, multiple units will not transmit simultaneously. However, the outputs are driven, so they cannot simply be wired together. Instead, you can use an AND gate (since the idle state is high).

If you want to daisy-chain a qik with other Pololu devices that use 0x80 as an initial command byte, the procedure becomes slightly more complicated. You should first transmit the byte 0x80 so that these devices can automatically detect the baud rate, and only then should you send the byte 0xAA so that the qik can detect the baud rate. Once all devices have detected the baud rate, Pololu devices that expect a leading command byte of 0x80 should ignore command packets that start with 0xAA, and qiks will ignore command packets that start with 0x80.

Related Products

Pololu Qik 2s12v10 Dual Serial Motor Controller
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