This example uses Python as the scripting language for the Android scripting layer (SL4A) but you can choose from other languages like Perl, Lua, JavaScript etc. see: http://code.google.com/p/android-scripting/
Remove these ads by
Signing UpStep 1: You need:
http://www.dealextreme.com/p/jy-mcu-arduino-bluetooth-wireless-serial-port-module-104299
or search for "bluetooth module" on ebay
I've bought mine for $8.20 on dealextreme.
2. An Android device with bluetooth.
3. An Arduino board.
4. Some sensor or potentiometer to read values from.



































Visit Our Store »
Go Pro Today »




I have the exact bluetooth module that you have but I can't send anything to this module. Below is simple echo code that I use. Have I missed anything?
Thank you.
Arduino mega 2560
const int LED_PIN = 13;
boolean toggle = true;
void setup() {
Serial1.begin(9600);
}
void loop() {
if (Serial1.available()) {
Serial1.println(Serial1.read());
digitalWrite(LED_PIN, toggle);
toggle = !toggle;
delay(1000);
}
}
please tell the program for arduino to transfer accelerometer sensor value serially using a bluetooth ttl interface
My module's documentation goes here :http://www.robokits.co.in/documentation/Bluetooth%20UART%20Module%201545.pdf
I think this will be helpful to lot of other undocumented module owners cause I have similar module.
Is there any idea how to make it discovered by Android?
"HC-06 Bluetooth V2.0 RF Wireless Transceiver Module Interface RS232 TTL"
This is my code:
#define trigPin 13
#define echoPin 12
const int LED1 = 8;
int sensorValue = 0;
boolean toggle = true;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LED1, OUTPUT);
}
void loop() {
if (Serial.available()) {
Serial.read();
}
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 200 || distance <= 0){
Serial.println("Out of range");
digitalWrite(LED1, LOW);
}
else {
Serial.print(distance);
Serial.println(" cm");
digitalWrite(LED1, HIGH);
sensorValue = Serial.print(distance);;
digitalWrite(LED1, toggle); // toggle the LED
toggle = !toggle;
}
delay(500);
}
Is there any way to just send serial command to arduino like the serial monitor in the IDE?
Anyway, Pretty neat instructable....
One question, as my Python scripting is not that hot - if I wanted to connect multiple bluetooth modules e.g. 2+ and route them all through my pad to my website how would I poll each module? something like this?.....
For x = 0 to (amount of bluetooth modules)
If BT(x) connected/success Then .....
TX/RX
End If
Loop
[SyntaxError: can't assign to operator (androino2.py, line 13)]
line 13 is the line where i am assigning the BT_DEVICE_ID.
When I open SLA4, all I see is the html file, not the py file, which is defininately in the same directory as the html one...
Any thoughts on where I've gone wrong?
Thanks in advance :)
Great for making buttons to send what you want for your commands. message me if you want an example of what I did for my android controlled car. easier in my opinion than a keyboard with small letters and big fingers.
from -- http://rocketbrandstudios.com/ -- This worked fine and returned
either an 8-bit or 10-bit value (depending on the call in the axe firmware) that
matched voltage on a pot (turn the pot, get a new value).
So now I am trying to use your Python approach. I have the BT only connected as a transmitter from the Picaxe and it just loops and sends a value out. When I run the Python code I see the connection light work but nothing happens when I click "get sensor data". I also tried the "dump.py" code. It also connects and gives back a couple of lines --
Result(id=2, result=u' .. very long what look like a MAC address ...', error=None)
Result(id=3, result=u'linvor', error=None)
-- and then nothing else. From some looking around, it looks like 'linvor' may be the default name for the module. Any ideas? Is there someplace where I can find documentation on ... droid.bluetoothReadLine() ...? Thanks for any help.
http://code.google.com/p/android-scripting/wiki/ApiReference
any thoughts
Now I would like to reverse it and have the android phone send a signal to the arduino to turn a led on and off
BT_DEVICE_ID = '00:11:11:18:62:60'
to the id of your module?
Did you pair the module with your android?
If the address that goes into the .py file is from the BT module, I'm not sure how to find it. As far as I can tell, I cannot find it just by looking at the module in the list of devices shown on my phone. Could this be that I am using an older phone (Nexus One), or the 2.3.6 operating system?
So you know, I ordered my piece from Ebay but it looks almost identical to the one shown above from dealextreme. It's my theory that the settings were changed by whoever the vendor was. The only physical difference I can see in the parts is that the gold strip that "zig-zags" at the top of my module has one less "zig-zag". I don't know what it does though. See the image I attached of my own module.
For changing the module name, baud rate etc.: http://wiki.openpilot.org/display/Doc/Serial+Bluetooth+Telemetry
Advice to anyone else in the USA, use a North American seller on eBay.
And sometimes the orders get stuck in customs for over a week here in germany :(
Thanks for the writeup - I'll be trying this soon. :-)
In the androino.py python script, the following line of code opens the webview.
droid.webViewShow('file:///sdcard/sl4a/scripts/tulpe/androino.html')
In my case I had to modify the code to exclude "/tulpe". So it now reads
droid.webViewShow('file:///sdcard/sl4a/scripts/androino.html')
Without this change, I was getting a blank screen that did nothing because androino.py couldn't find the html file.
Anyway, Thanks metanurb for this instructable! I can't wait to start making awesome bluetooth telemetry stuff!
Question re the bluetooth: How does the JY-MCU compare to the BlueSmirf modules? It's a lot cheaper and so I was going to order one, but why is this one 8 bucks and the others are 40-60?
Also, what baud rates can you get through this module? If I had a python module talking to the bluetooth, how many commands could I issue per second?
Baud rate goes up to 230400 and I have mine running reliable at 115200 (7m indoor).
More info about the baud rates can be found here: http://wiki.openpilot.org/display/Doc/Serial+Bluetooth+Telemetry
As for the rate: 115200 / (8+1) = 12800 byte / second (if I get this right).
Do you by any chance know of a barcode scanner using the Android Scripting Layer and/or Python for Android ?
import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code.result['extras']['SCAN_RESULT'])
url = “http://books.google.com?q=%d” % isbn
droid.startActivity(‘android.intent.action.VIEW’, url)
droid = android.Android()
isbn = droid.scanBarcode().result['extras']['SCAN_RESULT'])
url = “http://books.google.com?q=%d” % isbn
droid.startActivity(‘android.intent.action.VIEW’, url)
http://www.mithril.com.au/android/doc/
Sensor data documentation:
http://www.mithril.com.au/android/doc/SensorManagerFacade.html