User Manual

RoboClaw Series
Brushed DC Motor Controllers
RoboClaw Series User Manual
67
Packet Serial - Arduino Example
The example will start the motor channels independently. Then start turns with mix mode
commands. The program was written and tested with an Arduno Uno with P11 connected to
S1 and P10 connected to S2. Set mode 7 and option 4. Additional example programs can be
downloaded from Ionmc.com.
//Set mode to 7(packet serial address 0x80) and option to 4(38400)
//Includes required to use Roboclaw library
#include "BMSerial.h"
#include "RoboClaw.h"
//Roboclaw Address
#dene address 0x80
//Setup communcaitions with roboclaw. Use pins 10 and 11 with 10ms timeout
RoboClaw roboclaw(10,11,10000);
void setup() {
//Communciate with roboclaw at 38400bps
roboclaw.begin(38400);
roboclaw.ForwardMixed(address, 0);
roboclaw.TurnRightMixed(address, 0);
}
void loop() {
//Using independant motor Forward and Backward commands
roboclaw.ForwardM1(address,64); //start Motor1 forward at half speed
roboclaw.BackwardM2(address,64); //start Motor2 backward at half speed
delay(2000);
roboclaw.BackwardM1(address,64);
roboclaw.ForwardM2(address,64);
delay(2000);
roboclaw.BackwardM1(address,0);
roboclaw.ForwardM2(address,0);
delay(2000);
//Using independant motor combined forward/backward commands
roboclaw.ForwardBackwardM1(address,96); //start Motor1 forward at half speed
roboclaw.ForwardBackwardM2(address,32); //start Motor2 backward at half speed
delay(2000);
roboclaw.ForwardBackwardM1(address,32);
roboclaw.ForwardBackwardM2(address,96);
delay(2000);
roboclaw.ForwardM1(address,0); //stop
roboclaw.BackwardM2(address,0); //stop
delay(2000);
//Using Mixed commands
roboclaw.ForwardMixed(address, 127); //full speed forward
roboclaw.TurnRightMixed(address, 0); //no turn
delay(2000);
roboclaw.TurnRightMixed(address, 64); //half speed turn right
delay(2000);
roboclaw.TurnLeftMixed(address, 64); //half speed turn left
delay(2000);