1 Bluetooth LE introduction
Bluetooth LE-enabled devices to transmit data between each other, first form a channel of communication. There are following Key term shall be used in programming in PSoC 62S2 Wi-Fi BT Pioneer Kitl
- Generic Attribute Profile (GATT)
The GATT profile is a general specification for sending and receiving short pieces of data known as "attributes" over a BLE link. All current BLE application profiles are based on GATT. Review the Android BluetoothLeGatt sample on GitHub to learn more.
- Characteristic
A characteristic contains a single value and 0-n descriptors that describe the characteristic's value. A characteristic can be thought of as a type, analogous to a class.
- Service
A service is a collection of characteristics. For example, you could have a service called "Heart Rate Monitor" that includes characteristics such as "heart rate measurement." You can find a list of existing GATT-based profiles and services on bluetooth.org.
Others are important, but not neccessarily used in programming on hardware
- Descriptor
- Profiles
- Attribute Protocol (ATT)
2 Create Android APP
Android Studio is the official Integrated Development Environment (IDE) for Android app development, I have download and install Android studio, then create Application with default template,
with the project name of edrumer.example.com, I still keep two pages swap with finger.
3 Connection with PSoC 62S2 Wi-Fi BT Pioneer Kit
Use of the Bluetooth LE APIs requires you to declare several permissions in manifest file.
<uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Once the app has permission to use Bluetooth, app needs to access the BluetoothAdapter and determine if Bluetooth is available on the device.
int REQUEST_ENABLE_BT = 1; BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { // Device doesn't support Bluetooth } if (!bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); }
If Bluetooth is available, the device will scan for nearby BLE devices. Once a device is found, the capabilities of the BLE device are discovered by connecting to the GATT server on the BLE device. In this case the Address shall be used from the code in program
String address = "00:A0:50:00:00:00"; //MAC address... btDevice = bluetoothAdapter.getRemoteDevice(address); bluetoothGatt = btDevice.connectGatt(MainActivity.this, false, bluetoothGattCallback);
Once a connection is made, data can be transferred with the connected device based on the available services and characteristics.
String res = "28";//getSendText.getText().toString(); Log.d("Data to be sent ",res); byte[] mybyte = bytesHexStrTranslate.StringtoBytes(res); byte[] gtdt ; //gtdt = writeCharacteristic.getValue(); writeCharacteristic.setValue(mybyte); writeCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); bluetoothGatt.writeCharacteristic(writeCharacteristic);
The Characteristic shall got from UUID directly with the following value,
4 To Make the BLE Drum work
With previous action, the getting of data from eDrum is as easy as one line of code in setValue() function,
writeCharacteristic.setValue(mybyte);
I shall continue with the coding. There have been continuously changes in android functions, some language is absole and not recommendated. I have to take time for understand new one. That takes quite a lot of time. Next blog on how to code edrum in hardware.