element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Low Power IoT Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Low Power IoT Design Challenge
  • More
  • Cancel
Low Power IoT Design Challenge
Blog Handy BLE drum #4 Build with Android Studio  BLE Application
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fyaocn
  • Date Created: 5 Nov 2021 3:05 AM Date Created
  • Views 1606 views
  • Likes 1 like
  • Comments 2 comments
Related
Recommended

Handy BLE drum #4 Build with Android Studio  BLE Application

fyaocn
fyaocn
5 Nov 2021

    • 1 Bluetooth LE introduction
    • 2 Create Android APP
    • 4 To Make the BLE Drum work

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 PSoCRegistered 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,

image

with the project name of edrumer.example.com, I still keep two pages swap with finger.

image

3 Connection with PSoCRegistered 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"/>

 

image

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);

 

image

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,

image

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.

  • Sign in to reply
  • souadkarimahnajjar
    souadkarimahnajjar over 3 years ago

    BLE is supported by all smartphones, and the most prevalent consumer products that utilize it are wearable health gadgets such as FitBits, heart rate monitors, and so on. However, because of the simplicity of BLE, it is simple to connect to and communicate with BLE devices using an Android phone. In the future, we will need to contact an Android application development developer for a feature.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • asokfair
    asokfair over 3 years ago

    Checkout this Drum https://www.youtube.com/watch?v=N8adHGG5dOs

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube