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 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. range from 128 – 255) while data bytes always have their most significant bits cleared (i.e. range from 0 – 127). 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 (which include bad commands, incorrectly formatted commands, or even hardware-level serial errors). The qik has a configuration parameter that, if set, will shut down the motors if a serial error occurs, but the qik itself will continue running and accepting commands. This is a safety precaution taken in case the serial error occurred during a command that was intended to stop the motors.

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 will start with 0x8_ 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 9, but this is a configuration parameter you can change. Any qik on the line whose device number matches the specified device number will accept the command that follows; all other Pololu devices will 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 9, we could send the following byte sequence:

    in hex: 0xAA, 0x09, 0x0D, 0x7F
    in decimal: 170, 9, 13, 127

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

The qik will respond 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 will be 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.c), and then connect your TTL serial transmit line to each qik’s RX 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 will all automatically detect the baud from the initial 0xAA byte.

Connecting multiple serial outputs to one serial input is more complicated. Each device will only transmit 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 2s9v1 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