View Single Post
  #2  
Old 03-11-2011, 08:38 AM
hikerbob's Avatar
hikerbob (Bob)
Registered User

hikerbob is offline
 
Join Date: Jan 2008
Location: Redlands, Australia
Posts: 253
Some more notes
The Android emulator does not have bluetooth capabilities and isn't any use for testing Bluetooth activity.

I'm writing the numeric and character values of each byte out to the main Serial port on the Arduino in this example. Not sure why but without it I routinely miss part of the sent data in what's displayed elsewhere. Probably something basic and silly but I've not found it yet.

I added another button to the bluetooth chat sample and recoded the OnClick actions on the two buttons to send formatted commands to the bluetooth device rather than free text. All pretty rough so far.

The Arduino code I'm using to work with the recieved bluetooth comms. Mostly works with occasional glitches. I suspect that for a real app some kind of handshaking to confirm that the data was correct would be essential, a checkum and ability to resend the previous command would be a minimum. Not sure how that would work communicating with an existing API such as a mount though.

/*===========================
TITLE: Basic Android Bluetooth comms test
AUTHOR: Bob Stephens
DESCRIPTION: Framework for testing serial comms via Bluetooth from an Android (2.2)
COMPATIBLE BOARD: Arduino Mega
NOTES: Some of the Skywatcher API is included with the thought in mind that I can develop
that to mimic Skywatcher mount responses if I get to developing software to do mount control.
============================*/
int i = 0;
char input[10];
char inByte;

void setup() {
Serial.begin(9600); //INTIALISING THE SERIAL PORT
Serial3.begin(115200); //INTIALISING THE BLUETOOTH SERIAL PORT
Serial2.begin(115200); //INTIALISING THE BLUETOOTH SERIAL PORT
}

void loop() {
memset( &input, 0, 10 );
i = 0;
while ( Serial3.available() ) {
inByte = Serial3.read();
Serial.write(inByte);
Serial.print(" = ");
Serial.println(inByte);
switch (inByte) {
case 32:
// Space
break;
case 42:
// * End of Command
Serial.println(input);
Serial.println("--------------------");
Serial3.flush();
break;
case 58:
// : Start of command
break;
case 70:
// F - Initialise
Serial.println("Initialise");
break;
case 97:
// a - InquireGridPerRevolution
Serial.println("InquireGridPerRevol ution");
break;
case 98:
// b - InquireTimerInteruptFreq
Serial.println("InquireTimerInterup tFreq");
break;
case 101:
// e - InquireMotorBoardVersion
Serial.println("InquireMotorBoardVe rsion");
break;
case 103:
// g - InquireHighSpeedRatio
Serial.println("InquireHighSpeedRat io");
break;
case 115:
// s - InquirePECPeriod
Serial.println("InquirePECPeriod");
break;
case 76:
// L - AxisStopInstant
Serial.println("AxisStopInstant");
break;
case 75:
// K - AxisStopNonInstant
Serial.println("AxisStopNonInstant" );
break;
case 69:
// E - SetAxisPosition
Serial.println("SetAxisPosition");
break;
case 106:
// j - GetAxisPosition
Serial.println("GetAxisPosition");
break;
case 102:
// f - GetAxisStatus
Serial.println("GetAxisStatus");
break;
case 79:
// O - SetSwitch
Serial.println("SetSwitch");
break;
case 71:
// G - SetMotionMode
Serial.println("SetMotionMode");
break;
case 72:
// H - SetGotoTargetIncrement
Serial.println("SetGotoTargetIncrem ent");
break;
case 77:
// M - SetBreakPointIncrement
Serial.println("SetBreakPointIncrem ent");
break;
case 85:
// U - SetBreakSteps
Serial.println("SetBreakSteps");
break;
case 73:
// I - SetStepSteps
Serial.println("SetStepSteps");
break;
case 74:
// J - StartMotion
Serial.println("StartMotion");
break;
default:
input[i] = inByte;
++i;
}
delay(5);
}
}
Reply With Quote