My suggestion: Keep . It . Simple

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 >
2. 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
