Go Down

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

kas

Hi Tom

Quote
I have BT turned on, but I have not yet paired it to a device. 
Does that make a difference?

No, you should access option screens w/o pairing

Quote
I've downloaded version 5 to my Samsung tablet 4. 
I cannot find a way to get to a settings screen.

Are you talking about this one ??

Let me know

twm47099

Thanks for the quick response.

The tablet I have is the 8-inch version:
http://www.amazon.com/Samsung-Galaxy-Tab-8-Inch-White/dp/B00JKCH4V2/ref=sr_1_1?s=electronics&ie=UTF8&qid=1406474905&sr=1-1&keywords=Samsung+Galaxy+Tab+4+%288-Inch%2C+White%29

I can't find any active areas on the screen except for the joystick and 6 buttons.  There is also the pulldown notifications panel that is used to turn on the different table functions (wifi, location, bluetooh, etc).

Thanks
Tom

kas

#287
Jul 27, 2014, 06:59 pm Last Edit: Jul 28, 2014, 08:20 am by kas Reason: 1
Samsung has finally killed the dedicated menu button, replacing it with a task-switching key  :smiley-eek-blue:

Try pressing and holding this left button for a few seconds
Should bring the Option menu

Let me know if it works  ;)

twm47099

Thanks that worked.  Where did you find that?

Tom

kas

Quote
Thanks that worked

Glad to help

Quote
Where did you find that?

I used a new service called "Search Engine"   ;)  ;)  ;)
Try it:
https://www.google.com/search?hl=en&as_q=%22menu+button%22+%22tab+4%22+samsung&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=&gws_rd=ssl#as_qdr=all&hl=en&lr&q=%22menu+button%22+%22galaxy+tab+4%22+youtube

Can you connect now to your Arduino ??




twm47099

Duh!! Usually google is my friend, but sometimes I don't know what to ask.

I'm using a Propeller MCU.  I have C and Forth programs I wrote (using yours as a basis) for the previous protocol.  I've got to make a few changes for the new protocol. 

Thanks again,
Tom

kas

Quote
I'm using a Propeller MCU.  I have C and Forth programs I wrote (using yours as a basis) for the previous protocol.  I've got to make a few changes for the new protocol. 


Tom,

I started learning MCU's using Basic Stamps, I would really appreciate to have AndroTest V2.0 demo sketch
ported to the Propeller environment and offered to the Parallax Community.

Keep us aware of your progress, be sure you will get full support for this task   :) :) :)


kas

#292
Aug 01, 2014, 05:44 pm Last Edit: Aug 01, 2014, 05:53 pm by kas Reason: 1
Joystick Bluetooth Commander Version 5.2  has just been published on Google Play


Change log
new features:
- Manual return to center Button is displayed when "Auto return to center" is unchecked (thanks Artouste)
- "automatically flip if device turned upside down" is now an option, to maintain compatibility with
    early Android versions  (thanks joepro)
- Additional on screen Option button for new devices w/o dedicated Menu button (thanks twm47099)

Fixes:
- Fixed possible racing conditions at App start up (flickering buttons)
- Various minor improvements

 Demo sketch:   AndroTest V2.0   (communication protocol unchanged)    see reply #256



 Total RC Commander (with live video display) is also available.    Demo

Please contact me via PM

Enjoy  ;)




twm47099


Quote
I'm using a Propeller MCU.  I have C and Forth programs I wrote (using yours as a basis) for the previous protocol.  I've got to make a few changes for the new protocol. 


Tom,

I started learning MCU's using Basic Stamps, I would really appreciate to have AndroTest V2.0 demo sketch
ported to the Propeller environment and offered to the Parallax Community.

Keep us aware of your progress, be sure you will get full support for this task   :) :) :)




I've written a C program to use BT Commander with the Parallax Propeller ActivityBot.  So far I have the sections that (1) use a separate core to read the bluetooth data, translate the data to x & y (or button value) and transfer the results to the main core that continuously loops through the drive commands, (2) take the Joystick position and send drive commands to the bot, and (3) read the buttons -- I only have 2 buttons programmed so far, E-stop and Quit, but I intend to use the buttons to turn on an ultrasonic range finder and the Pixy color tracker.  I still have not gotten my head around the method for building the data frame for sending data to the android.  I want to use that to send range data from the UT range finder, but I'm trying to work out how I want to change numbers to ascii for the data frame.  Your sketch is a help, but the library functions are different so I try to port the concepts rather than the code.

Two questions -- 1. Does the data sent have to include values for all data fields?  Or can some be left out?
      2.  When the button status is sent to the android device, is it echoed back to the bot?

The code listing is at post 7 in the following thread:
http://forums.parallax.com/showthread.php/154687-EZ-Bluetooth-in-***C***-and-a-nice-App

Tom


kas

#294
Aug 02, 2014, 11:48 am Last Edit: Aug 02, 2014, 03:46 pm by kas Reason: 1
My suggestion:  Keep . It . Simple   ;)

Start with a program that parses data received from Android and just does that
It's final mission is to display (X,Y) joystick position and report button pushes
For data feedback to Android, just aknowledge button status on datafields phone screen.
You will find it much more confortable not to care about robot, motors and sensors at this development stage

Your PC screen should look pretty much like that:



In a second step, you may add debug facilities to your program
You will then chase communication errors and possibly adjust timing and code to reduce them
- Joystick errors
- Buttons errors
- data frame errors
- total data frames received


One Joystick (trapped) error out of 17530 received frames, not bad with Bluetooth

