Go Down

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

woodygb

#420
Dec 16, 2014, 11:21 pm Last Edit: Dec 16, 2014, 11:34 pm by woodygb
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?

AntonioLopez

Hi Kas, Woody,

Here's the video showing the this code


Code: [Select]
     
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  
Code: [Select]
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 >


https://www.youtube.com/watch?v=5HIAY2zPf7I&feature=youtu.be



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

woodygb

#422
Dec 17, 2014, 01:29 am Last Edit: Dec 17, 2014, 09:25 am by woodygb
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

kas

#423
Dec 17, 2014, 10:07 am Last Edit: Dec 17, 2014, 10:09 am by kas
Quote
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

woodygb

#424
Dec 17, 2014, 10:59 am Last Edit: Dec 17, 2014, 11:06 am by woodygb
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

kas

#425
Dec 17, 2014, 11:41 am Last Edit: Dec 17, 2014, 11:49 am by kas
@antonio

This is my personal V2 debug version, don't break it  ;)

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
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  :smiley-evil:
very sensitive to timing issues that could be generated by an underpowed device


woodygb

Quote
@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  :smiley-evil:
very sensitive to timing issues that could be generated by an underpowed device
Uuummmm .... was that a yes ,no or maybe?  :o 

kas

#427
Dec 17, 2014, 01:17 pm Last Edit: Dec 17, 2014, 01:22 pm by kas
Quote
Uuummmm .... was that a yes ,no or maybe? 
Still hesitating for the moment  ;)
Dual-core 1.2 GHz should be plenty enough
Let's wait for Antonio's data frames

AntonioLopez

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?


AntonioLopez

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.

https://www.youtube.com/watch?v=Hav3gtyR1UQ&feature=youtu.be

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.

kas

#430
Dec 17, 2014, 07:18 pm Last Edit: Dec 17, 2014, 07:19 pm by kas
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:
Code: [Select]
     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

 

kas

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

kas

#432
Dec 17, 2014, 10:16 pm Last Edit: Dec 17, 2014, 10:49 pm by kas
Code: [Select]
     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  :smiley-roll:  :smiley-roll:  :smiley-roll:
- 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



AntonioLopez

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.

kas

#434
Dec 18, 2014, 03:24 pm Last Edit: Dec 30, 2014, 11:24 am by kas
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     :smiley-evil:  :smiley-evil:  :smiley-evil:
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

Go Up