Android Bluetooth joystick

Ok I will test it soon as possible.

Many thanks for quick replies :wink:

I just tried running two servo's using SoftwareSerial on pins #2 & #3, and also got the "Tick-Tick syndrom"
SoftwareSerial disables interrupts while sending a byte.
This interferes with the Servo library, which relies on timer interrupts
The hardware Serial port should always be used, if possible, before considering SoftwareSerial.
Additional readings

Possible options

  • drop SoftwareSerial and use pins #0 and #1 (disconnect pins before uploading sketch)
  • try using ServoTimer2 or AltSoftSerial libraries that use a different timer (not tested)
  • get an Arduino Mega which has additional hardware serial ports

Jaap, this is FilingCab V1.6
PWM frequency was boosted from 490Hz to 20KHz to get rid of hissing noise at low speed
Also the infamous SoftwareSerial library was dropped ]:slight_smile:

Serial:

  • move pin #11 to RX1 (pin #19)
  • move pin #12 to TX1 (pin #18)

PWM:

  • move pin #5 to pin #11
  • move pin #6 to pin #12

Smoother and quieter control

Happy driving, mind the stair :wink:

FilingCabV16.ino (14 KB)

@tolisn63

Any idea when Total RC commander will be available with the new protocol and a test sketch ?

Will wait for Joystick BT commander V5.0 feedback
Would say two or three weeks

The video App is now ready for test
Same demo sketch as Joystick BT commander V5.0

Check your mail and let me have your feedback :wink:

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

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

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

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:

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

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" :wink: :wink: :wink:
Try it:
https://www.google.com/search?hl=en&as_q="menu+button"+"tab+4"+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="menu+button"+"galaxy+tab+4"+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

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

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

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