Android Bluetooth joystick

I had just been thinking it would be great if there were a few more buttons, and a way to send more data info.
Do you know if this version would work with my galaxy s3 and if so, is it also available on the google store?

hi Billcat
Check your mail
Six buttons + 4 data bytes :wink:

This is how it looks on my Sony Xperia Mini (3" 320X480)

Please let me have a screen shot from your Samsung galaxy S3 (4.8" 1280X720)

kas:
Please let me have a screen shot from your Samsung galaxy S3 (4.8" 1280X720)

Hello kas,

sorry for the delay....,

here is the screenshot from Samsung Galaxy S3. It looks great! But I have not had a chance to test it with/or the Arduino sketch, hopefully soon and I can let you know the outcome :smiley:

thanks again!

@Billcat,
Based on your feedback, I will slightly move the joystick on the right, for the next release
I will appreciate you test the app when you have time (no rush ;))

@nemesis159
I will answer you questions later today

hi, bro estoy tratando de usar tu app de android, es la mejor que e visto, con la parte de los botones no tengo problemas pero no entiendo como usar la el joystick para controlar motores dc con un puente H, si me pudieras dar una orientacion seria exelente, es lo que me falta para terminar el proyecto, te dejo el link del puente h que yo uso.
Pololu - TB6612FNG Dual Motor Driver Carrier

Hi nemesis159

For general matters such as DC motor control, Google is your best friend :wink:
This is a quick basic example for one motor, using joyY (joystick vertical moves)
Pin configuration is based on 328P chip

 *** AndroLED V10.3 modification: ***

/* add this code in the define section */
#define AIN1  4   // connect AIN1 to Arduino pin 4 ...
#define AIN2  5
#define PWMA  6
#define STBY  7
 

/* add this code in the setup function */
pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWMA,OUTPUT);
pinMode(STBY,OUTPUT);
digitalWrite(STBY, HIGH);


/* replace getJoystickState() with this one */
void getJoystickState(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
  
  joyY = map(joyY, -100, +100, -255, 255);
  joyX = map(joyX, -100, +100, -255, 255);
 
  if(!DEBUG)  {
    Serial.print("Joystick data:  ");
    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  {
    digitalWrite (AIN1,LOW);
    digitalWrite (AIN2,LOW);

  analogWrite(PWMA,joyY);
}

Option/Data Range should be set to -100 +100

Please note that DC motors do not work well with low PWM values
Should you have motors with built in rotary encoders, consider adding PID control
Full discussion here

Let us know how it works (can't test it now)

Hi!

Just (re-)discovered your software and this thread. Is there a possibility for a second joystick?

Michael

I am finalising the video embeded application

and need another beta tester with a different IP camera brand (Foscam or others), not Wanscam
Please contact me via PM

kas:
@Billcat,
Based on your feedback, I will slightly move the joystick on the right, for the next release
I will appreciate you test the app when you have time (no rush ;))

Hello Kas,

I have made a little time to play.... using Samsung Galaxy S3,
I have partially tested Joy BT Plus with AndroLedVidV11. Only the buttons, to control some leds. For the most, all seems to be working well :smiley:

I think the joystick may still be moved slightly more to the right yet....no complaints here :blush:....but since you mentioned it already.

But I remain very confused by how most of the sketch works, so I simply made all 'case' statements similar, and commenting out what I think does the momentary and debug parts here. At the same time, changing the main debug to true, all joystick motions and button pushes reveal some change in information displayed in serial monitor.

I also think there may be a slight problem when choosing to view the data as bytes sent....see screenshot. Seems to be missing the closing ")" and possibly some data. Perhaps I am mistaken, I still remain very unclear on how 1's and 0's are sent and received!
All of the menus display well with proper grammar, far as I can tell. Another thing, I cannot seem to get anything out of the haptic feedback options, but it may be some other setting on the phone. But, I am able to get the phone to vibrate on ring, if that means anything.

Also, I do have some interest regarding the Beta testing for video. I do not own an IP camera, but that is a simple fix $) . Seems a bit out of my league yet, but would be a challenge that should help increase my knowledge base. Feel free to contact me via PM/email.

Cheers,
Bill

@Bill
thanks for the feedback

I think the joystick may still be moved slightly more to the right yet.

The version I sent you yesterday should take care of that

I also think there may be a slight problem when choosing to view the data as bytes sent....see screenshot. Seems to be missing the closing ")" and possibly some data

Can see that, to be fixed in next revision

Perhaps I am mistaken, I still remain very unclear on how 1's and 0's are sent and received!

Welcome is the communication protocols Univers ]:smiley: ]:smiley: ]:smiley:

I cannot seem to get anything out of the haptic feedback options,

This option brings a vibrating feedback when moving the joystick
It is device dependant (works on my Motorola G, doesn't work on my Galaxy Tab3)
This feature is useless, to be removed in next build

Also, I do have some interest regarding the Beta testing for video. I do not own an IP camera, but that is a simple fix $)

Let me know when you are ready

@powermik

Just (re-)discovered your software and this thread. Is there a possibility for a second joystick?

