Hi Kas
Can you please post the communication protocol for Total RC commander V1.1 ? The communication from the android device to the arduino and between the arduino and the android device.
Hi Kas
Can you please post the communication protocol for Total RC commander V1.1 ? The communication from the android device to the arduino and between the arduino and the android device.
Total RC commander is the "video aware" version of Joystick BT Commander V4.x They both share the same Communication Protocol with Arduino
[u]Communication from Android to Arduino/u
This is the relevant Android (Java) code snippet from Joystick Bluetooth Commander:
final int XvalB = Xval + 200;
final int YvalB = Yval + 200;
if((((Xant!=Xval) || (Yant!=Yval)) || (mTimeoutCounter>=mMaxTimeoutCount && mMaxTimeoutCount>-1))) // joystick position changed, or timeout occurred
sendMessage( new String(new byte[] {STX, (byte) (XvalB / 128), (byte)(XvalB % 128), (byte)(YvalB / 128), (byte)(YvalB % 128), ETX } ));
So, for Xval=0 Yval=0: XvalB = YvalB = 200 XvalB / 128 = YvalB / 128 = 1 XvalB % 128 = XvalB % 128 = 72 Data frame: <2 1 72 1 72 3>
for Xval=100 Yval=100: XvalB = YvalB = 300 XvalB / 128 = YvalB / 128 = 2 XvalB % 128 = XvalB % 128 = 44 Data frame: <2 2 44 2 44 3>
The data frame is send via BlueTooth to the arduino board and decoded. This is the AndroTest V1.3.ino code snippet:
void getJoystickState(byte data[5]) {
int joyX = (data[1]<<7) + data[2];
int joyY = (data[3]<<7) + data[4];
joyX = joyX - 200; // Offset to avoid
joyY = joyY - 200; // transmitting negative numbers
}
buttonState is transmitted as a Byte value and reflects the state of the pushed button Button #1 ON: 1 Button #1 OFF: 2 Button #2 ON: 3 Button #2 OFF: 4 Button #3 ...
On the Arduino side, data frame is decoded in getButtonState()
void getButtonState(int bStatus) {
switch (bStatus) {
// ----------------- BUTTON #1 -----------------------
case '1':
buttonStatus |= B000001; // ON
Serial.println("\n** Button_1: ON **");
// your code...
displayStatus = "LED ";
Serial.println(displayStatus);
digitalWrite(ledPin, HIGH);
break;
case '2':
buttonStatus &= B111110; // OFF
Serial.println("\n** Button_1: OFF **");
// your code...
displayStatus = "LED ";
Serial.println(displayStatus);
digitalWrite(ledPin, LOW);
break;
// ----------------- BUTTON #2 -----------------------
case '3':
buttonStatus |= B000010; // ON
Serial.println("\n** Button_2: ON **");
// your code...
displayStatus = "DEBUG ";
Serial.println(displayStatus);
DEBUG = true;
break;
case '4':
buttonStatus &= B111101; // OFF
Serial.println("\n** Button_2: OFF **");
// your code...
displayStatus = "DEBUG ";
Serial.println(displayStatus);
DEBUG = false;
break;
....
}
[u]Communication back from Arduino to Android:[/u]
Arduino code
void sendBlueToothData() {
....
mySerial.print((char)0x2); // Start of Transmission
mySerial.print(getButtonStatusString()); mySerial.print((char)0x1); // buttons status feedback
mySerial.print(GetdataInt1()); mySerial.print((char)0x4); // datafield #1
mySerial.print(GetdataFloat2()); mySerial.print((char)0x5); // datafield #2
mySerial.print(displayStatus); // datafield #3
mySerial.print((char)0x3); // End of Transmission
....
}
Data frame transmitted back from Arduino to Android device: (by default, every 1000ms) < STX Buttons state 0X01 DataField#1 0x04 DataField#2 0x05 DataField#3 ETX >
example: < 0X02 001011 0X01 120.00 0x04 -4500 0x05 Motor enabled 0x03 >
Button state: This is a six character string reflecting the Arduino state for buttons position button #1,#2,#4: ON, all others: OFF >>> 001011 This feedback avoid any discrepancy with the Android device button state An Arduino Reset will reinitialize the Android buttons, Two way communication is mandatory for "clean" control Button state string is created in the getButtonStatusString() function.
String getButtonStatusString() {
String bStatus = "";
for(i=0; i<6; i++) {
if(buttonStatus & B100000 >>i) bStatus += "1";
else bStatus += "0";
}
return bStatus;
}
Datafields: Data is transmitted as ASCII characters using Serial.print() Numbers are printed using an ASCII character for each digit 120.00 >>> 0X31, 0X32, 0X30, 0X2E, 0X30, 0X30
So < 0x02 001011 0x01 120.00 0x04 -4500 0x05 Motor enabled 0x03 > is actually transmitted as < 0x02, 0x30,0x30,0x31,0x30,0x31,0x31, 0X01, 0x31,0x32,0x30,0x2E,0x30,0x30, ** ** 0x04, 0x2D,0x34,0x35,0x30,0x30, 0x05, 0x4D,0x6F,0x74,0x6F,0x72,0x20,0x65, ** 0x6E,0x61,0x62,0x6C,0x65,0x64, 0x03 >** without commas and spaces
Should you have additional questions, let me know ;)
Firstly thanks Kas this is a great app/sketch.
I too couldnt get it to work but after some playing around i got this to work with these settings:
// Arduino RX to TX BlueTooth module // Arduino TX to RX BlueTooth module // make sure your BT board is set @9600 bps //Set Serial Monitor rate to 9600 bps
Thanks Kas for the protocol information
@Maudey Thanks for the feedback I edited reply #182 based on your comments Please post an App screenshot, together with your screen size and resolution This will help me optimizing App display layout
What BT brand are you using ?? Most boards default to 9600bps, which is a bit slow I strongly suggest to boost your board @57600bps
@tolisn63 Did you try the on board mini router ?? I hardwired connection between IP camera and router and still have to observe any noticiable lag 8)
Hi Kas
The mini router did not come in yet. I'm waiting to see how it goes.
Hi kas
Thank's for your help! Now it works fine for me :) I really appreciate this app/sketch :D
Hi I have a small problem. I didnt get receive any of datafields.
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
Hi I have a small problem. I didn't get receive any of datafields.
I bit more information would definitely help ...
I use your basic sketch and your app, but under datafields in android is only xxxx
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
[u]Android side/u: 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)
[u]Arduino side:[/u] 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
[u]Finally:[/u] 9) your serial monitor should anycase display: AndroTest V1.3 - @kas2014 demo for V4.X (6 button version) does it ??
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
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
Hi Bob1943
I think your “Joystick bt commander” is brilliant
Thanks 8)
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... :roll_eyes: :roll_eyes:
Is there a correct boot up sequence between Arduino and Anroid or doesn’t it matter?
No, doesn't matter
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
// 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
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
@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 ??
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
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
@ n3kx
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
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 ??
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
@ 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
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.