Go Down

Topic: Android Bluetooth joystick (Read 334469 times) previous topic - next topic

kas

#165
Mar 17, 2014, 07:38 am Last Edit: May 09, 2014, 07:44 am by kas Reason: 1
Quote
hi kas, you could upload the apk with 6 buttons and 4 data   XD XD XD XD


Sorry nemesis159, I missed your recent PM  :smiley-red:

The 6 buttons, 4 data bytes App is now released as Joystick BT Plus
The actual number of buttons and data fields is adjustable within the Option menu
Fields and buttons labels are fully customizable



Road map:
Next revision will include an option to perform control using the android device built-in accelerometers
Control will be performed by tilting the smartphone/tablet  8)
Within this option, joystick will be "read only", reflecting the device inclination.

Please send me your email via PM

EDIT:  now renamed as Joystick bluetooth Commander V4.0, available for free on Google Play



nemesis159

Hi, i send you one MP, and thanks for sharing your excellent work  XD XD XD XD

nemesis159

Hi people, i need help  :smiley-roll-blue:, I'm trying to use this sketch to send rpm data from arduino to this application, but do not understand how data is sent  :smiley-roll-blue: :smiley-roll-blue:, if I could explain how it works this is the part would greatly appreciate (explanation to children xD)  XD XD XD XD XD XD

byte GetdataByte()  {             
  static byte i=0;
  i +=5;
  if(i >100)    i = 0;
  return i;

kas

Quote
I'm trying to use this sketch to send rpm data from arduino to this application, but do not understand how data is sent   :smiley-roll-blue: :smiley-roll-blue:


Will you use Joystick bluetooth Commander/4 button version, or Joystick BT Plus/6 button version ??
(different communication protocols)

How do you obtain RPM data ??  via encoder(s) ??
Did you allready build the code for RPM data aquisition ??

How is the new layout I sent you for Joystick BT Plus ?
Please post a screen shot

nemesis159

hi, i use basically this code for rpm http://playground.arduino.cc/Learning/Tachometer#.Uyr2Qfl5NAJ

my firs intent to send data is in 4 butons and 1 data, but now i trying in 6butons 4 data

kas

#170
Mar 21, 2014, 07:19 am Last Edit: Mar 21, 2014, 07:24 am by kas Reason: 1
Quote
I'm trying to use this sketch to send rpm data from arduino to this application, but do not understand how data is sent    :smiley-roll-blue: :smiley-roll-blue:


Data has to be sent as a positive Byte (0 to 127)
You need to scale RPM value in order to stay within this interval
If your RPM range is 0 to 12000:
Code: [Select]
byte GetdataByte()  {
 double data = rpm / 100;
 data = constain(data, 0, 127);            
 return byte(data);
}


To overcome this 127 steps limited resolution, I will switch from byte to integer in next Joystick BT Plus version

nemesis159

XD XD thanks, now i understand,  it was not as complicated as it seems, very grateful for the help

juycce

Can anyone give me a hand with some errors i have ...
I am trying to run the TB6612FNG on the vertical and a Servo on Horizontal ...so far the code only moves the motor only when you keep moving a little the joystick (i mean if u stay still with the finger on maximum speed i have no movement) :

Code: [Select]


#include <Servo.h>

boolean    DEBUG = true;

#define    pinServo_X     9
#define    PWM_Y          3
#define    STX            0x02
#define    ETX            0x03

#define    MAX_Y          255      // PWM limit
#define    ZERO_Y         0         
#define    MIN_Y          -255       

#define AIN1  4   
#define AIN2  5   // AIN1 and AIN2 as Direction pins
#define STBY  7   // StandBy

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                     
Servo myY;                 // ???? it is not a servo
byte buttonStatus = 0;             
byte dataByte = 0;                   
long previousMillis = 0;           
boolean setButtonFeedback = false;   
long interval = 1000;                 


void setup()  {
  Serial.begin(9600);
  myservoX.attach(pinServo_X); 
  myY.attach(PWM_Y);   

pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWM_Y,OUTPUT);
pinMode(STBY,OUTPUT);
 
}

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==5)   setServoPosition(cmd);                                     // 5 Bytes
      else            Serial.println("Communication error");
    }
  }  else  {
    long currentMillis = millis();
    if(setButtonFeedback == true)  {                      // allow momentary button visual effect (500 ms)
      previousMillis = currentMillis - interval*0.5;   
      setButtonFeedback = false;
    } 
  }
  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,  -100, +100, -255, 255);

  joyY+=ZERO_Y;
  joyY = constrain(joyY, MIN_Y, MAX_Y);
  myservoX.write(joyX);
  myY.write(joyY);
  digitalWrite(STBY, HIGH); //disable standby
  if(DEBUG)  {
  //Serial.print(joyX); Serial.print(", ");
  Serial.println(joyY);}


  if(joyY > 0) {
      digitalWrite (AIN1,HIGH);
      digitalWrite (AIN2,LOW);
  } else if(joyY < 0)  {
      digitalWrite (AIN1,LOW);
      digitalWrite (AIN2,HIGH);
  } else if(joyY = 0)  {
      digitalWrite(STBY, LOW); //enable standby

  analogWrite(PWM_Y,joyY);
}
}