Sorry no plan for a second joystick
As most of us, my limiting factor is time :expressionless:
I am currently building a R/C tank with built in IP camera; my focus is embeding the video stream in the App

Nice to hear that you are working at a robot equipped with an IP Camera. I have a similar project, with the difference that my control software is a C# application, so the contorlling machine is a computer not a phone. It may be off/topic but I hope you don't mind if I put a link to my robot here: Arduino Bluetooth camera robot control with C# application - YouTube

It may be off/topic but I hope you don't mind if I put a link to my robot here: Arduino Bluetooth camera robot control with C# application - YouTube

You are very welcome :slight_smile:

This his my own work in progress:

The bot is based on a Rover 5 frame
PID motor control yet to be finalised

kas:
@Bill
thanks for the feedback

you're welcome!

kas:
The version I sent you yesterday should take care of that

great!

kas:
Welcome is the communication protocols Univers ]:smiley: ]:smiley: ]:smiley:

:grin:

kas:
This feature is useless, to be removed in next build

got it...

kas:
Let me know when you are ready

Sure, thanks!

@wildatheart
also for billcat and others :wink:

Hello Kas.

Thank you for sharing your joystick app. I am reading 6 bytes (decimal) 2, 1, 72, 1, 72, 3. I understand the 2 & 3 are framing bytes. And I also understand that 1 is the MSB and 72 is the LSB, and I believe you subtract 200 (decimal) to eliminate negative values. But I do not understand the relationship between 173 and 0 being at the center. Would you please tell me how these values relate to 0,0 with stick in center position.

Thank you

Joystick data is transmitted as an integer = 2 Bytes (Most Significant Byte + Less Significant Byte)
according to this data frame:

This is the relevant Android (Java) code snippet from Joystick Bluetooth Commander:

    	final int XvalB = Xval + 200;
    	final int YvalB = Yval + 200;
    	if((((Xant!=Xval) || (Yant!=Yval)) || (mTimeoutCounter>=mMaxTimeoutCount && mMaxTimeoutCount>-1)))	   // joystick position changed, or timeout occurred
    		sendMessage( new String(new byte[] {STX, (byte) (XvalB / 128), (byte)(XvalB % 128), (byte)(YvalB / 128), (byte)(YvalB % 128), ETX } ));

So, for Xval=0 Yval=0:
XvalB = YvalB = 200
XvalB / 128 = YvalB / 128 = 1
XvalB % 128 = XvalB % 128 = 72
Data frame: <2 1 72 1 72 3>

for Xval=100 Yval=100:
XvalB = YvalB = 300
XvalB / 128 = YvalB / 128 = 2
XvalB % 128 = XvalB % 128 = 44
Data frame: <2 2 44 2 44 3>

The data frame is send via BlueTooth to the arduino board and decoded.
This is the Arduino code snippet from Joystick Bluetooth Commander:

  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

Voilà :slight_smile:
Should you have additional questions, let me know

EDIT:
The 6 button, 4 data field App and the video App both have a slightly different protocol
(STX & ETX values are different)

Thx for the explanation. Got it.

Joystick BT Commander is working perfectly with the LG G2 phone, the Adafruit EZ-link 315a bluetooth, and the Parallax Quickstart demo board.

Not sure what "Data XXX" is used for. Is there any chance the MCU can send and display a serial message in your APP? The joystick image is displayed a little above center but that's okay - it leaves room below (in line with the displayed x,y position) for a possible sent message.

Joystick BT Commander is working perfectly with the LG G2 phone, the Adafruit EZ-link 315a bluetooth, and the Parallax Quickstart demo board.

Nice to hear, I started learning microcontrollers with Basic Stamps :slight_smile:
http://forums.parallax.com/showthread.php/103850-Yet-another-balancing-robot?daysprune=-1

Not sure what "Data XXX" is used for. Is there any chance the MCU can send and display a serial message in your APP?

YES !!! see reply #74
Joystick BT Commander listens to the MCU and expect a 4 Byte data frame
<STX button status Byte data Byte (your choice) ETX>

This is the relevant code snippet in the Arduino demo sketch (V10.3):

  mySerial.write(STX); mySerial.write((button<<2)+4); mySerial.write(data+4); mySerial.write(ETX); // +4: avoid 0x2 & 0x3

There is another version with 4 data bytes and 6 buttons


For those interested, contact me via PM

The joystick image is displayed a little above center but that's okay

I need that type of feedback, please let me have a screen shot of the App on your LG G2 phone

Kas, this is a screenshot of the LG G2. The vertical location of the joystick is not a problem but it is a bit above center.

If I could submit a longer text string to the App in the "data" area the current location of the stick would be okay. But my current problem is... I cannot successfully send serial data from my Quickstart to Joystick. I guessing the problem is because the Quickstart seems only accept correct data with rx set at 9600, so I can only tx at 9600 too. Any chance the baud rate can be selectable or otherwise changed in the App?

(Your) Nice write-up and interesting project in the Parallax forums. I intend to submit your App (with due credit) along with my work to the forums in the near future.

If I could submit a longer text string to the App in the "data" area the current location of the stick would be okay

The data field can display a positive signed Byte (0 to 127), not a text string

