Go Back   IceInSpace > Equipment > Mobile Astronomy Apps

Reply
 
Thread Tools Rate Thread
  #1  
Old 03-11-2011, 06:54 AM
hikerbob's Avatar
hikerbob (Bob)
Registered User

hikerbob is offline
 
Join Date: Jan 2008
Location: Redlands, Australia
Posts: 253
Android and Bluetooth - what I've found sofar

I've been trying to make a start in using Android for remote control of devices. No actual motors have been moved in the making of these notes yet. Thought it might be worthwhile to put together some notes for others interested in the same thing to see where that leads.

I've not managed to find anything on line yet for a group working on control of astronomical devices from Android devices.

I've managed to get my HTC Wildfire talking to a serial bluetooth module hooked to an Anduio Mega, at this stage trying to get the com's more reliable.

Still very early days for me so if more experienced programmers spot errors please correct them.

I'm on android 2.2 which appears to still be very limited by way of USB support for external devices and I'd like if possible to be wireless where practical hence the use of bluetooth. Wi-fi gives the impression that it would be more complex.

There are a heap of tutorials online about getting started with Android programming (which is mostly done in Java). One which seems to cover it is at http://mobileorchard.com/introductio...d-development/


He has a range of articles most of which I've not used yet. http://mobileorchard.com/category/tutorials/android/

Also some useful notes on setting up at http://developer.android.com/sdk/installing.html

It is possible to work directly with the Android SDK without Eclipse but I've not tried it.

The stuff I'm doing is based on a modified version of the bluetooth-chat sample which is included with the Android SDK . You can build a new android project based on a sample as an option when you start the wizard for a new project.

A bug in the bluetooth stack used by a lot of android devices means that the sample project probably won't connect to a bluetooth serial device. A dodgy workaround is to set a generic UUID, in the bluetoothchatservice.java file (under the src area) set the UUID
// Unique UUID for this application
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

There are other alternatives which work around the bug and possibly get a real UUID using a dedicated app, intents etc but I've not managed to get the simpler ones working and there was mention of other stuff not working, factory resets etc afterwards so I'm leaving that for now.

The worst failure I've had is having to restart the phone by pulling the battery out.

I'm using an Arduino Mega on the other end of the bluetooth comms at the moment so that I have multiple serial ports. Eventually I'd like to either use one of the smaller Arduino's to drive a focuser or hook a bluetooth module directly to a mount's TTL serial port (an Android EQMOD?). Note for experimenters, the serial ports intended to talk to PC serial ports are not the right voltages and would need interfacing.

I gather that the baud rate is not relevant for Bluetooth itself and I'm running the Serial3 port which is connected to the Bluetooth module at 115200.

I'll post my Arduino code in a follow up post, pretty basic and just for testing. I've started adding in the Skywatcher API commands but the Arduino so far does very little except let me know what it's received.

The Skywatcher API is published at http://code.google.com/p/skywatcher/...atcherProtocol and via http://code.google.com/p/skywatcher/

Still a lot of learning to go but I'm hoping that my learning's may prompt some useful discussion or help someone else get started. The ultimate goal out of all this with be an ASCOM like approach to Android control of Astronomical devices. I'd also like to see something like EQMOD available via Android (preferably with an Alt/Az option for motorised Dob's).

Please also note, all care no responsibility. Writing apps for your phone or tablet using the Android SDK and Eclipse should be safe but I'm not responsible if you manage to make a lightweight brick of that expensive gadget.

Bob
Reply With Quote
  #2  
Old 03-11-2011, 07: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
  #3  
Old 03-11-2011, 07:48 AM
hikerbob's Avatar
hikerbob (Bob)
Registered User

hikerbob is offline
 
Join Date: Jan 2008
Location: Redlands, Australia
Posts: 253
Some Android code snippets

As mentioned earlier I've added a new button and some code to send commands. Not a good structure there currently it's expedient but likley to be short lived. I'd also renamed the project and code to BluetoothFocus rather than BluetoothChat so some of the naming won't match the samples.

This stuff should be in bluetoothchat.java under src. The moveAxis procedure in new, the other is an altered version of setupChat from that file. I've not managed to append integers to a string reliably yet so I send
multiple messages which is ugly. moveAxis does not relate to focus control, it's a test bed for my learning's so I will have to redo a buch of things when I work out how to do them.

Under // Layout Views the buttons are defined
private Button mInButton;
private Button mOutButton;

Then further down behaviours are setup.

private void moveAxis(Integer pIncrement) {
Integer lPosition;
// TextView view = (TextView) findViewById(R.id.edit_text_out);
lPosition = iPosition + pIncrement;
sendMessage(":E");
sendMessage(lPosition.toString());
sendMessage("* ");
// Replace this with a read position call
iPosition = lPosition;
}

private void setupFocus() {
Log.d(TAG, "setupFocus()");

// Initialize the array adapter for the conversation thread
mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
mConversationView = (ListView) findViewById(R.id.in);
mConversationView.setAdapter(mConve rsationArrayAdapter);

// Initialize the compose field with a listener for the return key
mOutEditText = (EditText) findViewById(R.id.edit_text_out);
mOutEditText.setOnEditorActionListe ner(mWriteListener);


// Initialize the In button with a listener that for click events
mInButton = (Button) findViewById(R.id.button_in);
mInButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
moveAxis(-10);
}
});

// Initialize the Out button with a listener that for click events
mOutButton = (Button) findViewById(R.id.button_out);
mOutButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
moveAxis(10);
}
});
Reply With Quote
Reply

Bookmarks

Tags
android, bluetooth, skywatcher

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time is now 12:53 AM.

Powered by vBulletin Version 3.8.7 | Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Advertisement
Bintel
Advertisement
Testar
Advertisement