Main Content

Bluetooth

(To be removed) Create Bluetooth object

Bluetooth will be removed in a future release. Use bluetooth (case-sensitive) instead. For more information on updating your code, see Compatibility Considerations.

Description

example

B = Bluetooth(RemoteName,Channel) creates a Bluetooth® object associated with the RemoteName and Channel. RemoteName is a friendly way to identify the RemoteID. If not specified, the default channel is 0.

The Instrument Control Toolbox™ Bluetooth interface lets you connect to devices over the Bluetooth interface, and to transmit and receive ASCII and binary data. Instrument Control Toolbox supports the Bluetooth Serial Port Profile (SPP). You can identify any SPP Bluetooth device and establish a two-way connection with that device.

B = Bluetooth(RemoteID,Channel) creates a Bluetooth object directly from the RemoteID and Channel.

To connect with the Bluetooth device, use the fopen function. When the Bluetooth object is created, its status property is closed. When the object is connected to the remote device with the fopen function, the status property is set to open.

B = Bluetooth(___,Name,Value) creates a Bluetooth object using the specified property values. If an invalid property name or property value is specified the object is not created.

Examples

collapse all

This example shows how to identify and connect to a Bluetooth device, send a message, and read data.

Find available Bluetooth devices.

 instrhwinfo('Bluetooth')

Create a Bluetooth object called b using channel 3 of a Lego Mindstorm robot with a RemoteName of NXT.

b = Bluetooth('NXT',3);

Connect to the remote device.

fopen(b)

Send a message to the remote device.

fwrite(b,uint8([2,0,1,155]));

Read data from the remote device.

name = fread(b,35);

Disconnect the device.

 fclose(b);

Clean up by deleting and clearing the object.

 delete(b)
 clear b

Input Arguments

collapse all

"Friendly name" for the Bluetooth device, specified as a character vector or string. For example, in the case of an iPhone, it might be simply 'iPhone' or a name like 'Zor'. If it is empty, use the RemoteID to communicate with the device.

Example: 'NXT'

Data Types: char | string

Internal ID of the Bluetooth device, equivalent to the Device ID, specified as a character vector or string. Every device has a device ID, which is usually a 12-digit character vector that starts with 'btspp://'. You can use this or the RemoteName to communicate with the device.

Example: 'btspp://0016530FD65F'

Data Types: char | string

Device channel, specified as a numeric value, if the device has channels. If no channel is specified, it defaults to 0.

Example: 3

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Timeout',60

Name of interface object, specified as a character vector or string.

Example: 'BTdev1'

Data Types: char | string

Time limit in seconds for communication, specified as a numeric value.

Example: 60

Data Types: double

Output Arguments

collapse all

Bluetooth device interface, returned as an interface object.

Version History

Introduced in R2011b

expand all

R2022a: Warns

Bluetooth will be removed in a future release. Use bluetooth (case-sensitive) instead.

This example shows how to connect to a Bluetooth device using the recommended functionality.

FunctionalityUse This Instead
b = Bluetooth("NXT",3);
fopen(b)
b = bluetooth("NXT",3);

The recommended interface has additional capabilities and improved performance. See Transition Your Code to bluetooth Interface for more information about using the recommended functionality.

See Also

Functions