This is my Print debug function that reports possible errors:
Code: [Select]
void printDebug(int nByte)  {
static int buttonErr=0, joyErr=0, frameErr=0;
static long frames=0;

 frames++;
 if(nByte==2)     {                                                                // button data   < STX X ETX >
   if(cmd[1]>64 && cmd[1]<77 && cmd[2]==ETX)  {
     Serial.print("buttonStatus: "); Serial.print(buttonStatus);
     Serial.print("  bin: ");        Serial.println(getButtonStatusString());    
     Serial.print("Button: ");
   }  else { buttonErr++;   Serial.print("** Button error **: "); }
 }

 else if(nByte==7)  {                                                             // Joystick data   < STX  XXX YYY ETX >
   boolean dataOK = cmd[1]>48 && cmd[1]<52 && cmd[2]>47 && cmd[2]<58 && cmd[3]>47 && cmd[3]<58
                 && cmd[4]>48 && cmd[4]<52 && cmd[5]>47 && cmd[5]<58 && cmd[6]>47 && cmd[6]<58
                 && cmd[7]==ETX;
   if(dataOK)           Serial.print("Joystick: ");                              // digits within range
   else                { joyErr++;   Serial.print("** Joystick error **: ");  }
 }

 else         { frameErr++; Serial.print("** data frame error **: "); }          // wrong Byte number
 
 Serial.print("< ");                                                             // print incoming Bytes
 for(int j =0; j<nByte+1; j++)   { Serial.print(cmd[j]); Serial.print(" "); }
 Serial.print(">  ");  

 Serial.print(buttonErr); Serial.print("-");                                     // print errors status
 Serial.print(joyErr);    Serial.print("-");  
 Serial.print(frameErr);  Serial.print("-");
 Serial.println(frames);
}



Finally, adapt a copy of your program to drive the ActivityBot



Quote
Two questions --
1. Does the data sent have to include values for all data fields?  Or can some be left out?

No, just send the delimiters:
- Standard frame:
Code: [Select]
< STX   Buttons state   0X01   DataField#1   0x04   DataField#2   0x05   DataField#3   ETX >  - DataField#2 and #3 omited:
Code: [Select]
< STX   Buttons state   0X01  DataField#1  0x04   0x05  ETX >  


Quote
2.  When the button status is sent to the android device, is it echoed back to the bot?

It was the case in V4, now fixed in V5
MCU feedback did generate a "onCheckedChanged" Android event that trigged a new button data frame to MCU
In some situation, data could flow back and forth and gererate buttons flickering
Now button info sent from Android to MCU is echoed back (Buttons state) by MCU to Android, that's it

Good luck   ;)




twm47099

Thank s for the info.  I actually did use the approach you described.  First I just read the buttons & printed the value to make sure that the android would communicate.  Next I added code to differentiate joystick from button data.  Then I moved the reading of the data from andriod to a different core and printed the results from the main core.

That was where I found a problem.  When transferring data between cores the Propeller automatically syncs the transfer for 1 variable.  For transferring groups of related data (x & y from the same time) the programmer has to handle it.  When the program printed x & y it was taking x & y from separate sequential data sets.  So I added a couple of global variables 'okwrite' and 'okread' to keep things sync'd.

Once I did that, I added code to calculate the scaled motor wheel speeds and the method for adding the turn values, with a printout of x, y, base speed, turn values, and modified speed.  Once I got reasonable values, I added the actual drive commands, the E-stop command (I had included the quit code in the first button reading step.)

My next steps are tuning the drive speeds and x y to speed scaling, sending data to the android (which I'll do in one of the earlier / simpler code versions), and then running things like pixy and ping.

I am glad that you deleted the android echoing of the button status since it complicated the code.

Tom


twm47099

One other thing, I haven't seen any button or joystick errors yet, but for a roaming robot they may start as distances increase.   So I will port your error checking code. 

Thanks for the example.
Tom

kas

#297
Aug 04, 2014, 07:34 am Last Edit: Aug 04, 2014, 07:41 am by kas Reason: 1
Quote
That was where I found a problem.  When transferring data between cores the Propeller automatically syncs the transfer for 1 variable.  For transferring groups of related data (x & y from the same time) the programmer has to handle it.  When the program printed x & y it was taking x & y from separate sequential data sets.  So I added a couple of global variables 'okwrite' and 'okread' to keep things sync'd.


I have no experience with multicore MCU's, so I may be wrong  :smiley-roll-blue:
What about combining  X & Y data into a single integer variable before transferring to the main core:
Code: [Select]
int joyData = joyX << 8  +  joyY
then parse back this value ??


Quote
One other thing, I haven't seen any button or joystick errors yet,

You may experience transmission errors when you start sending back data to the Android device

twm47099


Quote
That was where I found a problem.  When transferring data between cores the Propeller automatically syncs the transfer for 1 variable.  For transferring groups of related data (x & y from the same time) the programmer has to handle it.  When the program printed x & y it was taking x & y from separate sequential data sets.  So I added a couple of global variables 'okwrite' and 'okread' to keep things sync'd.


I have no experience with multicore MCU's, so I may be wrong  :smiley-roll-blue:
What about combining  X & Y data into a single integer variable before transferring to the main core:
Code: [Select]
int joyData = joyX << 8  +  joyY
then parse back this value ??


I originally tried something like that, but it didn't work -- possibly because it was 3AM when I tried it.  I did that with the Forth code I wrote for your earlier versions of the app.  Although the flags method is easy and it works, I'd rather do it in one transfer rather than 2, so I'm going to try again.

Tom

twm47099

I revised the code that transfers the x & y data between cores (and it works).

The core that receives the BT data does the following:

Code: [Select]
joydata = (x<<10) | y;   //  x & y range from 100 to 300,  joydata is a global integer

The core that uses the data parses joydata:

Code: [Select]
yval = (joydata & 511) - 200;      //   yval ranges from -100 to +100
xval = (joydata >> 10) - 200;     //   xval ranges from -100 to +100

Go Up