Configure Bluetooth Communication Settings
Discover Your Device
To connect to a Bluetooth® device from MATLAB®, your computer needs to have a built-in or external Bluetooth adapter. The adapter identifies Bluetooth devices within range when queried. After identifying nearby devices in the Bluetooth settings on your computer, you need to pair your device with your computer first before connecting to it from MATLAB.
On Windows®, you can pair to a device in Settings > Devices > Add Bluetooth or other device. The following shows the Windows
Bluetooth settings where two of the devices in range have been paired—an audio device
E7 and a phone named
Pixel 3. These are the same
names you see in the
bluetoothlist to see a list of nearby Bluetooth devices and their connection statuses.
ans = 4×4 table Name Address Channel Status _______________________ ______________ _______ _____________ "E7" "FC58FA8156E8" 1 "Ready to connect" "Pixel 3" "3C286DD533CA" 8 "Ready to connect" "" "98D331FB3B77" Unknown "Unknown" "mjin-maci" "A886DDA44062" Unknown "Unknown"
bluetoothlist returns a table of four Bluetooth devices that are in the range of the adapter on the computer. You can see that
Pixel 3 are shown in the list and have the
"Ready to connect". You can connect to a Bluetooth device using
bluetooth only if its status is
"Ready to connect". For a complete list of possible statuses, see Status.
Connect to Your Device and View Properties
You can use
bluetooth to connect to a device with either the name or
address displayed in the output of
bluetoothlist. If a device shows an
empty string as its name, you must connect to it using its address. To successfully connect
to your device, you must specify the same channel that appears in the output of
bluetoothlist. If you do not specify the channel when you connect to a
device, MATLAB attempts to connect to the default channel 1.
This example looks at the Pixel 3 phone in the previous section. The
bluetoothlist output provides the information you need to create a
bluetooth object for this device. You must specify either the name or
address and the channel.
device = bluetooth("Pixel 3",8)
device = bluetooth with properties: Name: "Pixel 3" Address: "3C286DD533CA" Channel: 8 NumBytesAvailable: 0 NumBytesWritten: 0 Show all properties
properties to view a full list of properties and their values
Name: "Pixel 3" Address: "3C286DD533CA" Channel: 8 NumBytesAvailable: 0 NumBytesWritten: 0 ByteOrder: "little-endian" Timeout: 10 Terminator: "LF" BytesAvailableFcn:  BytesAvailableFcnCount: 64 BytesAvailableFcnMode: "off" ErrorOccurredFcn:  UserData: