How to connect matlab with Bluetooth HC 05. Learn more about bluetooth, simulink, microcontroller, serial, connect.
Steps to Resolve the Error
Specify Board Type and Port. If you see the error
Cannot detect Arduino hardware.Make sure original Arduino hardware is properly plugged in. Otherwise,please specify both port and board type
, specify the boardand type as shown here,Specify Board Type and Port Correctly. If you see the error
Cannot program board Uno (COM4).Please make sure the board is supported and the port and board typeare correct
with both board type and port specified:- Make sure that you specify the correct board type.
- Make sure the board type is supported. Seethe full list.
- Make sure you are using an FTDI converter to connectthe board to computer, if you are using the old ATmega328p board.
- Make sure that you specify the correct port. See the Find Arduino Port on Windows, Mac, and Linux formore information.
- Open Arduino® IDE (any version supports the board).Make sure you can program the same board under the same port successfully.
If you are using official Arduino boards such as Uno, Mega,Due, Micro and Leonardo, MATLAB® can autodetect the port connectedto the hardware on Windows®. However, some Arduino devicesare not automatically recognized, especially those that require externalFTDI adaptors. In those cases, specify both the port and board typeto create a connection.
Remove Bluetooth Device. If you want the Arduino hardware to communicate with thehost computer via a USB cable, remove any Bluetooth® devices connectedto your Arduino hardware, and then call the
arduino
functionwith appropriate parameters to create your Arduino object.Install Device Driver. If you cannot connect to official Arduino hardware, you may be missing the device driver. See Install Hardware Driver to update the hardware driver.
Manual Disconnect. If you manually disconnect the board before clearing the
arduino
objectfrom the MATLAB workspace, MATLAB will not recognize the Arduino serialport if you reconnect. Restart MATLAB, and try reconnecting theboard.Turn On the Trace Log. If you have checked for Manual Disconnect and the issue still persists, turn on thetrace log by executing the following command in MATLAB.
The trace log gives a much more detailed output of the compilationand upload results. There are some common possible causes of the error.Depending on what you see in your trace log, try the one that applies.
- If you see either of these errors in the log, trythe appropriate action for your release. For R2015a update the supportpackage to the latest version, or uninstall WINAVR. For R2014a andR2014b, followthese workarounds.
- If you see the following error in the log, reinstallthe support package. If error still exists, report the bug to MathWorks® technicalsupport.
- If you see the following error in the log, removeor rename the user-installed Firmata folder that is conflicting withthe shipping Firmata library the support package downloads,Look for the location of the Firmata folder to change in theerror log. For example, this error above indicates that the Firmatafolder to change is
'C:UsersMaxDocumentsArduinolibrariesFirmata'
.Remove or rename this Firmata folder. Then callarduino
in MATLAB again.If you still have the same issues, after trying these steps, contact MathWorks Technical Support.
Discovering Your Device
Instrument Control Toolbox™ can communicate with Bluetooth® devicesvia an adaptor. In this example, a USB Bluetooth adaptor is pluggedinto the computer. It can identify Bluetooth devices within rangewhen queried. In order to communicate with instruments, you need toperform a pairing in the adaptor software. Note that some devices,such as many laptop computers, do not need to use an adaptor sincethey have one built in.
The following shows the software interface of an adaptor wheretwo of the devices in range have been paired – a smart phonewith Bluetooth enabled, and a Lego Mindstorm NXT robot. As youcan see, the “friendly name” or display name of thesmart phone is simply
iPhone
and the name of theNXT robot is C3PO
. In the Instrument Control Toolbox thisfriendly name is the Bluetooth RemoteName
property.To see the devices in the Instrument Control Toolbox, usethe
instrhwinfo
function on the Bluetooth interface,called Bluetooth
.instrhwinfo
returned a cell array of five Bluetooth devicesthat are in the range of the adaptor on the computer running Instrument Control Toolbox.Then indexing into the RemoteNames
property showsthe five devices. You can see that iPhone
and C3PO
areshown in the list.Notice that one of the other devices shows an empty charactervector for
RemoteName
. That means that device doesnot have a friendly name associated with it. To communicate with thatdevice, you need to use the RemoteID
property.The
RemoteIDs
are shown in the same orderas the RemoteNames
, so the fourth ID in the list, '0021BA74F3DD'
,could be used for the device that shows no RemoteName
.You can use either RemoteName
or RemoteID
tocommunicate with a device.Examples of communicating with a device are in Transmitting Data Over the Bluetooth Interface.