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 Wearable Gesture Control - #6 BLE communication with an app
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: zst123
  • Date Created: 28 Oct 2021 1:32 AM Date Created
  • Views 1020 views
  • Likes 1 like
  • Comments 0 comments
Related
Recommended

Wearable Gesture Control - #6 BLE communication with an app

zst123
zst123
28 Oct 2021

Table of Contents

Wearable Gesture Control - #1 Introduction

Wearable Gesture Control - #2 Install & Setup Template Application

Wearable Gesture Control - #3 Integrating LCD & Accelerometer

Wearable Gesture Control - #4 Collecting data for Edge Impulse

Wearable Gesture Control - #5 Deploying Edge Impulse model & Fixing Makefile issues

Wearable Gesture Control - #6 BLE communication with an app

Wearable Gesture Control - #7 Low Power Profiling

 

See all my posts here

 

In this blog, I will be configuring the PCoC 6 kit to communicate with my Android phone over BLE.

Control Your Bluetooth Devices via Web Browsers with Beacon

Understanding BLE

 

If you would like to learn more in-depth on what BLE is about, this article by Adafruit is very comprehensive

  • https://learn.adafruit.com/introduction-to-bluetooth-low-energy

 

However, to keep things short, I will not cover the theory.

 

We will be simply changing the GATT settings in order to create Services and Characteristics today. Within the characteristic, we can set values. In our case, the value will be the gesture that we want to communicate over to the app.

What is Bluetooth Low Energy (BLE) and how does it work? - Centare Blog

There are many more settings which you can explore in ModusToolbox.

 

Adding Bluetooth characteristics

 

Under your Project Navigator, open up the configurator tool. Do this by double clicking the design.cybt file.

image

If you go to GATT settings, you will see that some settings have been done by the example template already.

There is a service called CapSense and it has Button and Slider characteristics under it.

image

 

I will add my own custom service and characteristic. Click on the Add symbol image on the top left and add the following.

  • Create new service : MyService
  • Create new characteristic under the service : Gesture

 

When you create the service, the UUIDs are auto-generated for you. I left it as it is, but you can choose to modify it as well.

image

In order to make the Gesture characteristic contain our gesture text, I enabled the following settings:

- Properties > Read & Notify : for the device to be able to receive notifications when the value has changed.

- Add image > Client Characteristic Configuration : required when you use notifications, the tool also prompts you to enable it if you forget

- Format > uint8[] > Length 20 : the gesture will be a string, so I chose it to be a byte array with a length of 20 (the length is an arbitrary choice)

 

As of now, we have the following services and characteristics:

 

CapSense (Service)

0003CAB5-0000-1000-8000-00805F9B0131

Button (Char)0003CAA3-0000-1000-8000-00805F9B0131
Slider (Char)0003CAA2-0000-1000-8000-00805F9B0131

 

MyService (Service)

EF603193-7EC1-4825-93DC-A3C43DD45F05

Gesture (Char)EF603194-7EC1-4825-93DC-A3C43DD45F05

 

Click on save, and the project code will be auto updated when we compile.

 

Modify code to talk to BLE

 

In the code, I created a new Queue in order to relay information (from the accelerometer task running the inference to the BLE task)

 

In this code snippet, I find the maximum value of classification which will be the detected gesture, I then send it over the queue to be handled by the BLE task.

image

 

Next, upon receiving item from the queue, the BLE task will send a notification to the BLE API to update the value with the gesture that we have detected.

image

 

See the detailed changes here:

  • https://github.com/zst123/Element14_Low-Power-IoT/commit/aa4766105c5577778a5bd76cd3654e66fa7581a6

 

Testing BLE communication device

 

On an Android phone, I installed the LightBlue app to debug the BLE communication

  • https://play.google.com/store/apps/details?id=com.punchthrough.lightblueexplorer

image

 

Connect to the device and confirm that our new service and characteristic shows up.

image  image

 

Click on the Gesture characteristic, and subscribe to the value notifications. Choose UTF-8 String as the format to see the text.

The detected gesture will update every second through BLE

image

 

Integrating with a Web app

 

I will be trying a new feature which is the Web Bluetooth API. I chose it because I wanted it to have the maximum compatibility with my laptop PC and also my Android phone.

This is how the app looks like, coded in standard HTML, CSS and JS.

If you are interested, I have also open-sourced it here: https://github.com/zst123/Element14_Low-Power-IoT/blob/master/mywebapp.html

imageimage

 

Upon clicking "Connect BLE", a list of devices will be shown and it can pair with the PSoC 6 device. Information such as gesture detection and CapSense slider is transmitted over BLE to the web app.

 

This is a demonstration video:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Conclusion

 

As you can see, the ModusToolbox configuration tool has made it very quick to get started. After setting up everything in the GUI, all the setup code is auto-generated for you. Therefore, only a few chucks of code are needed to create an application.

Coming to the end of the challenge, I will be wrapping up next week in the final blog. Thank you for following me through this project!

  • Sign in to reply
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