Android is very prevalent now, especially ADK. It allows outside 0pen source hardware to attach with Android system by USB and interrelate with an Android-powered expedient in a special “accessory” mode.
We should keep employed on it for weeks, and should attempt to collect some bate prototype and make a library for the communiqué among Android and Arduino by bluetooth and Freaduino for ADK.
We are gifted to deliver this board from now on with the Google if source files. We can produce a batch, you can acquisition them now. We will deliver the Bata form as soon as possible.
To make the communiqué among Android and Arduino calm, we would like display you an original way that android interrelate with Arduino and other like boards. Bluetooth for example.
- Step one: Make an APP to Android which might connect with other policies by bluetooth.
- Step two: Android APP attach to Arduino by Bluetooth Bee.
This APP permits Android attach to every other by bluetooth, so you necessity at least two Android devices for this sample. Here we can secondhand two Android phones which are SAMSUNG I7680 and Lenovo O3. Then, there should be a complete growth environment like Eclipse on your PC. You can discovery many of them in the Internet.
The Android stage comprises care for the Bluetooth network stack, which permits a device to wirelessly discussion data with additional Bluetooth devices. The application framework offers entree to the Bluetooth functionality over the Android Bluetooth APIs. These APIs lease applications attach wirelessly to other Bluetooth devices, allowing point-to-point and multipoint wireless structures.
Completely of the Bluetooth APIs are obtainable in the Android bluetooth bundle. Now there is a summary of the classes you will must to make as under.
- Bluetooth Adapter: Embodies the local Bluetooth adapter (Bluetooth radio)
- Bluetooth Device: Embodies a remote Bluetooth device, query information such as its title, discourse, class, and affection state.
- Bluetooth Socket: Embodies the border for a Bluetooth socket (similar to a TCP Socket).
- Bluetooth Server Socket: Embodies an exposed server socket that attends for received requests (similar to a TCP Server Socket).
- Bluetooth Class: Defines the over-all features and abilities of a Bluetooth device. Bluetooth Consents
In order to use Bluetooth landscapes in your presentation, you must to state-run at smallest one of two Bluetooth consents: BLUETOOTH and BLUETOOTH_ADMIN.
State the Bluetooth permission(s) in your application’s AndroidManifest.xml as underneath.
<manifest … >
<uses-permission android:name=”android.permission.BLUETOOTH” />
<uses-permission android:name=”android.permission.BLUETOOTH_ADMIN” />
In order to attach by bluetooth, there should be four phases as under:
- Setting Up Bluetooth
- Finding Device
- Connecting Device
- Managing Device.
For the Bata, we lone necessity to use Activity01, Discovery Activity, ClientSocketActivity and ServerSocketActivity.
Before your application can connect with Bluetooth, you should confirm Bluetooth is maintained on the device and make certain that it is allowed. If Bluetooth is not maintained, you should elegantly restrict any Bluetooth structures. If Bluetooth is maintained, but restricted, you are capable to appeal the user allow Bluetooth without leave-taking your application.
There are two ways to enable bluetooth:
- //Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
- //startActivityForResult(enabler, REQUEST_ENABLE);
_bluetooth. Enable (); the first way, make a new Intent as
“Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)”,
A discourse box will look and request worker consent to allow Bluetooth. Choice “Yes” and the system will allow Bluetooth and attention will arrival to your application once the method completes (or fails). “Yes” proceeds RESULT_OK and “No” returns RESULT_CANCELED.
With Discovery Activity.java file, we will find about stratagem. The process is asynchronous and the way will directly return with a boolean representing whether detection has started effectively. The discovery process typically includes an analysis scan of about 12 seconds, trailed by a page scan of all found device to save its Bluetooth name. Your request must register a BroadcastReceiver for the ACTION_FOND. Resolved in order to obtain information about each device exposed.
After detection will return distant device’s MAC address, device name and class. Using this information, the device execution detection can then select to freshman an assembly with the open device. The following figure is tick the “Search Device” button.
Connecting Device and Managing Device
In command to make an assembly between your application and two strategies, you need implement the together server-side and client-side mechanisms, since one device must open a server socket and the other one must pledge the connection (use the server device’s MAC address to initiate a connection). So you must use a same UUID, I rummage-sale one find from internet and you can grow the UUID here: the UUID Generator.
One application method is to mechanically make each device as a server, so that both one has a server socket open and listening for networks. Then either device can recruit a construction with the other one as the client. Otherwise, one device can explicitly “host” the construction and open a server opening on call and the other device can only recruit the connection.
_serverSocket = _bluetooth.listenUsingRfcommWithServiceRecord(PROTOCOL_SCHEME_RFCOMM,
UUID.fromString(“a60f35f0-b93a-11de-8a39-08002009c666”)); As Client
socket = device.createRfcommSocketToServiceRecord(UUID.fromString(“a60f35f0-b93a-11de-8a39-08002009c666”));
It need choice a server and a client, we has ended two buttons which are “AS Client” and “AS Server”. Then one handset will be server and the other will be client.
Frist, this construction used Socket way, so there are some frequently functions such as attach, close, attend and so on and there are others stream regulator such as getInputStream, getOutputStream …select “AS Server” button, then you will see the next show.
Click the “AS Client” button, it will learn distant devices and display the devices slope. It will call DiscoveryActivity class and display the devices list at last, then click one device to attach to server, send socket.connect() to server and join to RFCOMM Channel.