Saturday 27 February 2016

Dagu Mini driver with bluetooth

I bought a Dagu mini driver with bluetooth  . I wanted to set up a easy  remote control robot using any android phone. This arduino based driver fit what I wanted . I had 2 motor driver, 8 digital ports and 6 analog ports. And also 1 port ( of 4 pins ) for bluetooth module. This module is very useful for my purpose. 2 ports for motor, 8 ports which can be used for servo. 6 ports for any analog sensor.
There is also a switch on it. Built in diode to prevent plunging power supply in the wrong way.
Perfect !!!
I got into some problem initially . Arduino error  :

avrdude: stk500_getsync(): not in sync: resp=0x0

I tried many ways to solve it, search through the web and discover nothing (to my surprise ).  
So in the end I solved it by flashing the boot loader . How to flash the boot loader ? I shall do it another day. 
First, for all Arduino, Bluetooth module must be remove before uploading.If in the event that you had damaged the bootloader, you can flash it. Remember take out the bluetooth first. 

Next configure the bluetooth.  Go to Play Store to find the app name Bluetooth Serial Controller .
Install it . Run it . Activate the Connect tab, and it shows you Bluetooth device that you can connect.
Choose HC-06 to connect. If this is the first time you connect, the password is 1234.
When it is connected the Bluetooth light will not flash anymore. Then , it is connected. Next configure your buttons. I has configure it to all these. You can hide, change functions, change text etc.I am preparing for a soccer playing Bluetooth remote control robot. So I have forward and reverse. left and right. Strike, defend and block. let us see how we do it.
At the PREFERENCE tab, once you click it, you can see
 options like Name, command visibility etc
Name , as it implies will show the name . Click on it, change the name of the buttons to what you want. You can see that I changed the buttons name for buttons 2,5,6,7,10, 4,8,12.
 
Next change the command for the buttons.  
"0"  = forward
"1" = backwards
"2 " = left
"3" = right.
"4" =stop.
You can add some more commands to buttons but you have to change the Arduino programs.
 

 
Next we change the visibility to invisible. We are only interested in  some layout and we want to hide some buttons. Or else we will mispress the buttons. The options is a tick box.
 

 Next  the arduino program that I used

 
// Modified by jack on Jan 2015
// Program for dagu mini controller.
//Standard PWM DC control
int M2 = 7;    //ML Direction Control
int M1 = 8;    //MR Direction Control
int E2 = 9;     //ML Speed Control
int E1 = 10;     //MR Speed Control
 
 
void stop(void)                    //Stop
{
  digitalWrite(E1,LOW);   
  digitalWrite(E2,LOW);      
}   
void advance(char a,char b)          //Move forward
{
  analogWrite (E1,a);      //PWM Speed Control
  digitalWrite(M1,HIGH);    
  analogWrite (E2,b);    
  digitalWrite(M2,HIGH);
}  
void back_off (char a,char b)          //Move backward
{
  analogWrite (E1,a);
  digitalWrite(M1,LOW);   
  analogWrite (E2,b);    
  digitalWrite(M2,LOW);
}
void turn_L (char a,char b)             //Turn Left
{
  analogWrite (E1,a);
  digitalWrite(M1,LOW);    
  analogWrite (E2,b);    
  digitalWrite(M2,HIGH);
}
void turn_R (char a,char b)             //Turn Right
{
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);    
  analogWrite (E2,b);    
  digitalWrite(M2,LOW);
}
void setup(void) 
  int i;
  for(i=7;i<=10;i++)
    pinMode(i, OUTPUT);  
 Serial.begin(9600);
Serial.println("-----LED Bluetooth Control-----");
Serial.println("++++++++++ Commands +++++++++++");
Serial.println("Press 0 to move forward.");
Serial.println("Press 1 to move backward.");
Serial.println("Press 2 to move left.");
Serial.println("Press 3 to move right.");
Serial.println("Press 4 to stop.");
Serial.println("nEnter Command: "); 
void loop(void) 
{
  if(Serial.available()){
    char val = Serial.read();
    if(val != -1)
    {
      switch(val)
      {
      case '0'://Move Forward
        advance (100,100);   //move forward in max speed
        break;
      case '1'://Move Backward
        back_off (100,100);   //move back in max speed
        break;
      case '2'://Turn Left
        turn_L (50,50);
        break;       
      case '3'://Turn Right
        turn_R (50,50);
        break;
      case 'z':
        Serial.println(" Error ");
        break;
      case '4':
        stop();
        break;
      }
    }
    else stop();  
  }
  
}



 

No comments:

Post a Comment