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
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog Open Source EMDR Machine #5. Bluetooth/BLE Trouble
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ilvyanyatka
  • Date Created: 8 May 2021 6:21 PM Date Created
  • Views 1152 views
  • Likes 4 likes
  • Comments 2 comments
  • bluetooth
  • ble
  • health care
  • open source emdr machine
  • design for a cause - design challenge
  • medical
  • bluetooth low energy
  • arduino nano 33 iot
  • design_for_a_cause_2021
Related
Recommended

Open Source EMDR Machine #5. Bluetooth/BLE Trouble

ilvyanyatka
ilvyanyatka
8 May 2021

Open Source EMDR Machine. The Whole Blog.

 

    • Why I chose Bluetooth
    • Attempt #1
    • Attempt #2
    • Attempt #3
    • And another ArduinoBLE difficulty

 

To begin there is an explanation on how Bluetooth works. How does Bluetooth work?

 

 

 

Why I chose Bluetooth

 

I chose Bluetooth over WiFi or serial cables for 4 reasons:

1) Arduino Nano 33 IoT has a built-in BLE (Bluetooth Low Energy) module.

2) I want to minimize use of wires and give both users of the device (therapist and client) as much flexibility as possible.

3) It is faster and more secure than WiFi. Unlike WiFi I don’t have to hardcode the SSID and passkey in my Arduino code. The code doesn’t need to be changed if the device is moved to another place.

4) It can be used in rural places where there is no WiFi.

 

So I needed to find a cross platform Bluetooth package for VS.NET that works on both Windows and Android, and also a reliable Bluetooth library for Arduino.

 

For my project the best approach to control the EMDR device is to send a command with all the parameters and parse the whole command. This way I could get all parameters at once and set them all in the same loop() call. It is important because my command contains parameters depending on each other (for example, starting LED number and ending LED number)

Classic Bluetooth would be perfect for it, but not BLE. This is why I wanted to go with classic Bluetooth not BLE.

 

Software implementation of standard Bluetooth and Bluetooth Low Energy technology is very different. From a programming point of view the Bluetooth library has calls to find the needed Bluetooth device and writes in its stream whatever the developer wants. BLE is much more rigid. It introduces Services, and different types of Characteristics, all identified by guids. For a short description of BLE hierarchy see this image

image

For an explanation - this page Arduino Nano 33 Sense | BLE Battery Level Tutorial

 

As far as I know there is no way for them to understand each other.




Attempt #1

 

Initially I wanted to use 32feet.NET bluetooth library (GitHub InTheHand.Net.Bluetooth  )on the PC/Android side and some simple Bluetooth setup+library, like SoftwareSerial library Arduino's reference for the SoftwareSerial library on Arduino side.

However this setup only works with Arduino and a separate bluetooth module, like HC-05. Classic Bluetooth functionality is blocked on Arduino Nano IoT 33. It is not a hardware limitation because the module responsible for bluetooth is based on ESP32 processor, so it can support both. It is a software limitation.

I am not sure why it was done this way, but the decision to block it limits this microcontroller functionality. It is a flaw imho.

 

It is possible to get Bluetooth functionality by hacking - reprogramming Bluetooth module. Instructions can be found here: Can the NANO IOT 33 run Full Bluetooth (NOT BLE)? However it will be cheating for this project so I have to work with what is available.

 



Attempt #2

 

Then I tried to use 32feet.NET BLE library. InTheHand.BluetoothLE (GitHub InTheHand.BluetoothLE ) , it has the same set of objects as ArduinoBLE so they can definitely communicate with each other. However. It is in pre-release state and I could not even add the package to my VS correctly. Nuget installation didn’t show any errors but didn’t let me use any functionality from the package.

 

 

 

Attempt #3

 

On PC/Android side I am trying to use Xamarin BLE Plugin Github xabre/xamarin-bluetooth-le: Bluetooth LE plugin for Xamarin and ArduinoBLE on the Arduino side. And it is Cross Platform which is very important for me.

This plugin is marked as pre-release but it is working fine on Windows (UWP). I haven't tested the Android part of it yet, but the functionality definitely doesn't work with an Android emulator which you can run from Visual Studio to debug your Android code. And it will make the Android related part of the project more complicated than I expected.

 

 

 

And another ArduinoBLE difficulty

 

I assumed I can use BLEStringCharacteristic and pass my whole command into one characteristic. However I found a limitation on the Arduino side - the limit for MTU (Maximum Transmission Unit) is 23 bytes and there is no way to change it. This makes the maximum length of my command string only 20 bytes. It is not enough, my command string should be about 90 bytes. So I had to make several characteristics, for 4 groups of parameters. And to make each command string less descriptive but shorter. It is not the approach I wanted but I believe is is better than creating 12 different characteristics for each parameter. (And as I mentioned before, parameters are not independent)

 

This approach is working so far but I am not nearly done.

  • Sign in to reply

Top Comments

  • BigG
    BigG over 4 years ago +1
    It's best to avoid using BLEStringCharacteristic. Instead create a byte array - you use BLECharacteristic for this purpose where you define your array size etc. It's much more efficient. Check out my blog…
Parents
  • BigG
    BigG over 4 years ago

    It's best to avoid using BLEStringCharacteristic. Instead create a byte array - you use BLECharacteristic for this purpose where you define your array size etc. It's much more efficient.

     

    Check out my blog where I created a byte array to send all the Arduino Nana 33 BLE IMU data.

     

    Hatching a hockey stick hack in a hurry!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • BigG
    BigG over 4 years ago

    It's best to avoid using BLEStringCharacteristic. Instead create a byte array - you use BLECharacteristic for this purpose where you define your array size etc. It's much more efficient.

     

    Check out my blog where I created a byte array to send all the Arduino Nana 33 BLE IMU data.

     

    Hatching a hockey stick hack in a hurry!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • ilvyanyatka
    ilvyanyatka over 4 years ago in reply to BigG

    Thank you for the advice! It is very useful.

     

    I read your blog post and am going to ask you a couple of questions there.

     

    And wow, you work fast!

    • 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