Serial Interface over Bluetooth and Matlab

Bluetooth, USB, UART, Storage, etc.
jollo
Posts: 5
Joined: Thu Mar 12, 2015 2:17 pm

Serial Interface over Bluetooth and Matlab

Postby jollo » Thu Mar 12, 2015 9:42 pm

Hi Guys

I received my BITalino device this week and everything works fine using the Open Signals software and bluetooth.
But for my project I need to be able to communicate with it in realtime in parallel with other measurements and controls of other devices. The communication of these other devices were implemented in Simulink.

So I am looking into the serial communication. I am on a win8.1 laptop and I can see the COM Port (COM5). I can open it via Matlab (serial() with baudrate 115200), but I do not seem to be able to send anything. Every write ends up in time out.

I read the code in the python and the c++ sources, but I do not see anything.

So can someone point to me what I am missing?

Thanks
jollo

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Serial Interface over Bluetooth and Matlab

Postby BITalino » Thu Mar 12, 2015 10:02 pm

Hi Jollo,

Have you double checked to make sure that what you're trying to send is compliant with the command set of BITalino?
http://bitalino.com/datasheets/MCU_Block_Datasheet.pdf

The baud rate is the right one, but your serial port settings may be configured to use flow control by default... try to use no flow control.

Another useful test to try and sort out the problem is to try to send the commands using Hyperterminal or another direct serial access software.

If you continue to experience any issues just let us know and we'll try to help to the best of our abilities.

Best regards,
The BITalino Team

jollo
Posts: 5
Joined: Thu Mar 12, 2015 2:17 pm

Re: Serial Interface over Bluetooth and Matlab

Postby jollo » Fri Mar 13, 2015 7:43 am

Thanks, this got me further, though not very far.

It seems I get two COM ports (why?), both with bitalino in their names as can bee seen in the attached picture:

Image

I downloaded HTerm and first tried COM5, which did not work. Then I tried COM4, which worked. Okay, but I tried COM4 before in Matlab and Matlab throws an error when using fopen on this port. I tried it anyway with HTerm disconnected.:

Code: Select all

port = 'com4';
s = serial(port,'BaudRate',115200,'FlowControl','none');
fopen(s);

Answer by Matlab:
Error using serial/fopen (line 72)
Open failed: Port: COM4 is not available. Available ports: COM3, COM5.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.


Back to HTerm, COM4 still works.
So, something's up with Matlab, I think.

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Serial Interface over Bluetooth and Matlab

Postby BITalino » Sat Mar 14, 2015 10:14 am

Hi Jollo,

Small steps are steps as well ;)

Mounting two ports COM is the standard way Windows uses to address serial communication... you can see additional details here:
http://windows.microsoft.com/en-us/windows/choose-com-port-bluetooth#1TC=windows-7

Regarding the communication with BITalino it should indeed be made via COM4, but apparently Matlab is not detecting that port.

Not sure if you've done so already, but perhaps the links bellow provide some information on how to add the outgoing COM to Matlab:
http://www.mathworks.com/matlabcentral/answers/29909-matlab-doesn-t-see-necessary-com-port
http://www.mathworks.com/help/matlab/ref/instrfind.html

Do keep us posted on your progress.

Best regards,
The BITalino Team

jollo
Posts: 5
Joined: Thu Mar 12, 2015 2:17 pm

Re: Serial Interface over Bluetooth and Matlab

Postby jollo » Tue Mar 17, 2015 9:50 am

Another little bit of progress:

I tried connecting the BITalino with Matlab on a Mac and it works fine. So it's something with Matlab and Windows. Does not help a lot in my case, but I thought it could be of interest to other people.

Specifically with Matlab on Windows: I found out, that Matlab can see the COM4 port under certain circumstances. When Matlab is running, shut off Bluetooth and BITalino. Then switch on Bluetooth and after that switch on the BITalino. Then run

Code: Select all

getAvailableComPort()
, which is a function from Matlab Central. Then it shows COM3, COM4, COM5. Interestingly, when repeating

Code: Select all

getAvailableComPort()
right afterwards, it again shows only COM3, COM5.

But when I do the same procedure but instead of

Code: Select all

getAvailableComPort()
enter the following:

Code: Select all

s = serial('COM4','BAUD',115200);
fopen(s)

Error using serial/fopen (line 72)
Open failed: Cannot connect to the COM4 port. Possible reasons are another
application is connected to the port or the port does not exist.


So, there is still an error, but a different one. Now when repeating

Code: Select all

fopen(s)
I get the old error:
Error using serial/fopen (line 72)
Open failed: Port: COM4 is not available. Available ports: COM3, COM5.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.


Veeery mysterious.

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Serial Interface over Bluetooth and Matlab

Postby BITalino » Tue Mar 17, 2015 11:14 pm

:shock: thanks for sharing.

We've seen your post on the MathWorks blog... hopefully they can provide some additional insight.

Best regards,
The BITalino Team

jollo
Posts: 5
Joined: Thu Mar 12, 2015 2:17 pm

Re: Serial Interface over Bluetooth and Matlab

Postby jollo » Fri Mar 20, 2015 12:24 pm

I give up using the Bluetooth interface.

I looked into using a USB connection, but it seems I need to order some additional parts. But I do not quite get what and http://forum.bitalino.com/viewtopic.php?f=8&t=11 does not help me much further.

Can you point me to a specific product?

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Serial Interface over Bluetooth and Matlab

Postby BITalino » Sat Mar 21, 2015 11:05 pm

Hi there,

Sorry to hear that you've been forced to give up on the Bluetooth connectivity option :?

Any standard UART to USB adapter will work with your BITalino (e.g. an FTDI breakout)... bear in mind that you should snap off the Bluetooth module and also the PWR block (given that these interfaces usually also provide power to your system).

You can see a short tutorial on how to connect it here: http://youtu.be/GvwMtHKWxgI

While using a UART to USB adapter, if you have a sensor such as the ECG / EMG / EDA connected to you, the signal quality may be degraded.

Also, in the unlikely event of a high-voltage power surge (e.g. due to a lightning strike) capable of blasting through the protections on your electrical box, power outlet, or computer, it may lead to injury.

As such, for improved signal quality and also for safety reasons, we recommend that you use a USB isolator together with your UART to USB adapter: http://www.bb-elec.com/Products/USB-Connectivity/USB-Isolators/USB-Isolators.aspx

Best regards,
The BITalino Team


Return to “I/O”




cron