Go Down

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

kas

#195
May 19, 2014, 04:12 pm Last Edit: May 19, 2014, 04:13 pm by kas Reason: 1
Quote
Hi kas
Thanks for your help! Now it works fine for me   :)
I really appreciate this app/sketch    :D

Thanks hulkpeppe for this positive feedback

@n3kx
Quote
Hi I have a small problem. I didn't get receive any of datafields.

I bit more information would definitely help ...

n3kx

I use your basic sketch and your app, but under datafields in android is only xxxx

kas

#197
May 23, 2014, 07:20 am Last Edit: May 23, 2014, 07:24 am by kas Reason: 1
Quote
I use your basic sketch and your app, but under datafields in android is only xxxx

Not a lot of additional info's   ;)

Carefully review those 9 questions and answer YES/NO

Android side (smartphone/tablet screen):
1) go to Option/About and confirm that installed version is V4.0 (or higher)
2) can you move the joystick and display position at bottom left
3) are you connected ("connected to: XXX", green text)

Arduino side:
4) are you using AndroTest V1.3.ino (or higher)
5) are Bluetooth TX connected to D2 and RX connected to D3
6) is your Bluetooth card already configured @57600 bps  (most are 9600bps by default)
7) is your Bluetooth card LED solid red or green  (blinking = not connected)
8 ) is your Serial monitor configured @57600 bps

Finally:
9)  your serial monitor should anycase display:
          AndroTest V1.3 - @kas2014
          demo for V4.X  (6 button version)
  does it ??

- any additional information ??

Bob1943

Hi Kas,
I think your "Joystick bt commander" is brilliant - just what I want for some projects I am looking at.
However, I am having intermittent problems connecting from Android to Arduino via HC-05 module and very rarely get data from Arduino to Android. Is there a correct boot up sequence between Arduino and Anroid or doesn't it matter?
When I changed the baud rate in AT commands I used AT+UART=57600,0,0 - is that correct?
Also I think I may have a mismatch of Wiring diagram/ino code/Android app. Can you email me details of where I can get the latest drawings/codes etc.
Again - brilliant application
Many thanks
Bob

n3kx

YES I have 4.0 version
YES I see changing position on bottom left
YES I am conncted

YES I using ArduinoTest V1.3.ino
YES I have Connected Bluetooth in right way
YES I have solid led
YES Is my serial monitor configured @57200 bps

YES My serial monitor display that information

kas

#200
May 23, 2014, 10:09 pm Last Edit: May 23, 2014, 10:14 pm by kas Reason: 1
Hi Bob1943

Quote
I think your "Joystick bt commander" is brilliant

Thanks  8)

Quote
I am having intermittent problems connecting from Android to Arduino via HC-05 module and very rarely get data from Arduino to Android

Can you be more specific, I would expect the App to always work or always fail... :smiley-roll: :smiley-roll:

Quote
Is there a correct boot up sequence between Arduino and Anroid or doesn't it matter?

No, doesn't matter

Quote
When I changed the baud rate in AT commands I used AT+UART=57600,0,0 - is that correct?

Yes, make sure you have entered the Command mode
I just prepared a sketch for my new HC-05 board.
Will display
- device name
- firmware version
- serial parameters

Code: [Select]
// Iteaduino BT board configurator - BASIC version

// Utility will display actual Baud rate

// TX BT board pin to Arduino D2
// RX BT board pin to Arduino D3
// 5V BT board pin to Arduino 5V
// GND BT board pin to Arduino GND

// set Serial Monitor @57600bps

#include "SoftwareSerial.h"

SoftwareSerial mySerial(2, 3);          // BlueTooth module TX RX
char response[30];                      // responses from module
int rv = 0;                             // return value

