Android Bluetooth joystick

Kas ... I've had the data field etc become just xxx ...and stay like that after reconnecting to the Blue Tooth....but only when I've been playing about uploading new code to the Arduino with the Joystick Commander App still ON ...turning the App OFF then ON again resolves this for me.

Is it OK to remove the if**(i==7)** and just have else?

Hi Kas, Woody,

Here's the video showing the this code

Serial.print("i=");  Serial.println(i);         // <<--- debug
if     (i==2)        getButtonState(cmd[1]);    // 3 Bytes  ex: < STX "C" ETX >
else if(i==7)        getJoystickState(cmd);     // 6 Bytes  ex: < STX "200" "180" ETX >

inserted just before

if     (i==2)        getButtonState(cmd[1]);    // 3 Bytes  ex: < STX "C" ETX >
else if(i==7)        getJoystickState(cmd);     // 6 Bytes  ex: < STX "200" "180" ETX >

Let me know what's going on.............Thanks.........Antonio

Well that seems to explain it!!..Your seeing i=2 for a button press which is CORRECT.

BUT i=5 is WRONG it should be i=7 ....if it isn't a 7 it'll never look down the code at the joystick input.

This isn't your fault Antonio...just an unexpected and unforeseen circumstance.

Kas probably won't be on till tomorrow ....he is the man that will know more ...in the mean time you could try changing that 7 in the line

else if(i==7) getJoystickState(cmd);

to a 5 and see what happens...so it becomes.

else if(i==5) getJoystickState(cmd);

OR..just change it to my favorite option which is.

else getJoystickState(cmd);

which means that if the number isn't a 2 it WILL go down the code for any joystick values.

Woody

Goodnight ..it's 00.48am here in the U.K. ZZZZzzzzzzzzzzzzzzzzzzzzzzz

Is it OK to remove the if(i==7) and just have else?

No it won't work

i<>2 and i<>7 means "communication error"
You can't expect valid data out of bad data frames

kas:
No it won't work

i<>2 and i<>7 means "communication error"
You can't expect valid data out of bad data frames

I realise that the joystick data read... if any ... by removing the if and i==7 may not be valid but it would give Antonio "hope" to see something being produced by the joystick .... even if it is WRONG.

But your right it may well be best to track down the real reason for the problem.

So.

Any idea of what the data problem is likely to be or the solution?

Do you suspect that it is simply the current Android phone being used that is at fault?

Cheers Woody

@antonio

This is my personal V2 debug version, don't break it :wink:

You should see that type of info on your Serial Monitor:

See reply #252 for data frame explanations
The last 3 numbers on the right are errors, sorted by categories

Please let us have a new video

@woody

Do you suspect that it is simply the current Android phone being used that is at fault?

Data transmission is not far from Black Magic :smiling_imp:
very sensitive to timing issues that could be generated by an underpowed device

AndroTest_V20_POSTED_DEBUG.ino (9.25 KB)

@woody
Quote
Do you suspect that it is simply the current Android phone being used that is at fault?
Data transmission is not far from Black Magic :smiling_imp:
very sensitive to timing issues that could be generated by an underpowed device

Uuummmm .... was that a yes ,no or maybe? :o

Uuummmm .... was that a yes ,no or maybe?

Still hesitating for the moment :wink:
Dual-core 1.2 GHz should be plenty enough
Let's wait for Antonio's data frames

Kas,

I downloaded - AndroTest_V20_POSTED_DEBUG.ino from your post #425, this is the same one as before, I'm assuming, but I downloaded again to make sure and that is what you want me to try, correct?

Kas and Woody,

Here's the video, towards the end of the video I zoom in while using the phone, at that point you'll be able to see the data up close.

Now I'm assuming that I'm not the only guy that this is happening to?.....maybe? However, I have been know to lose a bet on a one horse race. Hopefully this is not the case here.

Thanks.............Let me know what's going on.

Thanks Antonio,

I now see what happens

