Serial Port & Bluetooth. Learn more about bluetooth, serial port. May 16, 2013 - 1) the user can select the COM port from the GUI that the Arduino is. 5) the Arduino 'RX' led blinks indicating the value from serial port has.
So I'm working in Unity3D, programming in C#, and I heard that one can read data from a Bluetooth adaptor via SerialPort. I have several Bluetooth USB adaptors that I've tried to connect on my PC using this method. However, when I try to open the SerialPort, I get an error message that says port does not exist. I only included the code relevant to the question, but portI is a string ('COM11' or 'COM12') and PortIn is of type SerialPort.
Rice_Crisp
Rice_CrispRice_Crisp
2 Answers
Here is some code I'm working on and it gets data from the bluetooth connection to a standalone pc build (or in the editor) as long as the COM port (in my case COM9) is the same as the bluetooth device when you pair it.
After you pair it go to Bluetooth Settings > COM Ports and see what port is there with the name of your device. It might say COM8 or COM9 or whatever. If the device is paired and the COM Port is the same in the code as it is in your Bluetooth Settings, AND the timeout number and baud rate are the same as in the application you are sending the data from... then you will get something from this code when you run it. This is just meant to help make a connection to the serial over bluetooth connection.
Hope it helps someone. I've gotten a lot of great advice from reading these forums ;)
KrisCodeKrisCode
It should be possible. The bluetooth rfcomm/spp services emulate a serial port. A COM port if it's on Windows. Baudrate doesn't matter in this emulation, it will always go as fast as possible.
You need to have the devices paired and connected though.To what device are you connecting? Try to make a connection first with Putty or some terminal application.
Eric SmekensEric Smekens
Not the answer you're looking for? Browse other questions tagged c#bluetoothserial-portunity3d or ask your own question.
I am sending accelerometer data via bluetooth into Matlab where I will process it and build a GUI.
I am currently working on getting the bluetooth data into Matlab. I'm using a dongle which gets data into port COM18. This is the code I'm using:
When I start from scratch (disconnect and connect bluetooth and dongle, reopen matlab etc) The port successfully opens and allows me to read data. However, if I close and then try to open, it will give me an error:
Error using serial/fopen (Line 72) Open failed: Port COM 18 is not available. Available ports: COM6, COM7, COM19. use INSTRFIND to determine if other instrument objects are connected to the requested device.
I know that my device isn't connected to anything else. So I then have to disconnect my bluetooth, dongle, and restart matlab.
Is there a more efficient way to do this?
Also, I am able to get values from my accelerometer into Matlab, but I don't know how to make them continuous. Each time 512 bytes are sent and if my ValuesReceived exceeds 12000, I once again have to restart my bluetooth device to get more values. I've tried flushoutput, but it hasn't worked. Any ideas on how to get continuous data into Matlab so I can process it in my GUI?
AzizelleAzizelle
1 Answer
I figured out the problem. In order to not get this error anymore I simply had to follow the sequence
and then when I do
I am no longer getting the error. It was just the order of operation to close the serial.
AzizelleAzizelle
Not the answer you're looking for? Browse other questions tagged matlabbluetoothaccelerometer or ask your own question.