void setup()  {
 Serial.begin(57600);
 mySerial.begin(38400);                  //  config mode bps
 mySerial.setTimeout(500);
 delay(300);
 Serial.print("\n\nIteaduino BT board configurator ");
 Serial.print("\nSearching ...");        
 mySerial.write("at\r\n");               // BT card bug ???
 delay(20);
 mySerial.readBytes(response, 15);
 mySerial.write("at\r\n");               // "AT" will respond with "OK" if it is working
 delay(20);
 response[0] = 0;
 rv = mySerial.readBytes(response, 15);
 response[rv] = 0;
 if (strncmp(response, "OK", 2)==0)    Serial.println("\n\nBluetooth Module found");
 else  {
   Serial.println("\nERROR: Bluetooth Module not responding!");
   Serial.println("Make sure there are no active bluetooth connection and try again");
   while(1);
 }
 
 delay(100);
 mySerial.write("at+name?\r\n");               // Check device name
 while(mySerial.available() == 0);
 rv = mySerial.readBytes(response, 30);
 response[rv] = 0;
 if (strncmp(response, "+NAME:", 6)==0)  {
   Serial.print("Name: ");
   Serial.println(response);
 }  else  {  
   Serial.println("Error checking name");
   while(1);
 }

 delay(100);
 mySerial.write("at+version?\r\n");           // Check firmware version
 while(mySerial.available() == 0);
 response[0] = 0;
 rv = mySerial.readBytes(response, 30);
 response[rv] = 0;
 Serial.print("Version: ");
 Serial.println(response);

 delay(100);
 mySerial.write("at+uart?\r\n");           // Check serial parameters
 while(mySerial.available() == 0);
 response[0] = 0;
 rv = mySerial.readBytes(response, 30);
 response[rv] = 0;
 Serial.print("Serial: ");
 Serial.println(response);
}

void loop() { }

Please confirm your BT board baud rate

Quote
Also I think I may have a mismatch of Wiring diagram/ino code/Android app. Can you email me details of where I can get the latest drawings/codes etc.

Bluetooth TX connected to D2 and RX connected to D3
Joystick bluetooth Commander V4.0 is here
AndroTest V1.3.ino is there

Please answer the 9 questions as per above




kas

#201
May 23, 2014, 10:32 pm Last Edit: May 23, 2014, 10:39 pm by kas Reason: 1
@n3kx

Base on your responses, problem is the  BT card  to  Arduino board  serial connection
Is your BT card HC-05 or HC-06 ??
let me have a link to your specific model
You may reverse TX and RX cables just to make sure, this will not harm anything
Did you actuallly check you BT card baud rate ??  they usually default to 9600bps
Have succesfully used this card for other projects ??

Can you see the scrolling Joystick values in the Serial Monitor ??

n3kx

My model is HC-05 and it work @9600bps. I use your older version and it works, even on version 4.0 it works Arduino receive joystick data as button data no problem. But datafields doesnt change there are always showing XXXX.

I have this type of Bluetooth: http://www.ebay.com/itm/Wireless-Serial-6-Pin-Bluetooth-RF-Transceiver-Module-HC-05-RS232-Master-Slave-D-/400709013564?pt=LH_DefaultDomain_2&hash=item5d4c1e503c

Bob1943

Hi, thanks for your rapid response. Your assistance in helping is excellent. Hope I have answered your questions so I can get a response from Arduino UNO back to Android

>>>>>>>>I used the AT Command setup at this URL
http://arduinofy.blogspot.co.uk/2013/10/tutorial-programming-hc-05-at-mode-with.html

when completed AT+UART? Returned: 57600,0,0

>>>>>>>>Your sketch headed:
// Iteaduino BT board configurator - BASIC version
Returned the following error message:

    Iteaduino BT board configurator
    Searching ...
    ERROR: Bluetooth Module not responding!
    Make sure there are no active bluetooth connection and try again
I couldn't find anything paired with the HC-05
The red BT LED flashed on/off about every half second

>>>>>>>>Your sketch headed:
AndroTest V1.3 - @kas2014\ndemo for V4.X  (6 button version)
Only Connections:
.Arduino pin#2 to TX BlueTooth module
. Arduino pin#3 to RX BlueTooth module
..Arduino 3.3v to 3.3 BlueTooth module
..Arduino GND to GND
NOTE: Key and 5v not connected

Paired and connected with Android (v4.0.4) OK.
Still only xxx showing bottom left.
Interesting point is that button B5 stays locked the same as other buttons until pressed again to release. (I did notice at one time it did act like a push button - maybe that was when data got fed back). Just a thought
I think the connection problems may be down to me as that problem appears to have gone away.
My only problem now (apart from error in BT board configurator mentioned above) is the failure to get a signal from Arduino to Adoid.

Answers to 9 question in reply #197
1..Version v4.0.4
2. Yes
3. Yes
4. Yes
5. Yes
6. Yes
7. NO - Initially Red LED flashes continuously but when connected it flashes twice every couple of seconds (not solid red as in question)
8. Yes
9. Yes

Observations:
I am not experienced with serial coms., but understand there are parity and stop bits. When I changed the BT module to 57600 baud I sent AT+UART=57600,0,0 and the AT command AT+UART? returned: 57600,0,0
Is that OK?

BT Red LED flashes rapldly before pairing. Then when paired changes to on/off flash every 2 seconds then but when connected it flashes twice every couple of seconds.

