Standard Serial Mode with Arduino

Spread the love

In standard serial mode, called Simple Serial in Motion Studio, a RoboClaw motor controller accepts single-byte commands from any TTL serial device. This guide wires an Arduino to a RoboClaw, configures Simple Serial mode at 38400 baud in Motion Studio, and runs a complete sketch that drives both motor channels.

Arduino Uno wired to a RoboClaw 2x7A motor controller with jumper wires for standard serial control
Figure 1: An Arduino Uno wired to a RoboClaw 2x7A for standard serial control.

Standard serial is the simplest way to drive a RoboClaw from a microcontroller: the Arduino sends single bytes over one wire and the RoboClaw translates each byte into a direction and power level for one of its motor channels. No library is required. Communication is one way only, so the RoboClaw receives commands but never transmits, and encoder feedback is not supported in this mode. For error-checked, two-way control with encoder support, use packet serial mode instead (see Next Steps).

This guide works with any RoboClaw model. The example sketch uses SoftwareSerial, which is available on AVR-based Arduino boards such as the Uno and Nano. The RoboClaw’s serial input accepts 5V and 3.3V logic, so both 5V and 3.3V boards connect directly without level shifting.

Some photos in this guide show an older RoboClaw revision with onboard configuration buttons. Button configuration is deprecated; all current RoboClaw models are configured with Motion Studio.

What You Need

Wire the Arduino to the RoboClaw

  1. Follow the RoboClaw Quick Start Guide to mount the motors, connect power, and verify basic operation in Motion Studio.
  2. Disconnect power from the RoboClaw by removing the positive battery lead.
    Never remove only the negative battery lead while the Arduino has its own power supply and shares a ground with the RoboClaw. With the negative lead removed, the RoboClaw pulls its ground return current through the Arduino’s ground pin and the jumper wire, which can damage the Arduino. Disconnect the positive lead, or both leads, instead.
  3. Wire the Arduino and RoboClaw together with the two jumper wires, using the table below and Figure 1 as a reference.
    Function Arduino RoboClaw
    Transmit Pin 11 S1 signal pin (pin closest to the edge of the board)
    Ground Any Arduino ground pin Ground pin on the S1 header (pin closest to the inside of the board)
  4. Reconnect power to the RoboClaw.

Configure Simple Serial Mode in Motion Studio

  1. Connect the RoboClaw to the computer with the USB cable, then open BasicMicro Motion Studio and connect to the RoboClaw.
  2. Click “General Settings” on the left side of the application. In the pane labeled “Setup”, set the control mode to “Simple Serial”.
    BasicMicro Motion Studio General Settings screen with the control mode set to Simple Serial and the baudrate set to 38400
    Figure 2: Configuring Simple Serial mode and the baud rate in Motion Studio.
  3. In the pane labeled “Serial”, set the baudrate to “38400”. The RoboClaw supports rates from 2400 to 460800; this guide uses 38400 to match the example sketch.
  4. Save the settings to the board by selecting “Save Settings” from the File menu, then disconnect the RoboClaw in Motion Studio and unplug its USB cable. Power cycle the RoboClaw so the new control mode takes effect.

Upload and Run the Sketch

  1. Open the Arduino IDE, create a new sketch, and replace its contents with the complete sketch below.
    #include <SoftwareSerial.h>
    
    SoftwareSerial serial(10, 11);
    
    void setup() {
      serial.begin(38400);
    }
    
    void loop() {
      //Run motor 1 forward at about half power
      serial.write(94);
      delay(2000);
      //Stop motor 1
      serial.write(64);
      delay(2000);
      //Run motor 1 backward at about half power
      serial.write(32);
      delay(2000);
      //Stop motor 1
      serial.write(64);
      delay(2000);
    
      //Run motor 2 forward at about half power
      serial.write(223);
      delay(2000);
      //Stop motor 2
      serial.write(192);
      delay(2000);
      //Run motor 2 backward at about half power
      serial.write(160);
      delay(2000);
      //Stop motor 2
      serial.write(192);
      delay(2000);
    }
    SoftwareSerial is only available on AVR-based Arduino boards such as the Uno and Nano, and the sketch must include SoftwareSerial.h at the top. On other Arduino models, use a hardware serial port instead. On boards where the hardware serial port is wired to the built-in USB-to-serial adapter, the USB cable must be disconnected while the sketch runs.
  2. Connect the Arduino to the computer with its USB cable and upload the sketch.
  3. Once the sketch runs, motor 1 runs forward at about half power, stops, runs backward, and stops. Motor 2 then repeats the same pattern. If nothing moves, check the ground connection between the RoboClaw and the Arduino, confirm pin 11 connects to the S1 signal pin, and verify the baud rate saved to the RoboClaw matches the sketch.

How the Sketch Works

The sketch calls a single function to communicate with the RoboClaw: serial.write(). In standard serial mode the RoboClaw accepts one byte at a time, and each byte sets the direction and power level for one motor channel. Values 1 through 127 control channel 1, values 128 through 255 control channel 2, and a value of 0 stops both channels. The RoboClaw maps the byte values as shown in the table below.

Value Function
0 Stops channels 1 and 2
1 Channel 1 full reverse
64 Channel 1 stop
127 Channel 1 full forward
128 Channel 2 full reverse
192 Channel 2 stop
255 Channel 2 full forward

Values between the stop point and either endpoint scale the power proportionally. The sketch’s value of 94, for example, runs channel 1 forward at about half power, and 223 does the same for channel 2.

Managing Communication Errors

Standard serial mode has no error checking or acknowledgement: if a command byte is corrupted or lost, nothing indicates that anything went wrong. To minimize the impact of communication errors, send the current command byte in a periodic, repeating manner, every 50 milliseconds or faster.

As an added safety measure, set the Timeout value in the Serial pane of Motion Studio’s General Settings. When the timeout is set, the RoboClaw automatically stops both motors if no command arrives within the selected period (0.1 to 25.5 seconds). A value of 0 disables the timeout.

Next Steps