Go Down

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

_SBC_

#60
Jul 27, 2013, 01:59 am Last Edit: Jul 27, 2013, 02:06 am by _SBC_ Reason: 1
Nice application. Thanks!
I'd like to ask... if your application sends X=2, Y=3 (for example) will it be read as 'Button 2 is pressed' by Arduino?
I use a phone with display resolution is only 320x240. Joystich is not fully shown on display =/

kas

#61
Jul 27, 2013, 02:58 pm Last Edit: Jul 27, 2013, 03:02 pm by kas Reason: 1
Quote
if your application sends X=2, Y=3 (for example) will it be read as 'Button 2 is pressed' by Arduino?

No
Data in textbox is joystick data only (4 bytes)
Packet size is 3 bytes for button data : <STX  X  ETX>
and 4 Bytes for joystick data: <STX  X  Y  ETX>
Code: [Select]
    if(i==2)    setLED(cmd[1]);
   if(i==3)    setJoystick();  

According to packet length, joystick or buttons will be controlled


Quote
I use a phone with display resolution is only 320x240. Joystick is not fully shown on display =/

Let me have more info re your phone, with possibly a link to specs

_SBC_

Yes, sorry, checked it ))
About the phone - it is Samsung Galaxy Young.
Many thanks in advance!! ;)

kas

Quote
Yes, sorry, checked it ))
About the phone - it is Samsung Galaxy Young.
Many thanks in advance!! smiley-wink


Let me have your email in a private message

kas

Quote
Let me have your email in a private message

Check your mail  8)

I have no possibility to test screen layouts
Let me have feedback, possibly with a screenshot 

arRaindog

Thank you for the wonderful app.  I am using it to control my first scratch built rover robot.  I have been able to implement the X,Y joystick function to control the robot but when the joystick is held static the app stops sending data causing the robot to jerk to a stop. 

I am using a google Nexus 7 as my android platform.

I've searched through the options but don't see anything to keep the app transmitting while the joystick is held stationary.  Is this an artifact of my android platform, or is this a design element?

Again thank you for your hard work on this app.

kas

@_SBC_

Quote
Thank you veeeery much! )
Finally I can fully test my bot...

Many thanks again!!!


Glad to help  ;)
please let me have a screen photo

kas

#67
Jul 29, 2013, 07:52 am Last Edit: Jul 29, 2013, 07:54 am by kas Reason: 1
Quote
Thank you for the wonderful app.
...
Again thank you for your hard work on this app.

Thanks for the nice comment and welcome to the Forum  :)


Quote
I've searched through the options but don't see anything to keep the app transmitting while the joystick is held stationary.  Is this an artifact of my android platform, or is this a design element?

To save bandwidth, the application only send data if the joystick position is changed
This is by design
Pseudo code:
Code: [Select]
if data <> dataAnt
 sendData()
 dataAnt = data
endIf


See if you can modify your bot code,
it should not need a constant flow of data to work
Otherwise let me know, I will then create a new option

arRaindog

Thanks for the reply. I can modify my code if I choose to use this. As a fail safe I designed the code so the robot stops in the absence of a control signal. While the short range of Bluetooth reduces the chances of a runaway I can't catch before it breaks something I like the peace of mind. Thanks again.

kas

Quote
As a fail safe I designed the code so the robot stops in the absence of a control signal

Got the point, make sense  :smiley-roll-blue:
I will create the option this week


kas

#70
Jul 30, 2013, 01:43 pm Last Edit: Jul 30, 2013, 07:01 pm by kas Reason: 1
I just received a new Galaxy Tab3 8" tablet 8)

The application didn't run well on this specific machine :smiley-sad-blue:
- toggle buttons didn't show the green LEDs as per reply #47
- erratic joystick movements
- screen layout was far from optimal on large tablets

Version 2.5 change log:
 layout adapts to device screen size
 better looking buttons
 fixed joystick bug (for the Android nerds: "nested weight")
 removed "Data Format" option (useless)
 buttons/joystick data collision management



@arRaindog:
Go to Option/Advanced Option/Timeout count
set to "Continually", should now work as expected

@_SBC_:
the display on your Samsung galaxy Y should now be OK with this new version
please confirm

I will test the application and upload it here, within 24 hours
Get it directly from your device with Google Play

I definitely can't purchase every Android devices to check layout
Please let me have a feedback, possibly with screenshot

kas

#71
Aug 01, 2013, 11:07 am Last Edit: Aug 03, 2013, 07:15 am by kas Reason: 1
Done

@arRaindog:
Make sure to adjust timeout count to the lowest frequency compatible with your Dead Man strategy

arRaindog

Thank you KAS.  I really appreciated your response and modifying your app.  I did have to make some changes to my code to deal with unavailable bluetooth data but now it is working wonderfully.  This is an excellent app that works as designed, is well laid out, and has many options and customizations to make it easy to use.  I've configure button one to engage autonomous mode (just got the three sensor ultrasonic array debugged) and to change the motor PWM (speed) for carpet vs. tile.


Attached is a screen shot on my google nexus 7:

kas

#73
Aug 03, 2013, 06:19 pm Last Edit: Aug 03, 2013, 06:28 pm by kas Reason: 1
Quote
Thank you KAS.  I really appreciated your response and modifying your app.  I did have to make some changes to my code to deal with unavailable bluetooth data but now it is working wonderfully.  This is an excellent app that works as designed, is well laid out, and has many options and customizations to make it easy to use.
:smiley-red: :smiley-red: :smiley-red:


Quote
I've configure button one to engage autonomous mode (just got the three sensor ultrasonic array debugged) and to change the motor PWM (speed) for carpet vs. tile

