0

$USD

$USD
TUTORIALS Bluetooth

How to Control An Insectbot Remotely with Bluetooth Joystick

DFRobot Nov 02 2015 1392
For six-legged insectbot, the Mars in the bug world, having controlled by people without using bluetooth would be a pity. The following is a self-designed tutorial on how to control such insectbot using pre-programmed joystick and bluetooth module. Come and experience the comeback of the real Mars!
Step 1: Essential Hardwares
·         1*BLE LINK Bluetooth 4.0 Communication Module
·         1*Programmable joystick/Remote Control Handpiece V2.2
·         1*Insectbot(six-legged version) Compatible with bluetooth 4.0
·         1*Mini usb Cable


Step2: Debugging Bluetooth Module
Configuring bluetooth module through serial port instructions
Completing bluetooth profiles by using the Arduino IDE's own serial monitor. Specific instructions are as follows?
1.Open the Arduino IDE
2. Go to Menu-?Tools-?Serial Port and select the appropriate device
3. Switch on the serial monitor(click on the button on the top right corner of the window)
4. Select ‘No line ending’ and 115200 baud rate from the two drop-down lists at the bottom right corner
5.Type"+++" in the input box and click send
6. Once you receive ‘Enter AT Mode’, you have entered in the AT command mode.

Set the Bluno Beetle from the Insectbot as the slave, set the baud rate as 115200 and the instructions are as follows?
 
5. Select ‘Both NL & CR’ and 115200 baud from the two drop-down lists at the bottom right corner
6. Type in AT instruction in the input box and click send. Tpye in AT+UART=115200 to set the baud rate
7. If BLE is successfully configured?the interface will go back to ‘OK’
8. If you receive ‘ERROR CMD’ , you can send the instruction again?If ‘ERROR CMD’keeps coming up after several sending, you need to check if you have sent the right instructions.
 
 
Tpye in AT+UART=115200 to set baud rate

Type in AT+ROLE=ROLE_PERIPHERAL to install the bluetooth module set as the slave

Connect the modules to power and check if they can be well connected (link lights of both master and slave machines are on).The lights will not be off when master and slave machines are working in pairs under normal utilization. If the master machine disconnects from the slave machine due to long distance, then the instructions for setting lights of master and slave machines are as follows:
 
Using the same method to set the BLE LINK Bluetooth 4.0 communication module as the master machine?type in AT+ROLE=ROLE_CENTRAL under the AT instruction mode?.The light will flash all the time if baud rate is set as 115200. If they come closer further?they will find each other and connect automatically again. Master machine will memorize its own configured slave. Once supplied with power, the master machine will search for the address of its own memorized slave.


STEP3: Debugging the joystick
Install bluetooth module on the xbee slot of the programmable joystick motherboard, check if the joystick buttons function normally by using key press test procedure outlined in the data bank of handles

The instructions for rewriting the joystick's program:

int buttonState[17];
int joystick[4];
int AnalogButton[2];
void setup()
{
 Serial.begin(115200);  //Init the Serial baudrate
 Serial1.begin(115200);//Baud rate of initialized serial port 1 is 115200
 InitIO();             // Initialize the inputs/outputs and the buffers
}
void InitIO(){
 for(int i = 0; i < 17; i++) pinMode(i, INPUT);
}
void loop()
{
 DataUpdate();  //read the buttons and the joysticks data
 printData();   //print the datas and states
 delay(720);   //calculate the time for the Insectbot to complete a whole set of movement
}
void DataUpdate(){
  
 for(int i = 3; i < 17; i++)  buttonState = digitalRead(i);
 buttonState[0] = analogRead(0);
 buttonState[1] = analogRead(1);
 for(int i = 0; i < 4; i++)  joystick = analogRead(i);
 for(int i = 4; i < 6; i++)  AnalogButton[i-4] = analogRead(i);
  
}
String Buttons[17] = {
 "J2","J1","NULL","S2","S1","UP","LEFT","DOWN","RIGHT","1","4","2","3","RZ1","RZ2","LZ1","LZ2"};
 // Buttons Nmes
void printData(){
  
  for(int i = 3; i < 17; i++)  if(buttonState == 0)  Serial1.print(i),Serial.print(i);//to simplify the calculation, analog quantity 8 from the joystick is not exported.
}



Upload the following codes for the Insectbot (send the serial ports data back)

void setup()
{ Serial.begin(115200);  //initial the Serial} void loop()
{   
if(Serial.available())   
{        
Serial.write(Serial.read());    //send what has been received   
}
}


Test if the bluetooth joystick is well connected with Bluno beetle from the Insectbot.

Step3?Debugging the Insectbot
Delete the hidden parts of the Insectbot's original program and insert bluetooth control codes
void loop()
{        
if (Serial.available() > 0) {// only send what has been received        
incoming = Serial.read();  // read what has been imported
                //Serial.println(incoming, DEC); // instruct what you have received
 
if(incoming== 53)                    //Foward
forward();
else if(incoming== 55)              //Reverse
reverse();
else if(incoming== 54)              //LeftTurn
leftTurn();
else if(incoming== 56)              //RightTurn
rightTurn();
        }
else{
stay();                             //Stop
        }
}
 
For completed codes please refer to the attachment

 
Step4: Final Debugging
Switch on to see if the insectbot can make movement according to your instructions. Fine tune the insectbot's outlook so that it can finish instructions more accurately.

Step5: Completion
Switch on and try your own insectbot with remote control joystick! Change codes of your insectbot to give it a more characterized walk.
 
Presentation Shot