I know that i shouldn't use servo library for the Vertical Axis (DC Motor) ....but i don't know how to do it ,i tried to change it with PWM but i got errors...also motor kepp making noise (without moving) when joystick is in the middle posicion
On Serial Monitor i get the right values  :  255 when joystick full up   ----  0 in the middle ---- and -255 when is down
I apreciate your help,thank you,i hope to get this work ;)

kas

Yes,  using servo library with DC Motor makes no sense :smiley-roll:

Standby is enabled and never driven high again
Code: [Select]
  } else if(joyY = 0)  {
      digitalWrite(STBY, LOW); //enable standby


Classical error  ;)
Code: [Select]
} else if(joyY = 0)  {        // assignment operator, always TRUE !! 
should really be
Code: [Select]
} else if(joyY == 0)  {         // comparison operator, the way to go

Sample code for DC motors here
Take the easy way, build separate codes for DC motor and servo, make sure they both work, and finally combine them

@nemesis159
How is the new layout I sent you for Joystick BT Plus ?
Please post a screen shot

juycce

You was right about this ...i just change it
Code: [Select]

} else if(joyY == 0)  {         // comparison operator, the way to go

...as for the Stanby  it   is  enabled again :
Code: [Select]

 myY.write(joyY);
 digitalWrite(STBY, HIGH); //disable standby   <----


Made some small modification and works (but not how it should) : it only have one speed fwd and backword (very very slow :((  ) in the middle get in Standby but it have no speed .On Serial monitor it goes from -255   0  255 ...and i test the motor and it works,
What am i doing rong? I just don't get it,I don't wanna give up this project...shoud i open a new topic and ask for some advice ?
Thank you KAS


kas

juycce,

There are other glitches in your code

Code: [Select]
joyX = map(joyX, -180, 180, 180, 0); 
joyY = map(joyY,  -100, +100, -255, 255);


Second and third parameters should match App Option > Adv properties > Data Range
and should be identical for both joyX and joyY

Did you test the code example at reply #146 ?

For additional help, the Motors Mechanics and Power section seems adequate

Keep us informed  :)

kas

#176
Mar 31, 2014, 07:47 am Last Edit: Apr 01, 2014, 07:41 am by kas Reason: 1
@tolisn63
Quote

I just tried out the new sketch. It is working great. All button now work as well as the data fields.
Also the camera has very little lag (<0.5sec) after  I switched it to a lower res. (320x240) which is absolutely usable.

Thanks for the good new  8) 8) 8)

Quote
1. Is it possible to change the orientation of the settings screen so it is the same as the main control screen ?
2.Also it would be nice if the data receiving fields could also accept incoming text.

Will look into that matter  ;)

Quote
one question, when the buttons are pressed and the color becomes green, does the tablet do that or is it feedback from the arduino ?

This is the real button position
- button first becomes green "locally" as an Android feature
- position is then sent to Arduino
- Arduino sends back the actual button position
See replies #36 and #73

A good example is toggle (momentary) buttons
Button is set green by Android and reset white by Arduino  after 250 milliseconds, to create a visual effect.

Quote
thanks for all your hard work.
Looking forward to trying your newest version.

:)

kas

#177
Apr 03, 2014, 06:22 pm Last Edit: May 10, 2014, 09:47 am by kas Reason: 1
Quote
@tolisn63

Quote
1. Is it possible to change the orientation of the settings screen so it is the same as the main control screen ?
2.Also it would be nice if the data receiving fields could also accept incoming text.

Will look into that matter  ;)


You got it ;) ;) ;)
check your mail

Total RC Commander V1.1A
- Data fields now accept integers, floats and text messages
- Improved video management
- adjustable Option screen orientation



Important:
To allow text messages, Arduino to Android communication protocol has been modified
Please use and adapt "AndroTest_PlusV12_string.ino" demo sketch

Let me have your feedback and a screenshot for your specific Android device

@all
Joystick BT Plus (6 buttons, 3 datafields)
and
Total RC Commander (video from IP camera)
will be available on Google Play within a month for a symbolic fee

In the meantime, please contact me via PM

Next version: remote control using built-in accelerometers (see reply #165)  :P

Enjoy


EDIT:  Joystick BT Plus is now Joystick bluetooth Commander V4.0
available on Google Play as a free upgrade
See reply #181


kas

#178
Apr 30, 2014, 03:19 pm Last Edit: Aug 31, 2014, 08:09 am by kas Reason: 1
I just posted a video showing tank control using Total RC Commander.



See it in action in the Exhibition Section

To obtain the App, please contact me via PM


kas

#179
May 06, 2014, 08:56 pm Last Edit: May 09, 2014, 07:46 am by kas Reason: 1
Quote
Hi Kas
Thanks for the reply
Can I use hardware serial with this on my mega2560 (it has 4 hardware serial ports) and how ?


Hi tolisn63
Not too familiar with the Mega  :|

- remove   #include "SoftwareSerial.h"
- remove   SoftwareSerial mySerial(2,3);
- search/replace  mySerial  >> Serial1

pin#19  to TX bluetooth module
pin#18  to RX bluetooth module

You should be all set  ;)
Let me know the outcome

Go Up