UNO TX LED flashes about every 2 seconds and whenever a button is pressed. When the joystick is moved it constantly flickers, then after about 10 seconds of continuous joystick movement the TX LED locks on. Opening the serial monitor window seems to return it  back to normal.
UNO RX LED only ever flashes when uploading code

Hope some of this makes sense - thanks again for your help
Bob


kas

#204
May 24, 2014, 11:03 am Last Edit: May 24, 2014, 09:33 pm by kas Reason: 1
@ n3kx

Quote
even on version 4.0 it works Arduino receive joystick data as button data no problem. But datafields doesnt change there are always showing XXXX

Interesting
Android to Arduino communication is OK
Arduino to Android communication is not wired correctly

Quote
I have this type of Bluetooth: ...

The link is broken, please double check and let me know

Which Arduino board do you use ??
Can you post a photo of you setup ??
Did you modify the actual demo sketch ??

Quote
My model is HC-05 and it work @9600bps

Although this is not the cause of your problem, 9600bps is too slow for the data stream and generates transmission errors

I strongly urge everybody to set speed @57600bps

Depending on your specific model, I can post a tool for this adjustment



kas

@ n3kx

I just downgraded my HC-05 board to 9600bps and could reproduce your situation  ]:)  ]:)  ]:)

Please modify demo sketch as follow:
in void loop()  line #3               change  "delay(5);"   to   "delay(2);"
in void loop()  last line             remove  "delay(5);"

Did you make any change in Option for advanced users ??
Let me know your current settings for
- Refresh interval
- Time out count


n3kx

Today I bought HC-06 and it work @9600 pbs. So can you post code how to change it to whatever it need . I try change delay but same results.

kas

Quote
Today I bought HC-06 and it work @9600 pbs. So can you post code how to change it to whatever it need . I try change delay but same results.

Glad it works with HC-06
Please scroll up to reply #15 and download the HC-06 config tool

I own HC-05 and HC-06 cards and they both work flawlessly @57600bps

Quote
Did you make any change in "Option for advanced users" ??
Let me know your current settings for
- Refresh interval
- Time out count

Please reply

kas

#208
May 24, 2014, 09:11 pm Last Edit: May 24, 2014, 09:29 pm by kas Reason: 1
@Bob1943
Quote
Still only xxx showing bottom left

Are you referring to the joystick position field at bottom left of android device screen ??   :smiley-eek:
This should indicate joystick position at App start up, even before any connection
It should read (-100,-100) for South West position and (100,100) for North East position

Quote
Interesting point is that button B5 stays locked the same as other buttons until pressed again to release. (I did notice at one time it did act like a push button - maybe that was when data got fed back).

This is normal behavior when not connected

Quote
My only problem now (apart from error in BT board configurator mentioned above) is the failure to get a signal from Arduino to Android.

- You can follow joystick position and buttons state on you Serial Monitor
- Datafields don't update, B5 is not in "push" mode
Correct ??

Quote
Answers to 9 question in reply #197
1..Version v4.0.4

I was talking about App version, should be V4.0       OK ??

Quote
the AT command AT+UART? returned: 57600,0,0 Is that OK?

Yes
According to documentation
Param2 = stop bit:   0->1 bit  1->2 bits
Param3 = parity bit:   0->None  1->Odd parity  2->Even parity
Arduino serial is 8N1 (1 stop bit, no parity)

Quote
UNO TX LED flashes about every 2 seconds and whenever a button is pressed. When the joystick is moved it constantly flickers,

This reflects the data flowing from Arduino to Serial Monitor

Quote
then after about 10 seconds of continuous joystick movement the TX LED locks on. Opening the serial monitor window seems to return it  back to normal.

Strange  :smiley-slim: :smiley-slim:


Did you change any setting in Advanced options ??
Try "reset Option" to restore initial parameters
EDIT: also set Refresh interval @100ms, Timeout count @every 10 intervals

Finally let me have a link to your specific BT board

Bob1943

Data flow from Arduino to Android problem SOLVED

I am using Joystick BT Commander on an Android Tablet. This allows Apps to be closed by swiping the minimised app icon off the screen. This was the problem.

When I closed the App by using back button (hairpin arrow) and confirm "Total RC Commander - close this controller" and then re-open the App it works OK.
Data received back from Arduino and Button 5 is in push mode.
Apologies for inconvenience and thanks for your time.
It is great to see the care and level of attention that you provide to the users of your App.
Again many thanks - Brilliant App
Bob

Go Up