Pages: [1]   Go Down
Author Topic: Bluetooth robotic dancer  (Read 5025 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This basic pan & tilt robot is controlled via an Android smartphone, using a virtual joystick



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  smiley-confuse

More info re Joystick Bluetooth Commander application here

Enjoy
« Last Edit: July 15, 2013, 03:27:31 pm by kas » Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

Nowhere. I am but a figure of your imagination.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the comments

The robot was quickly assembled using available parts, including an old parallax sonic sensor for the head smiley-wink
The all project is just a proof of concept for the Joystick Bluetooth Commander application
« Last Edit: July 22, 2013, 11:58:46 pm by kas » Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



Joystick Bluetooth Commander Version 2.5 here
« Last Edit: August 03, 2013, 01:04:13 am by kas » Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Rosamunda

Here is the Arduino side code:
Code:
// 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
« Last Edit: August 21, 2013, 11:43:14 am by kas » Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
// 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
Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code has been updated to be compatible with Joystick BT Commander V5.x



More info here and here

« Last Edit: July 08, 2014, 12:49:36 am by kas » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

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


« Last Edit: July 09, 2014, 10:54:20 am by kas » Logged

0
Offline Offline
Sr. Member
****
Karma: 18
Posts: 401
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

     Joystick BT Commander V5.2   now available

More info here
Logged

Pages: [1]   Go Up
Jump to: