User Guide

Motor Controller W/A/S/D Computer Control Code
ThecodebelowallowsserialcommandstobesenttotheDFRobotShopRoverbyeitherawired
(USB)orwireless(Bluetooth,XBee)connection.Ifyouareplanningtocreateyourowncode,you
canusethistogetabasicunderstandingastohowtorunthemotors.Thekeyboardcommands
are:
"w":driveforward
"a":rotateclockwise(i.e.left)
"s":rotatecounterclockwise(i.e.right)
"d":drivebackward
Theroverwillexecutethecommandsenttoituntilitistoldtostopbypressinganyotherkeyon
thekeyboard.CommandscanbesentviatheArduinoserialterminal,thoughyoumustpressthe
“enter”keyforthecommandtobesent.InterfacessuchasHyperterminalforWindowscanalso
beused.
EnsureyouselectthecorrectCOMportand9600baudrate.TheBaudratefortheBluetooth
modulecanbe9600or115,200dependingonthemodule–checkthemanualtobecertain.
Notethatitislikelythetwomotorsarenotidenticalandyouwillneedtoadjustthespeedslightly
sotherobotgoesroughlystraight.Notethatencodershelptherobotmoveinastraightline.
/*Tocontroltherover,copyandpastethecodebelowintotheArduinosoftware*/
intE1=6;//M1SpeedControl
intE2=5;//M2SpeedControl
intM1=8;//M1DirectionControl
intM2=7;//M2DirectionControl
voidsetup(void)
{
inti;
for(i=5;i<=8;i++)
pinMode(i,OUTPUT);
Serial.begin(9600);//Thereforeifyousendserialcommands,theyshouldbeat9600baud,Xon/Xoff
}
voidloop(void)
{
while(Serial.available()<1){}//Waituntilacharacterisreceived
charval=Serial.read();
intleftspeed=255;//255ismaximumspeed
intrightspeed=255;
switch(val)//Performanactiondependingonthecommand
{
case'w'://MoveForward
forward(leftspeed,rightspeed);
RobotShopInc.www.RobotShop.com