Line 8: Line 8:
 
int MotorLeft[2] = {A0,A1};
 
int MotorLeft[2] = {A0,A1};
 
int MotorRight[2] = {A2,A3};
 
int MotorRight[2] = {A2,A3};
 +
 
void setup()
 
void setup()
 
{
 
{
Line 15: Line 16:
 
Serial.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right");
 
Serial.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right");
 
}
 
}
 +
 
void loop()
 
void loop()
 
{
 
{
Line 33: Line 35:
 
  }     
 
  }     
 
}
 
}
 +
 
//Intialize the motor
 
//Intialize the motor
 
void MotorInit()
 
void MotorInit()
Line 73: Line 76:
 
}
 
}
  
 
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 14:06, 27 August 2014

Intro

For this tutorial we will be using the Explore Robo kit. You may go ahead and download the schematics and other details from the link. To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE

  1. #include <Firmata.h>
  2. int MotorLeft[2] = {A0,A1};
  3. int MotorRight[2] = {A2,A3};
  4.  
  5. void setup()
  6. {
  7. Serial.begin(9600);
  8. MotorInit();
  9. Serial.print("*Explore Robo Mode Computer: Controlled*\n\r");
  10. Serial.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right");
  11. }
  12.  
  13. void loop()
  14. {
  15. int command;
  16. command = Serial.read();
  17. switch(command)
  18. {
  19. case 'w': Robot_Forward(); delay(100); break;
  20. case 's': Robot_Backward(); delay(100); break;
  21. case 'a': Robot_Left(); delay(100); break;
  22. case 'd': Robot_Right(); delay(100); break;
  23. //in case the caps lock is ON
  24. case 'W': Robot_Forward(); delay(100); break;
  25. case 'S': Robot_Backward(); delay(100); break;
  26. case 'A': Robot_Left(); delay(100); break;
  27. case 'D': Robot_Right(); delay(100); break;
  28. default: break;
  29. }
  30. }
  31.  
  32. //Intialize the motor
  33. void MotorInit()
  34. {
  35. int i;
  36. for(i=0 ; i<2; i++)
  37. {
  38. pinMode(MotorLeft[i],OUTPUT);
  39. pinMode(MotorRight[i],OUTPUT);
  40. }
  41. }
  42. //Robot Driving Functions
  43. void Robot_Forward()
  44. {
  45. digitalWrite(MotorLeft[0],0);
  46. digitalWrite(MotorLeft[1],1);
  47. digitalWrite(MotorRight[0],1);
  48. digitalWrite(MotorRight[1],0);
  49. }
  50. void Robot_Backward()
  51. {
  52. digitalWrite(MotorLeft[0],1);
  53. digitalWrite(MotorLeft[1],0);
  54. digitalWrite(MotorRight[0],0);
  55. digitalWrite(MotorRight[1],1);
  56. }
  57. void Robot_Left()
  58. {
  59. digitalWrite(MotorLeft[0],1);
  60. digitalWrite(MotorLeft[1],0);
  61. digitalWrite(MotorRight[0],1);
  62. digitalWrite(MotorRight[1],0);
  63. }
  64. void Robot_Right()
  65. {
  66. digitalWrite(MotorLeft[0],0);
  67. digitalWrite(MotorLeft[1],1);
  68. digitalWrite(MotorRight[0],0);
  69. digitalWrite(MotorRight[1],1);
  70. }