Saturday, June 9, 2012

Arduino + Labview


   This is a quick (REALLY quick) writeup on establishing a connection between a custom designed Arduino Board using Atmega8 and LabVIEW.  I used a very simple setup where Arduino would receive data  serially  from LabVIEW. To demonstrate this I have used an example of RGB-colour gradient. This employs a simple 2-way communication, the Arduino would listen for a comma separated values of red, green and blue at the beginning of each iteration. If a command is heard, it would react by first parsing these values and then changing the color of the RGB LED, depending on the combination of red, green and blue color received. If nothing was heard, then it would continue on through the read cycle. The method is inefficient and barbaric, but my intent was proof-in-concept.  The concept may be improved upon to increase reliability and efficiency.



Step 1:  Quick Arduino Sketch

    The first thing we need to do is write a sketch for the Arduino, to prepare it for taking values from the serial port and parse it to ensure correct intensities are set for red, green and blue pins of the RGB led.. This is accomplished with a simple sketch that accepts comma separated values of red, green and blue and constantly transmits a message over the Serial comm. 




Step 2:  Let's do the Labview VI

    The trick in this step is more about the right serial data than anything else.  Below is a snapshot of the VI I threw together to connect to the Arduino.


























The Labview Vi creates a comma separated values of the colors and sends it to Arduino, which simply parses that string and does it's job. With that all wired together, save it as a VI named Arduino or something along those lines. Hypothetically you could set the baud rate as a constant 9600, but I left it changeable in case I feel crazy one day and want to spice up that rate a bit.

As a side note, the VI is a handy thing to be able to build, and when you establish a successful connection with the Arduino with reliable data flow and communication, I recommend wrapping the whole thing up as a VI so all you need to do is set the Baud Rate and Resource Name on input nodes and the output node will flow the raw data for you to do with whatever you want.

Step 3:  Now Look at the front-end to see if everything is perfect





Step 4:  Plug in the Arduino and turn it on

Plug in the Arduino and turn it on. Go to the Front Panel and select the appropriate VI resource name (which is hidden under the settings panel on my front panel) and flip the “On” switch.  If all goes well, on modifying the R, G and B values in the front-end above, the RGB Led would change color to the color shown in the front end. 

From here it is just a matter of using your new found connectivity to do something revolutionary.  Feel free to leave me any questions you might have.
You can get the code here

6 comments:

  1. nice post on integrating the powerful Labview and Arduino.

    ReplyDelete
  2. Actually there's more coming up, keep watching this space.

    ReplyDelete
  3. Thanks for posting this up, this is exactly what I'm looking for!

    I'm new to Arduino and want to communicate my Arduino Uno with Labview 2011.

    I've followed all the instructions here --> https://decibel.ni.com/content/docs/DOC-15971 but to no avail.

    I couldn't find the LVIFA_Base pde file to be uploaded to Arduino 1.0.1

    Any help would be much appreciated. Sorry for the noob question.

    ReplyDelete
    Replies
    1. Hi,
      Labview interface for Arduino has very limited functionality. This is a very basic project to do serial communication between labview and any other device using VISA. I suggest you use Visa to connect your arduino with labview. Compile and download the .pde file and also the Labview file is there which can be used as-is given with this link.
      http://sdrv.ms/NHGRi4



      http://sdrv.ms/NHGRi4

      Delete
    2. Note: We have shifted our blog to http://teamembedded4u.wordpress.com/

      Delete
  4. Hello, the color will still be able to change color even though i didn' t plug in my arduino. why is it so?

    ReplyDelete