element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
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
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
Author: fyaocn
Date Created: 5 Nov 2021 3:05 AM
Views: 311
Likes: 0
Comments: 2
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,

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

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"/>

 

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.

Anonymous
Parents
  • souadkarimahnajjar
    souadkarimahnajjar 5 months 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
    • Up 0 Down
    • Reply
    • More
    • Cancel
Comment
  • souadkarimahnajjar
    souadkarimahnajjar 5 months 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
    • Up 0 Down
    • Reply
    • More
    • Cancel
Children
No Data
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube