Go Down

Topic: Bluetooth robotic dancer (Read 5354 times) previous topic - next topic

kas

Jun 22, 2013, 09:43 pm Last Edit: Jul 15, 2013, 10:27 pm by kas Reason: 1
This basic pan & tilt robot is controlled via an Android smartphone, using a virtual joystick

http://www.youtube.com/watch?v=-jaszg2t2TY

The code on the Arduino side is rather straighforward
Tip: the SoftwareSerial and the servo libraries don't collaborate happily, I learnt it the hard way  :~

More info re Joystick Bluetooth Commander application here

Enjoy

kas

I posted a BlinkM (RGB LED) project based on Joystick Bluetooth Commander, in the LEDs and Multiplexing Section



Irvin

Interesting. Perhaps you could outfit the robot and make it look a little bit better. Thin layer of plastic? Not sure, I'm still new to this. Also, you could do something along the lines of it being able to function multiple limbs at once: I.E: One arm up, at the same time, another arm going down, while spinning in a circle. You might be able to do something with this in the toy industry.

kas

#3
Jul 23, 2013, 06:56 am Last Edit: Jul 23, 2013, 06:58 am by kas Reason: 1
Thanks for the comments

The robot was quickly assembled using available parts, including an old parallax sonic sensor for the head ;)
The all project is just a proof of concept for the Joystick Bluetooth Commander application

kas

#4
Aug 03, 2013, 08:02 am Last Edit: Aug 03, 2013, 08:04 am by kas Reason: 1


Joystick Bluetooth Commander Version 2.5 here

kas

#5
Aug 21, 2013, 06:37 pm Last Edit: Aug 21, 2013, 06:43 pm by kas Reason: 1
Hi Rosamunda

Here is the Arduino side code:
Code: [Select]
// Andro_Pan&Tilt      V2.6
// Arduino test sketch for Joystick BT commander
// Controls two servo motors

// V2.6 can receive both Byte (Joystick BT commander V2.5)& Integer data (V3.0)
// V2.0: removed SoftwareSerial

//  Arduino pin #0  to  TX Bluetooth module

#include <Servo.h>

#define    DEBUG          false

#define    ledPin         13              // LED pin
#define    pinServo_X     9
#define    pinServo_Y     10
#define    STX            0x02
#define    ETX            0x03
#define    MIN_Y          45             // vertical move limitation
#define    MAX_Y          180            // horizontal move limitation
#define    ZERO_Y         60

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                         // create servo object
Servo myservoY;

void setup()  {
 Serial.begin(57600);
 myservoX.attach(pinServo_X);  
 myservoY.attach(pinServo_Y);  
 pinMode(ledPin, OUTPUT);
 if(DEBUG)  Serial.println("AndroZinZin V2.5");
}

void loop() {
  if(Serial.available())  {            // received from smartphone
   delay(5);
   cmd[0] =  Serial.read();  
//    if(DEBUG)  Serial.println(cmd[0]);   // ** DEBUG **
   if(cmd[0] == STX)  {  
     i=1;      
     while(Serial.available() && ((cmd[i]=Serial.read()) != ETX)) {
       if(i>5)  break;
//        if(DEBUG)    {Serial.print(i); Serial.print(": "); Serial.println(cmd[i]);}  // ** DEBUG **
       i++;
     }
   }
   if(i==2)    setLED(cmd[1]);
   if(i==3)    setPosition_Byte(cmd[1], cmd[2]);  
   if(i==5)    setPosition_Int(cmd[1]*128+cmd[2], cmd[3]*128+cmd[4]);  
 }
 delay(5);
}

void setLED(int LEDstatus)  {
 switch (LEDstatus) {
   case '1':
     Serial.println("Button_1: ON");
     // your code...      
     break;
   case '2':
     Serial.println("Button_1: OFF");
     // your code...      
     break;
   case '3':
     Serial.println("Button_2: ON");
     // your code...      
     break;
   case '4':
     Serial.println("Button_2: OFF");
     // your code...      
     break;
   case '5':
     Serial.println("Button_3: ON");
     // your code...      
     break;
   case '6':
     Serial.println("Button_3: OFF");
     // your code...      
     break;
   case '7':
     Serial.println("Button_4: ON");
     // your code...      
     break;
   case '8':
     Serial.println("Button_4: OFF");
     // your code...      
     break;
 }
}