I guessing the problem is because the Quickstart seems only accept correct data with rx set at 9600, so I can only tx at 9600 too. Any chance the baud rate can be selectable or otherwise changed in the App?

There isn't any Baud rate value within Joystick BT Commander code
The Baud rate setting is only for communication between BT card and microcontroller, NOT between Android device and BT card
Try sending 2 4 14 3
the Data field should display 14-4=10, while keeping all buttons to the OFF position

I intend to submit your App (with due credit) along with my work to the forums in the near future.

What is your current project ??
Please give my regards to my friends from the Alternate Univers (Parallax) :wink:
and post a link here when done

Great job KAS , i test again and you was right,your app works great with Android 2.3.5,and the HC-06 also compatible (bad thing is i don't recive any data,i can only send) :D:D so...
Based on your replay at post #146 i am trying to modify the arduino code with your permision,so that on vertical move a DC Motor, and the orizontal a Servo (for steering)...
the joyY control Vertical joystick movement ,and "joyX" the horizontal right ?
I will post the code as soon i will get it work ... Thank you ,Congratulations again for the app,Karma up :wink:

Along with all others, again.. GREAT APP! Nice layout. Easy to use. And all functions work as designed. Can even send data now.

I don't expect you to modify anything, but just a couple of observations...

  1. The condition is rare and does not seem to correlate with any certain circumstance, but it has happened that the yellow stick will lock itself in a position other than "center", usually about the 10 o'clock or the 5 o'clock location. It seems to lock position at about 1/3 the distance from center to the outer ring. I've seen it happen 3 or 4 times in testing.

  2. It would be nice if your APP could receive and display a text message. ie "X axis is clear", "Pump 3 flow rate set to 40%", "Press B1 to launch" etc.

  3. I am experimenting with a continuous rotation servo. I may be able to correct this in my own software but as it is - when the stick is released 3 or 4 readings are sent before the stick settles into the center position. The affect of this is the lack of ability to stop the servo rotation at a precise point. I've tried several different refresh interval and timeout count settings but it does not seem to help. You'd know best, but perhaps the remedy lies in my own Propeller code. The other option would be - upon stick release --> automatic center (100,100) without the intermediate readings.

The above are just observations - no big deal. Joystick is a GREAT educational opportunity to learn about Bluetooth control and most will find a way to incorporate it in their projects as is. Thanks for sharing your work.

@juycce

Great job KAS , i test again and you was right,your app works great with Android 2.3.5,and the HC-06 also compatible (bad thing is i don't receive any data,i can only send) smiley-grin:D so...

You mean data from Arduino to Smartphone ??
Provided the connection is established, it should work :roll_eyes:
You may have to drop SoftSerial communication if you still use it
Please post your current Arduino sketch

Based on your replay at post #146 i am trying to modify the arduino code with your permision, so that on vertical move a DC Motor, and the orizontal a Servo (for steering)...
the joyY control Vertical joystick movement, and "joyX" the horizontal right ?

Right

@wildatheart

Along with all others, again.. GREAT APP! Nice layout. Easy to use. And all functions work as designed. Can even send data now.

Glad it works, thanks for the comments :slight_smile:

it has happened that the yellow stick will lock itself in a position other than "center", usually about the 10 o'clock or the 5 o'clock location. It seems to lock position at about 1/3 the distance from center to the outer ring. I've seen it happen 3 or 4 times in testing.

I tried and couldn't reproduce this "feature"
What is your App version ?? (Option > About...)
When the freezing occurs,

  • is the BT connection established
  • what is the displayed joystick position

It would be nice if your APP could receive and display a text message. ie "X axis is clear", "Pump 3 flow rate set to 40%", "Press B1 to launch" etc.

I will think about it :wink:

I am experimenting with a continuous rotation servo. I may be able to correct this in my own software but as it is - when the stick is released 3 or 4 readings are sent before the stick settles into the center position. The affect of this is the lack of ability to stop the servo rotation at a precise point.

I understand the point
I may be wrong, but a joystick is not supposed to work that way
For my pan/tilt servo device, I just uncheck Auto return to center (Option > Joystick behavior)
I get a precise positioning, no need to return to center
Am I missing something ??

Joystick is a GREAT educational opportunity to learn about Bluetooth control and most will find a way to incorporate it in their projects as is. Thanks for sharing your work

Thanks, comments appreciated :slight_smile:

Still working on my new toy (see reply #152)
For the moment, I am busy tuning my PID motors (more info), while monitoring battery level (8.2V)
I just toggle buttons Up or Down; the actual values are displayed in the data fields.

Kas, thanks for giving thought to the possibility of 'text'.

Started a thread in the Parallax forum using your App and the Propeller Quickstart board as a quick and dirty demo. We've been doing a lot with C over there and the timing of this is just right to generate added interest. Feel free to join us.[/ I think there'd be great interest in a brief tutorial on writing Android Apps too.

http://forums.parallax.com/showthread.php/154687-EZ-Bluetooth-in-***C***-and-a-nice-App

If the asterisks mess with the link, copy and paste the entire line. I think its okay if you just click it.