Troubleshooting Bluetooth Communication
The MATLAB® Bluetooth® interface allows you to connect to devices over Bluetooth and to transmit and receive ASCII and binary data. MATLAB supports the Bluetooth Serial Port Profile (SPP). You can identify any SPP Bluetooth device and establish a two-way connection with that device.
Issue
If you are having trouble discovering your Bluetooth devices, connecting to them, or communicating with them, try these troubleshooting tips.
Possible Solutions
Check Supported Platforms
The Bluetooth interface is supported on these platforms:
macOS 10.14 Mojave or later
Windows® 10
Configure Adapter
To connect to Bluetooth devices 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. For more information about discovering and pairing your device, see Configure Bluetooth Communication Settings.
If a Bluetooth adapter is removed and a different one plugged in, all Bluetooth devices have to be paired again with your computer. If the same adapter is removed and plugged back in, then you do not need to pair the devices again.
If MATLAB does not detect your built-in or external adapter, restart Bluetooth services on your computer and update to the latest device drivers for your adapter. Then, restart your computer.
Check Device Status
Make sure that the Bluetooth device is turned on and that the Bluetooth service on the device is turned on. Bring the device within range of your computer.
View the status of your device in MATLAB by using the bluetoothlist
function. You can connect to a device using bluetooth
only if its
status is "Ready to connect"
. Possible status values follow.
Value | Description |
---|---|
"Ready to connect" | Device supports SPP, is paired, and is not connected anywhere. |
"Requires pairing" | Device supports SPP and is not paired. |
"Connected" | Device supports SPP and is connected. |
"Unsupported" | Device does not support SPP. |
"Unknown" | Unknown if device supports SPP. Device is turned off or fails to respond to scanning request. |
If your device status is "Unsupported"
, it does not support SPP.
You cannot connect to it from MATLAB.
If your device status is "Unknown"
, it fails to respond to a
scanning request. Make sure that it is within range, turned on, and not already connected
outside MATLAB.
If your device does not appear in the bluetoothlist
output, make
sure that it is not connected to any other devices or applications. You can also try a
larger value for the Timeout
parameter in
bluetoothlist
. Using a larger value increases the amount of time
MATLAB scans for nearby devices.
For more information about connecting to your device, see Configure Bluetooth Communication Settings.
Check Device Connection
Make sure you can connect to the device by creating a bluetooth
object. You must provide two arguments to create the object, either the device name or
address and a channel number. The specified channel number must match the channel number
from the bluetoothlist
output. For more information about creating a
bluetooth
object, see bluetooth
.
After you connect to the device, you can communicate with it. For more information about communicating with your device, see Transmit Data Using Bluetooth Communication.
Device Out of Range
If you create a bluetooth
object for a Bluetooth device and the device goes out of range, the object still exists in the
MATLAB workspace. However, when the device comes into range again, you must clear
the object and create it again for communication to continue.
Make Sure Device Is Powered On
If you create a bluetooth
object for a Bluetooth device and the device is turned off or runs out of charge, the object still
exists in the MATLAB workspace. However, if you recharge and turn on the device again, you must
clear the object and create it again for communication to continue.