void setPosition_Byte(byte posX, byte posY)    {    // Joystick BT commander V2.5
 posX = map(posX, 10, 110, 180, 0);
 posY = map(posY, 10, 110, 0, 180);
 posY+=ZERO_Y;
 posY = constrain(posY, MIN_Y, MAX_Y);
 if(DEBUG)  { Serial.print("(Byte) ");  Serial.print(posX);  Serial.print(", ");  Serial.println(posY); } // ** DEBUG **
 myservoX.write(posX);
 myservoY.write(posY);
}

void setPosition_Int(int posX, int posY)    {        // Joystick BT commander V3.0
 posX = map(posX, 10, 210, 180, 0);
 posY = map(posY, 10, 210, 0, 180);
 posY+=ZERO_Y;
 posY = constrain(posY, MIN_Y, MAX_Y);
 if(DEBUG)  { Serial.print("(Int) ");  Serial.print(posX);  Serial.print(", ");  Serial.println(posY); } // ** DEBUG **
 myservoX.write(posX);
 myservoY.write(posY);
}


Let me know the outcome in the Project main thread

Enjoy

kas

This is the revised sketch, compatible with Joystick Bluetooth Commander V3.X
(modified communication protocol)

Code: [Select]
// Andro_Pan&Tilt      V3.1
// Arduino demo sketch for Joystick BT commander V3.X
// Controls two servo motors

// V3.0: Android BT Commander V3.X compatible, no button data management
// V2.5 can receive both Byte & Integer data
// V2.0: removed SoftwareSerial

// Android BT Commander settings:
// Options/Options for advanced users/Data Range        >>>  -180 to +180
// Options/Options for advanced users/Refresh interval  >>>  25ms

//  Arduino pin #0 to TX BlueTooth module
// BT TX to be disconnected from D0 during sketch upload

#include <Servo.h>

boolean    DEBUG =         true;

#define    pinServo_X     9
#define    pinServo_Y     10
#define    STX            0x02
#define    ETX            0x03
#define    MIN_Y          45             // vertical move limitation
#define    MAX_Y          180
#define    ZERO_Y         60             // vertical offset

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                         // create servo object
Servo myservoY;

void setup()  {
 Serial.begin(57600);
 myservoX.attach(pinServo_X);  
 myservoY.attach(pinServo_Y);  
 if(DEBUG)  Serial.println("Stepper demo for Android BT Commander V3.X");
}

void loop() {
 if(Serial.available())  {                   // data received from smartphone
   delay(5);
   cmd[0] =  Serial.read();  
   if(cmd[0] == STX)  {  
     i=1;      
     while(Serial.available())  {
       cmd[i] = Serial.read();
       if(cmd[i] == ETX)  {
         if(i==2 && cmd[1]>48)                break;    // Button data
         if(i==5 && cmd[1]<3 && cmd[3]<3)     break;    // Joystick data
       }
       if(i>5)   break;
       i++;
     }
     if     (i==2)   Serial.println("Button data not implemented");             // 3 Bytes
     else if(i==5)   setServoPosition(cmd);                                     // 5 Bytes
     else            Serial.println("Communication error");
   }
 }
 delay(5);
}

void setServoPosition(byte data[5])    {
 int joyX = (data[1]<<7) + data[2];
 int joyY = (data[3]<<7) + data[4];
 joyX = joyX - 200;                         // Offset to avoid
 joyY = joyY - 200;                         // transmitting negative numbers
 
 joyX = map(joyX, -180, 180, 180, 0);      // (-180/+180 JBC range)
 joyY = map(joyY, -180, 180, 0, 180);

 joyY+=ZERO_Y;
 joyY = constrain(joyY, MIN_Y, MAX_Y);
 myservoX.write(joyX);
 myservoY.write(joyY);
 if(DEBUG)  {Serial.print(joyX); Serial.print(", "); Serial.println(joyY);}
}


Please post technical questions in the main thread

kas

#7
Jul 08, 2014, 07:29 am Last Edit: Jul 08, 2014, 07:49 am by kas Reason: 1
Code has been updated to be compatible with Joystick BT Commander V5.x



More info here and here


caymanguy

if i add ur software to my robot it will be nice

https://www.youtube.com/watch?v=uAcljpmfuh0

kas

#9
Jul 09, 2014, 03:58 pm Last Edit: Jul 09, 2014, 05:54 pm by kas Reason: 1
Quote
if i add ur software to my robot it will be nice
https://www.youtube.com/watch?v=uAcljpmfuh0


Hi caymanguy,
Nice bot ,  thanks for sharing  :)

I also use this App for controlling my own balancing robot, (now with MPU-6050 gyro/acc combo)


You may see the Bluetooth card, vertically plugged on the breadboard



kas


Go Up