This document provides a brief introduction to the use of MATLAB® functions to enumerate, connect and control a Muse v3 device over Bluetooth Low Energy (BLE). BLE is a wireless communication protocol that uses Bluetooth with low-power peripheral devices. It is worth noting that BLE communication support is different from the Bluetooth Communication interface in MATLAB®, which uses the Bluetooth Serial Port Profile (SPP).
All the examples are based on MATLAB® official documentation, available at the following link:
To connect to peripheral devices that support BLE, your computer needs to have a built-in or external Bluetooth 4.0 adapter. After you connect to a device, use MATLAB to read from or write data to it. You can work with both standard and custom services, characteristics, and descriptors.
2.1 Device Enumeration
blelist function allows you to scan for nearby Bluetooth Low Energy peripheral devices and look at the device advertisement data.
The available devices are listed in a table as in Figure 1, which includes a set of relevant fields such as: name, address, the RSSI value indicating signal strength and a struct with the advertisement data. In its simplest operating mode, there are no input parameters and/or filters.
2.2 Device Connection
ble(name) function allows to connect to a selected BLE device. It returns a BLE object that represents the connection to a BLE peripheral device from your computer.
It is also possible to connect to a peripheral device using its address as an alternative to using the device name as input parameter. If the connection successfully complete, the function returns a BLE object that includes a set of properties related to the device as well as access to services and characteristics descriptors.
If read or write are supported in the object Attributes property, you can read characteristic values using read or you can write characteristic values using write. If the characteristic has any descriptors, you can also access them using descriptor.
read(c) function allows to read the characteristic value from BLE peripheral device. The data read depends on the Attributes property of the input characteristic object c.
If the characteristic supports “Notify” it is also possible to create a callback function that accesses the characteristic content on your peripheral device. In the follow, a generic example of callback function:
function displayCharacteristicData(src,evt) [data,timestamp] = read(src,'oldest'); disp(data); disp(timestamp); end
subscribe(c) subscribes to a characteristic notification or indication of a BLE peripheral device. Notification or indication depends on the Attributes property of the characteristic c. The property must contain Notify, Indicate, or both. If the property contains both Notify and Indicate, the function subscribes to notification.
After you finish working with the characteristic, disable notifications using unsubscribe(c).