Example Code

LabVIEW/Android comm via bluetooth (serial) using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
A simple example how to send strings to an Android phone from LabView via bluetooth. A serial COM port is needed to be assigned to the bluetooth adapter (incoming COM port).


Description
In some cases WIFI is not an option, so we cannot use the nice features of NI Data Dashboard, etc. This was the case for our lab: wifi is restricted, but bluetooth is OK to use. Therefore I tried to find a solution to receive data from my LabView application to my Android device. I have found a nice tutorial how to program bluetooth in MIT App Inventor 2 (http://ai2.appinventor.mit.edu) here: http://puravidaapps.com/btchat.php . It gave a good starting point how to develope such an application for Android.

I share here a simple bluetooth application for Android devices (tested on Nexus7 and Motorola MotoX) to be able to receive data sent from LabView using serial VISA. The Android client's clock is set to 250 msec (see aia source file), so do not send data from LV faster than 500-1000 msec. I did not have time to experiment with bandwidth (baud rate, etc), to try faster data transfer.

This example can be extanded to have Android-to-LabView communication too, it requires to program bluetooth send feature in the Android app, and VISA Read part in the LabView side (it works, tested).


Requirements

Software:

LabVIEW 2012(or compatible)

 

Steps to Implement or Execute Code

  1. See the list in the snippet.

 

Additional Information or References
VI Block Diagram

1.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Blokk
Trusted Enthusiast
Trusted Enthusiast
on

my mistake, the shift register was actually not a FGV

I have replaced the zip including the corrected subVI AE.

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

by the way: someone with good AppInventor skills could program a chart/graph feature...like checking min/max values, and dynamically rescaling the graph... Here is one tutorial, recently i have no time to make this feature...

https://groups.google.com/forum/#!msg/app-inventor-developers-library/BlM-lU2rsDE/xsLDYPiw1MUJ

BTS_TPIL
Member
Member
on

Hi,

That kind of project would interest some of our students (french university). But we've labview 10 so : i cant' open your vi, and i don't have the functions "init_com.vi" "send_data.vi" or "close_com.vi" as represented in the diagram.

How can i  find them ?

Thanks.

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

Hello,

Of course  you do not find these subVIs, since I made them, they are not part of the built in LabView VIs. But they encapsulate very simple VISA serial functions. Now i have only a mobile with me, but you can quickly upload the zip project to the version conversion forum, and someone will be nice and downconvert it for young: http://forums.ni.com/t5/Version-Conversion/bd-p/VersionConversion

Happy coding ! 🙂

davekorpi
Member
Member
on

I feel like a TOTAL BOZO but can you tell me how to do this step..

  1. Be sure the BT is turned on on both devices, and they are paired (no need to connect yet)

HOW DO YOU PAIR the two devices???

I select BlueTooth on the Droid and it just sayd PAIRING and to Pair with DK-PC Make sure it is showing this Pair Key: 987489

but there is nothing to enter.. I KNOW there must be a way to "WAKE UP" the pairing with the PC but alas I can not find it... If I find it I will post HOW to do this..

I am 3 millimeters away from getting it!

Blokk
Trusted Enthusiast
Trusted Enthusiast
on
davekorpi
Member
Member
on

OK... YOu PAIR it with the PC by WATCHING the popup in the lower notification bar, where your TIME shows up next to the WiFi signal strength indicator comes up.

Sheesh!

davekorpi
Member
Member
on

Thanks a million! I REALLY appreciate it!

You gotta LOVE this community!!

Vaneessa
Member
Member
on

Please could save the previous version labview 2011?

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

LV version 2011 added to the file list, see above. Unzip it and open the LV project file to see if it works for you. Test with the "MAIN_test.vi".

davekorpi
Member
Member
on

VERY VERY VERY Cool! So this example uses the Serial Port on the PC that has been "assigned" to the Bluetooth device. As such, the PC simply "talks" using the serial device and this is "translated" into the wireless bluetooth at a basich 9600,n,8,1 or whatever and the LabVIEW program "barfs out" the date and time and the Android Client displays this data with a CR/LF.

I wonder about ALSO having the Droid send something to the PC. With that the PC needs to know the address of the BT of the Droid and then make a connection and READ however many bytes are in there.

When I try this, by using another "server" I can not get the data back to the LabVIEW display..

Are you up to making an edit to the MIT Inventor and the LabVIEW program that demonstrates this??

I do not know why I can not get this silly thing! Once I get it going both ways I will get it and make a video for folks!

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

Have a look at the example at http://puravidaapps.com/btchat.php.

You can modify according to this example my MIT App Inventor 2 code so you can send ASCII strings from the mobile to the PC.

In the PC side LV code you only need to simply set up a VISA Read part where you read the incoming data. Sorry, but I do not have the time to make an example.

davekorpi
Member
Member
on

Will look at it and if I get it I will add my solution to this to help everyone out!

I want to MODEL with LabVIEW to design apps...

lolasue
Member
Member
on

I am a novice at Labview and I am trying to send ASCII data from a broadcom BLE device to Labview on my windows pc. I have read and examined many different types of bluetooth connection examples and have ended up very confused. Firstly do I need a wireless bus to link device to pc labview? Do I use the DAQ function and select for bluetooth within that or must I do some external programming? Any advice would be greatly appreciated.

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

Well, first you usually need to have a physical connection between the PC and the "BLE" device I think. It means, you need to pair them somehow. LabVIEW comes after this. I do not know anything about this "broadcom BLE device", so it is difficult to give specific answer.

I do not understand why you mention DAQ function here, it means data acquisiton. Here you want to send ASCII data via BT simply.

I would advice you to first search the LV discussion forum for similar topics, you might find there the good answer for your questions. If not, you can create a post in this forum (do not forget to specify your hardware components in details), so more people will see it, than here, so higher chance you get help:

http://forums.ni.com/t5/LabVIEW/bd-p/170

lolasue
Member
Member
on

Hi Blokk, thanks for your response. Why would i need a physcical connection?, isnt that what bluetooth connectivity is for, to avoid that?  Re DAQ, I thought I would first need a Bluetooth VI to make the pc-to-device connection and then I would need a DAQ VI to read the data from that connection?

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

Why would i need a physcical connection?, isnt that what bluetooth connectivity is for, to avoid that? 

I mean, you could first test whether you can connect your PC to this BT hardware, like BT pairing. This does not involve cable, i used the word "physical" in a wrong way.

Re DAQ, I thought I would first need a Bluetooth VI to make the pc-to-device connection and then I would need a DAQ VI to read the data from that connection?

DAQ = means data acquisition. You BT hardware will do data acquisition, and send the data via BT to your PC. So your PC side will not do any DAQ! Only establish a BT connection, and get the data in string format.

I ask you again, not doing here the discussion, but please post your detailed question in the proper forum, I gave you the address above. Do not forget to specify your hardware.

lolasue
Member
Member
on

thank you again.

georgesbou
Member
Member
on

hi blokk, im using a samsung (note 4) device and paired it with my toshiba laptop(Win 10) but i cannot connect using the application or any other bluetooth application(error 507)while both bluetooth are on and paired and the corret COM port is written. any help?thanks

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

Sorry, I have no idea why your devices do not work. You wrote the BT connection does not work either using any other application. It can be a faulty device, or some software problem either in Android or in Win10. Try to find help in a Windows related forum, or take your devices for service/replacement. Did you try to use another Android tablet or phone to connect to Windows? If they work it means a problem with your Samsung note. Did you try to use your Samsung Note with another laptop? If they work, the problem is in your laptop...

svq
Member
Member
on

Can I use antroid make an atroid app which will act as frontpanel executable just like VI front panel?

Pls somebody help.

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

In principle you could do something similar, using some form of communication via wifi or BT. You can do lots of things using LabVIEW Web services ( https://decibel.ni.com/content/groups/web-services ), and then in principle all you need is a browser.

But your question has not too much to do with this particular community document

Are you aware there is the so called NI product called Data Dashboard? It can do very easily what you want. Note that, the functionality of Data Dashboard for android smart phones are limited and there are some bugs. But for Android tablets, this product works very nice.

Here some links:

http://www.ni.com/tutorial/13757/en/

https://play.google.com/store/apps/details?id=com.ni.labview.SharedVariableViewer&hl=en

https://www.ni.com/mobile/

mohmdth120
Member
Member
on

hi

i have prplem wit send  world from labview to hc-05 (bluetooth with arduino

can you help me and this code can work with this state

thanks

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

You should really post your question in the appropriate discussion forum. I never worked with Arduino.

Here you can find the forum: http://forums.ni.com/t5/LabVIEW/bd-p/170

Advice: try to properly explain your problem not as above (hardware components you use, etc.). You should also attach your VI to your post (not a screenshot, but the VI itself), you will get help faster.

Good luck!

cartert
Member
Member
on

Hello Blokk,

Could you speak more to the last line in your description about how to convert this code to an android-to-labview communication tool?

Thanks

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

It is quite simple, but right now i do not have time to put together an example. At LabVIEW side you need a VISA Read function, and at the Android side you need to program the text sending function (in my example there is only the text receiving functionality programmed). The example Android code can give you starting point if you have a look at this link: http://puravidaapps.com/btchat.php

MonkTronix
Member
Member
on

Hey,

Could you please help me with a step you mentioned:

  1. Assign a serial COM port to your Bluetooth adapter (BT settings in Windows)

I opened BT setting where I find COM port but I don't know how to apply COM port and to which BT adapter my own laptop's one or the phone. Coz when I tried to add a COM it as server it does not show any of them.

 

Thanks in advance

Nipun1234
Member
Member
on

Sir please send me all the details about

interfacing HC-05 with LabVIEW & myrio using

MIT APP inventor at nipunjain005@gmail.com

Blokk
Trusted Enthusiast
Trusted Enthusiast
on

I realized the community provider killed some media from this page: (**This document has been updated to meet the current required format for the NI Code Exchange.**).

So I add the deleted part here to keep the page "in the required format" (just a screenshot of the Android side):

 

Screenshot_2014-10-10-22-31-59.png