Saturday 27 February 2016

How to Flash Dagu Mini Driver Boot loader

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

A lot had been written about the error, but mine was solved loading bootloader. 

I believe flashing boot loader is nothing new. But the process may be abit tricky.
I used Arduino uno to program the Mini driver boot loader. Yes, you may be right. You need another arduino to program the one which you need a new bootloader. Common one is UNO. How to do it ?
1) connect you arduino Uno to PC using USB cable.
2)  Select the correct port to connect. If you do not know, go to Control panel - > device manager -> ports   to look for the port arduino Uno is connected.  If you cannot find, that means Uno is not recognized in your system.

3) select the correct board to connect. In my case Arduino Uno ( not yet mini driver.)

4) In the arduino programmer, load the program called ArduinoISP.  Upload it into arduino Uno.
 
 
5) Next connect your Uno to Dagu Mini driver.

 
 
6) Now in the arduino programmer, change the board to  Arduino  NG or older with ATmega 8.
   You probably need to set programmer as USBasp.
 
7)  Now goto Tools -> burnt boot loader.
8 )  Now you are done. You can now directly detect and upload the mini driver.
 

 
 

 


My Dagu mini driver setup.

To set up a Bluetooth vehicle using Dagu  mini driver and Bluetooth is so easy. Take a look at my configuration. You can use Tamiya base plate or cut your own aluminium base plate, or 3D print it. Also I am using a Tamiya twin gearbox motor to driver the car. You must be wondering why need gear box ? can't we just driver directly from the motor ? The answer is NO ! DC motor is running at a very high speed. so you car could be running too fast. and it consume too much current.



Another setup using 3D printed base and arduino Nano.  

Next, Mount the motor onto the base plate . Connect Lipo  / AA/ NiCD/NIMH batteries to it. I am using some 4X AA batteries holder for this. I also used ball castor for free rotation. It is a bit noise and ruse easily .


 
Aluminium Chasis setup







 

Dagu mini driver alternative programs.

For those who bought the Dagu robot, these are the alternative program to start with .
You can find more information at Dawn robotics blog .

Demo program for a car controlled by Dagu mini driver.
You can actually turn this program into a line tracker using IR sensor like TCRT5000,
or using sonar sensor to detect walls.
Hope this make a good start. If you need, change the motor speed as needed.
 
// Demo program for the Dagu Arduino Mini Driver. Uses dead reckoning
// to try to drive a robot in a square
 
const int LEFT_MOTOR_DIR_PIN = 7;
const int LEFT_MOTOR_PWM_PIN = 9;
const int RIGHT_MOTOR_DIR_PIN = 8;
const int RIGHT_MOTOR_PWM_PIN = 10;
 
const int DRIVE_FORWARD_TIME_MS = 1500;
const int TURN_TIME_MS = 2000;
 
//----------------------------------------------------------
void setup()
{
    // Setup the pins
    pinMode( LEFT_MOTOR_DIR_PIN, OUTPUT );
    pinMode( LEFT_MOTOR_PWM_PIN, OUTPUT );
    pinMode( RIGHT_MOTOR_DIR_PIN, OUTPUT );
    pinMode( RIGHT_MOTOR_PWM_PIN, OUTPUT );
}
 
//----------------------------------------------------------
void loop()
{
    // Drive forwards at 100%
    // Try changing the maximum value to 100 if your car is running too fast.  
    digitalWrite( LEFT_MOTOR_DIR_PIN, HIGH );
    digitalWrite( RIGHT_MOTOR_DIR_PIN, HIGH );
    analogWrite( LEFT_MOTOR_PWM_PIN, 255 );
    analogWrite( RIGHT_MOTOR_PWM_PIN, 255 );
    delay( DRIVE_FORWARD_TIME_MS );
 
    // Turn right at 50%. Stop right motor on left motor.
    // you can change the value from 128 to lower. 
    digitalWrite( LEFT_MOTOR_DIR_PIN, HIGH );
    digitalWrite( RIGHT_MOTOR_DIR_PIN, LOW );
    analogWrite( LEFT_MOTOR_PWM_PIN, 128 );
    analogWrite( RIGHT_MOTOR_PWM_PIN, 128 );
    delay( TURN_TIME_MS );


With these, you can easily start you Dagu vehicle.
You can check out Dawn robotics for their program with Bluetooth, which could be harder for some to understand.
 

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();  
  }
  
}