II.3.8. Adding Bluetooth Interface

Blackstomp core provide a very simple BLE (Bluetooth Low Energy) terminal interface for the easiest implementation. All you need to is just enabling the BLE terminal by calling enableBleTerminal() inside Arduino’s setup() and write the BLE terminal handler for the effectModule descendant class. Here is the example sketch code:

You can see in the sketch code, the method enableBleTerminal() (at line #105) is called right after blackstompSetup() inside the Arduino’s setup function. The BLE terminal’s handler function onBleTerminalRequest() is defined in line #14, and implemented in line #83.

Customizing Some BLE Terminal Setup

The above sketch will run a pedal with BLE terminal enabled with some default setups:

  • Device name: same name with the pedal name property but appended with unique device ID.
  • Service UUID: “d11747ac-6172-4bb1-9b3a-20d58cc88f20”
  • Characteristic UUID: “7a9fd763-04a5-4a17-b625-1fce28329f23”
  • Pass Key: 123456;

It should be fine to leave the default setup untouched, but you can customize the service UUID, characteristic UUID, and the pass-key by manually set them up anywhere inside the init() function. Just copy and paste the following codes, paste into the init() function implementation, and edit their values with your own:

Writing The BLE Terminal Handler

The BLE terminal handler function (line #83) is supplied with two parameters: (const char* request) and (char* response). You can read the request string pointed by request pointer, an do any action based on what we read. After that, we can send any text response to the connected BLE device by writing the response text to the memory pointed by response pointer (line #85).

Each time a connected Bluetooth device write the characteristic’s value, the system will call the handler function with the characteristic’s value as the request parameter. After the handler returns, the system will detect if the response memory content has changed, and if yes then the characteristic’s value will be update with the response text, and the connected Bluetooth device will be notified.

Developing BLE Client Device

In Bluetooth Low Energy (BLE) terms, Blackstomp sketch that enable the BLE terminal is a BLE server, that wait for incoming connection from the client. After getting connected, server will read the request and send the response. Here are what should be done when designing BLE client for Blackstomp BLE terminal:

  • Scan the available BLE device with specific service and characteristic filter (either the default or custom characteristic and service uuids), so you’ll get the list of supported device.
  • With list of supported device on scan, connect to the right BLE device name, and open the characteristic with read, write, and notification.
  • To send a request, write the characteristic with the request string up to 517 bytes, always end the string with a carriage return (‘\n’ character), and make sure there no “carriage return” character before the end of your request string.
  • Please keep in mind that shorter string would be faster to transfer, so keep your custom request-response protocol as short as possible for the best responsive link. Try to shorten the request string if it fails or too slow.
  • After sending the request, wait a notification for that characteristic. After getting a notification, read the response by reading back the characteristic’s value.
Back to Table of ContentsBuy BSCORE Dev Pedal PCBBuy BSCORE ModuleBuy BSCORE Dev Pedal