Still a small glitch: the buttons state synchronization can be lost on communication problems or simple Arduino reset
To be a serious control application, Android BT Commander needs two way communication channel and get Arduino acknowledgments to buttons change requests (see Reply #36)
I am working on V3.0 ;)


Please post a photo/video of your new toy   :P


kas

#74
Aug 10, 2013, 09:21 pm Last Edit: Aug 31, 2013, 07:11 am by kas Reason: 1
** Major Upgrade **

Change Log
Full blown two way Bluetooth communication with the associated microcontroller
Arduino sends back a button status Byte and a user defined data Byte to be displayed
on the phone/tablet screen (Bot battery level is a nice candidate)
Device user defined Data textbox can be renamed and/or hidden if unused
Selectable -50/+50 or -100/+100 output range Option
** EDIT: added -180/+180 output range for servo motors **
Auto-connect at start up Option

Communication protocol
Android device data transmission
Joystick data is now transmitted as an integer = 2 Bytes (Most Significant Byte + Less Significant Byte)
<STX  MSB-X  LSB-X  MSB-Y  LSB-Y  ETX>

Code modification:
Code: [Select]
void loop() {
...
else if(i==5)    setJoystick_Int(cmd);  // 6 Bytes
...
}



Integer data is then assembled as follow:
Code: [Select]
void setJoystick_Int(byte data[5])    {
 // Demo
 int joyX = (data[1]<<7) + data[2];
 int joyY = (data[3]<<7) + data[4];
 joyX = joyX - 110;               // Transmission offset = 110   XXXXX
 joyY = joyY - 110;               // to avoid negative numbers   XXXXX
 
 Serial.print("Joystick data:  ");
 Serial.print(joyX);  
 Serial.print(", ");  
 Serial.println(joyY);

 // Your code here ...
}


** EDIT **     please see reply #84
 joyX = joyX - 200;               // Transmission offset = 200
 joyY = joyY - 200;               // to avoid negative numbers


Arduino data transmission:
Arduino sends back buttonStatus and dataByte
<STX  buttonStatus  dataByte  ETX>
(see  bitwise operators)

Code: [Select]

void setLED(int LEDstatus)  {
 switch (LEDstatus) {
   case '1':
     buttonStatus |= B0001;    // Button_1: ON
     Serial.println("Button_1: ON");
     // your code...      
     break;
   case '2':
     buttonStatus &= B1110;    // Button_1: OFF
     Serial.println("Button_1: OFF");
     // your code...      
     break;
   case '3':
     buttonStatus |= B0010;    // Button_2: ON
     Serial.println("Button_2: ON");
     // your code...      
     break;
   case '4':
     buttonStatus &= B1101;    // Button_2: OFF
     Serial.println("Button_2: OFF");
     // your code...      
     break;
   case '5':
     buttonStatus |= B0100;     // Button_3: ON
     Serial.println("Button_3: ON");
     // your code...      
     break;
   case '6':
     buttonStatus &= B1011;     // Button_3: OFF
     Serial.println("Button_3: OFF");
     // your code...      
     break;
   case '7':
     buttonStatus |= B1000;     // Button_4: ON
     Serial.println("Button_4: ON");
     // your code...      
     break;
   case '8':
     buttonStatus &= B0111;    // Button_4: OFF
     Serial.println("Button_4: OFF");
     // your code...      
     break;
 }
 sendData(buttonStatus, dataByte);
}


Advanced hint:
Button status can be monitored at a deeper level by directly manipulating and transmitting Arduino internal ports Byte (see Example Program)

Choose DataByte to taste:

Code: [Select]

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

 // Your code ...
}



Button status is feeded back by Arduino to the Android device
on a timed basis (every 'interval' milliseconds), and each time a button is pressed:
Code: [Select]

void loop() {
 if(mySerial.available())  {            // received from smartphone
   ...  
 }  else  {
   unsigned long currentMillis = millis();
   if(currentMillis - previousMillis > interval) {
     dataByte = GetdataByte();
     sendData(buttonStatus, dataByte);         // <<<<<
     previousMillis = currentMillis;  
   }
 }
 ...
}


Code: [Select]

void setLED(int LEDstatus)  {
 switch (LEDstatus) {
 ...
 }
 sendData(buttonStatus, dataByte);         // <<<<<
}


Code: [Select]

void sendData(byte button, byte data)    {
 mySerial.write(STX);
 mySerial.write((button<<2)+4);
 mySerial.write(data+4);           // +4: avoid 0x2 & 0x3
 mySerial.write(ETX);
}

button status Byte is left shifted to avoid transmitting 0x02 and 0x03 (STX, ETX) values


As already stated, make sure your BT communication is set to 57600 BPS


The full Arduino sketch will be available shortly for download at the bottom of this post

The  Joystick Bluetooth Commander Version 3.0 is ready and debugged, I will upload it at Google Play as soon as user tests
are finished


Quote
Quote
BTW, the Galaxy phone guy [non-techie] was totally amazed how

he could suddenly use his Android phone to control the world, ;-),

I had this very same feeling 8), this is the reason I decided to share


I believe I did my duty  ;)
According to Google Play, Joystick Bluetooth Commander is now in the 500/1000 downloads ball park  8)
I spent an interesting month  :smiley-roll-blue: :smiley-roll-blue: :smiley-roll-blue: developing the application, but it's now time to move to other projects.

Thanks again for your interest and suggestions  :)

Edit:
Arduino sketch attached

Edit2:
Updated demo Arduino sketch at reply #90

Go Up