6. Using the Serial Interface

6.1. Serial Settings
6.2. Binary Commands
6.2.1. Binary Command Reference
6.3. ASCII Commands
6.3.1. ASCII Command Reference
6.4. Controller Variables
6.5. Cyclic Redundancy Check (CRC) Error Detection
6.6. Daisy Chaining
6.7. Sample Code
6.7.1. Arduino Examples
6.7.2. Orangutan Examples
6.7.3. Cross-platform C Example
6.7.4. Windows C Example
6.7.5. Bash Script Example
6.7.6. CRC Computation in C

The Simple Motor Controller has two serial interfaces that allow you to send commands and receive responses from the controller. The commands and responses are represented as a series of bytes. Serial commands let you set the speed of the motor when the Input Mode is Serial/USB. In any Input Mode, serial commands let you request information about the motor controller’s state and monitor the RC and Analog channel inputs. The serial commands can come from a TTL serial source, such as a microcontroller, transmitted to the motor controller’s RX pin, or they can come via USB transmitted to the controller’s virtual COM port. The Simple Motor Controller treats the two command sources independently and can simultaneously process commands from both sources.

The Simple Motor Controller can also be controlled using its native USB interface (see Section 7).

COM Port

The Simple Motor Controller installs as two devices, one of which is a virtual serial (COM) command port (see Section 3.1 for driver installation instructions). You can identify the COM port number by looking in your computer’s Device Manager:

Windows Vista or Windows 7 device manager showing a Simple Motor Controller.

In Linux, the COM port name will be something like /dev/ttyACM0. In Mac OS X 10.7 or later the COM port name will be something like /dev/cu.usbmodemfa121.

You can use a terminal program or computer software to send commands to this virtual serial port over USB. Most common programming languages have libraries for sending serial data (e.g. Visual C# has a SerialPort class), which makes it easy to write a custom computer program to control the Simple Motor Controller. See Section 6.7 for code examples. The baud rate settings do not matter when communicating through the virtual COM port.

TTL Serial

The Simple Motor Controller’s serial receive line, RX, can receive bytes from a TTL serial source, such as a microcontroller, which allows for integration into embedded systems. The RX line expects a logic-level (0 to 2–5 V, or “TTL”), non-inverted serial signal.

The voltage on the RX pin should not go below 0 V and should not exceed 5 V.

The Simple Motor Controller provides logic-level (0 to 3.3 V) serial output on its serial transmit line, TX. The bytes sent by the motor controller on TX are typically responses to commands that request information, but they can also be data received by the TXIN pin and passed on. If you aren’t interested in receiving TTL serial bytes from the motor controller, you can leave the TX line disconnected. See Section 4.2 for more information on connecting a serial device to the Simple Motor Controller.

The serial interface is asynchronous, meaning that the sender and receiver are separately configured ahead of time to agree on the length of a bit (this is known as the “baud rate” and it is usually specified in bits per second, or bps), and each side independently times the serial bits. The Simple Motor Controller has the ability to automatically detect the baud rate, which means that it can be used even when the baud rate of the serial source is unknown as long as the serial source initiates communication by sending the proper baud rate indication byte: 0xAA (written as 170 in decimal notation). The Simple Motor Controller works with baud rates from 1200 to 500,000 bits per second. Asynchronous TTL serial is available as hardware modules called “UARTs” on many microcontrollers, but it can also be “bit-banged” by a standard digital output line under software control.

The data format is 8 data bits, no parity bit, and one stop bit, which is often expressed as 8-N-1. The diagram below depicts a typical asynchronous, non-inverted TTL serial byte:

Diagram of a non-inverted TTL serial byte.

A non-inverted TTL serial line has a default (non-active) state of high. A transmitted byte begins with a single low “start bit”, followed by the bits of the byte, least-significant bit (LSB) first. Logical ones are transmitted as high (3.3 V) and logical zeros are transmitted as low (0 V), which is why this format is referred to as “non-inverted” serial. The byte is terminated by a “stop bit”, which is the line going high for at least one bit time. The Simple Motor Controller supports fixed baud rates of 1099 bps to 2 Mbps and can automatically detect baud rates up to 500 kbps in auto-detect baud rate mode.

You must wait for at least 1 ms after the Simple Motor Controller powers up or is reset before you start sending data. Anything sent during this first millisecond is likely to be ignored or incorrectly received.

Whenever connecting devices, remember to wire the grounds together, and ensure that each device is properly powered. Unpowered devices with a TTL serial port can turn on or partially on, drawing power from the serial line, which means that extra care must be taken when turning power off and on to reset the devices.

Note: TTL serial is not the same as RS-232 serial. You must use an inverter and level shifter such as a MAX232 or a Pololu 23201a Serial Adapter if you want to interface an RS-232 device with the Simple Motor Controller. Connecting an RS-232 device directly to the Simple Motor Controller can permanently damage it.