Android Bluetooth joystick

I can’t really get onto google play and download the app from China
can anybody send me the app to my email
or send me another link to download
thankyou very much!

I can't really get onto google play and download the app from China can anybody send me the app to my email (xxx-xxx@qq.com) or send me another link to download thank you very much!

Hi magicjackho, welcome to the Forum Check your mail ;)

I sent you V5.2 to be published on Google Play within a few weeks Should you need support, this is the place

Let me have a screenshot of the Application

@All ** I NEED screenshots ** this my only way to optimize display layout for your specific device :)

Personal advice: To avoid spamming, I suggest you edit your message and remove your email info ]:)

I've downloaded version 5 to my Samsung tablet 4. I cannot find a way to get to a settings screen. I have BT turned on, but I have not yet paired it to a device. Does that make a difference? How do I find a settings screen.

Thanks Tom

Hi Tom

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

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

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

Samsung has finally killed the dedicated menu button, replacing it with a task-switching key :fearful:

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

Let me know if it works ;)

Thanks that worked. Where did you find that?

Tom

Thanks that worked

Glad to help

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 ??

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

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 :slight_smile: :slight_smile: :slight_smile:

Joystick Bluetooth Commander Version 5.2 has just been published on Google Play

[u]Change log[/u] 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

[u]Demo sketch:[/u] 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 ;)

kas:

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

My suggestion: Keep . It . Simple :wink:

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:

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

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:
    < STX Buttons state 0X01 DataField#1 0x04 DataField#2 0x05 DataField#3 ETX > - DataField#2 and #3 omited:
    < STX Buttons state 0X01 DataField#1 0x04 0x05 ETX >
  1. 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 :wink:

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

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

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 :roll_eyes:
What about combining X & Y data into a single integer variable before transferring to the main core:

int joyData = joyX << 8  +  joyY

then parse back this value ??

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

kas:

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 :roll_eyes:
What about combining X & Y data into a single integer variable before transferring to the main core:

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

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:

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

The core that uses the data parses joydata:

yval = (joydata & 511) - 200;      //   yval ranges from -100 to +100
xval = (joydata >> 10) - 200;     //   xval ranges from -100 to +100

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

I tried your code and got wrong results

unsigned int joyData;
int joyX, joyY;

void setup()  {
  Serial.begin(57600);
  
  // twm47099 code
  joyX = 280;    // 280-200 = 80
  joyY = 260;    // 260-200 = 60
  
  joyData = (joyX<<10) | joyY;                    // encoding
  // --------------------------------
  joyY = (joyData & 511) - 200;                   // decoding
  joyX = (joyData >> 10) - 200;
  Serial.print(joyX);  Serial.print("\t");  Serial.println(joyY);  Serial.println();
  // >> printed result:   -176	60  (not OK) <<


  
  // kas code
  joyX = 280;    // 280-200 = 80
  joyY = 260;    // 260-200 = 60

  joyData = (joyX-100 <<8) | joyY-100;              // encoding
  // --------------------------------
  joyX = (joyData >>8) -100;                        // decoding
  joyY = (joyData & 0xFF) -100;
  Serial.print(joyX);  Serial.print("\t");  Serial.print(joyY);
  // >> printed result:   80	60  (OK) <<
}

void loop()  {}

Probably due to data type implementation difference in Arduino and Propeller :roll_eyes: :roll_eyes:

Kas,
Interesting results. It must be due to different number formats, or maybe the declaration of an unsigned integer?

Propeller C uses 32 bit integers. I chose not to subtract 100, just to save a step.

Here’s the code I ran on the Prop using both your and my methods. I did declare joydata as an integer.

#include "simpletools.h"                      // Include simple tools
int joydata;
int joyY;
int joyX;
int x;
int y;

int main()                                    // Main function
{
  joyX = 280;       // x = 280-200 = 80
  joyY = 260;       // y = 260 - 200 =60

  //  Tom's Method
  joydata = (joyX << 10) | joyY;
  printi ("joydata = %b    %d\n", joydata, joydata);
  y = (joydata & 511) -200;
  x = (joydata >> 10) -200;
printi ("x = %d     y = %d\n\n", x, y );
  // results copied below
  // joydata = 1000110000100000100    286980
 // x = 80     y = 60

  // Kas Method
  joydata = (joyX -100 << 8) | joyY - 100;
  printi ("joydata = %b    %d\n", joydata, joydata);
  y = (joydata & 0xFF) - 100;
  x = (joydata >> 8) - 100;
  printi ("x = %d     y = %d\n\n", x, y );
  // results copied below
  // joydata = 1011010010100000    46240
  // x = 80     y = 60
}