Please go to setup and press "reset options"

also, In AndroTest_V20_POSTED_DEBUG.ino, within this code snipet:

     while(mySerial.available())  {
       delay(1);    //   <----------<<
       cmd[i] = mySerial.read();
       if(cmd[i]>127 || i>7)                 break;     // Communication error
       if((cmd[i]==ETX) && (i==2 || i==7))   break;     // Button or Joystick data
       i++;
     }

try increasing delay
change
delay(1);
to
delay(2);
and see if errors are disappearing

Also, in the App, try Option >> advanced users >> refresh interval: 100 milliseconds

     while(mySerial.available())  {
       delay(1);
       cmd[i] = mySerial.read();
       if(cmd[i]>127 || i>7)                 break;     // Communication error
       if((cmd[i]==ETX) && (i==2 || i==7))   break;     // Button or Joystick data
       i++;
     }

within AndroTest V2, this "while" loop does collect the incoming data frame and should succesfully exit when receiving an ETX (0x03) byte.
Error exit is triggered if received Byte is >127 or frame lenght is >8

As you see, for some reason, Arduino receives Bytes >127 (149, 144, 176 ...) and a Data frame error is generated.

Now... why and where are these Bytes generated :roll_eyes: :roll_eyes: :roll_eyes:

  • from the Android device

reset App options to factory default
increase delay(1)
set refresh interval to 100 milliseconds
test the App on another Android smartphone

  • from the BT card

change card baud rate (38400bps)
setup another card

Thanks Kas,

As of now,

I resat the app to factory default
increased delay to (2)
sat the refresh interval to 100 milliseconds

Nothing changes, all remains the same.

So, I'm trying to find someone with an android phone or tablet that I can use, so we'll see what happens.

Thanks.........and talk to you later.

I tried to reproduce these errors without success :-\ :-\

This is a call for witnesses

  • buttons data display = OK
  • joystick data display = not OK

Anyone ??

>> EDIT <<
Problem solved using a genuine Uno :smiling_imp: :smiling_imp: :smiling_imp:
See reply #447

Antonio,

  1. In loop() function, try commenting last line:
    sendBlueToothData(); -> // sendBlueToothData();
    This will stop Arduino to Android communication and reduce Bluetooth traffic

  2. Also for the good sake, confirm again your BT card baudrate

  3. Finally let us know the outcome, using another phone/tablet

Kas,

Would this explain the problems?

http://forum.dev.arduino.cc/index.php?topic=140299.0

I've sent Antonio this utility/program that I found sometime ago ...( it's mentioned in the link above )...to check and or set the Baud rate.

BT_Config_HC_06_baud.ino (3.35 KB)

Woody, Kas

Here's another video showing my latest attempt.

Refresh interval - set at 100 milliseconds

Thanks..............Let me know what you think.

Kas,
Would this explain the problems?
http://forum.dev.arduino.cc/index.php?topic=140299.0

Interesting comment in the thread you mentioned:

If I use the Hardware serial ports on the Mega, everything works perfectly, no odd bits :astonished:
Using SoftwareSerial it does not work on the Uno or Mega.
So I assume that the Bluetooth module is fine, but the SoftwareSerial has a problem

Antonio,
Please confirm you have a Mega Arduino available
This board has several hardware serial ports that may solve the problem
I will then prepare a V2.0 sketch for the Mega, for you to test

Note that Antonios video shows rubbish for the end of the name linvor.

Here's a pic of mine.

Note that Antonios video shows rubbish for the end of the name linvor

Yes, seen that ::slight_smile:

The two remaining potential culprits are BT card and Softserial/Arduino board
Let's try a Mega board

Here is the code for the Mega

Attach pin#18 to RX bluetooth module and pin#19 to TX bluetooth module
Do not modify delay(1)
Reset options to factory setting in the App

Next stop: BT card :wink:

AndroTest_V20_POSTED_DEBUG_MEGA.ino (9.12 KB)