LabVIEW and VISA interface, with chipKIT Digilent UNO32 and Basic I/O Shield

Introduction

NI LabVIEW can communicate with external devices such as microcontrollers through VISA a standard I/O language for instrumentation programming.

LabVIEW ties the creation of user interfaces (called Front Panels) into the development cycle. A key feature of LabVIEW over other development environments is the extensive support for accessing instrumentation hardware.

Objectives

Write step by step a simple serial read VI that can communicate with chipKIT Digilent UNO32 and Basic I/O shield, and serial read  values processed in UNO32 and display  these on LabVIEW’s front panel.

Requirements

MAP_3782-400x265– chipKIT Digilent UNO32 development board
MPIDE software
– Digilent BASIC I/O shield
LabVIEW software and VISA drivers

Your LabVIEW software and VISA and drivers as well as MPIDE software for programming chipKIT Digilent UNO32 baord must be installed in your PC. Check previous tutorial on this blog LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Procedure

a) Install libraries of Basic I/O Shield in MPIDE environment for UNO32 board

On Uno32 you must have Jumpers JP6 and JP8 set in the RG3 and RG2 positions. Install the Basic I/O shield on top of UNO32 as shown on the above image . Connect to the PC with USB cable. USB connection will power UNO32 and the Basic I/O shield simultaneously.

We assume that you have already installed MPIDE environment.

You will need to know the location of MPIDE sketches folder:

Run MPIDE  (in my PC with Windows XP Pro I need to do it with Administrator’s priviledges). In menu do File -> Preferences find the sketchbook location:

mpide1

Take note of the location of your sketches (MPIDE codes are called “sketches”). In your Windows navigate to where the folder is, and create a directory named ‘Libraries’.

mpide2

Download from here the zipped file containing libraries and documentation for using the Basic I/O Shield™ with the chipKIT MPIDE and unzip into the Libraries folder you have just created:

mpide3

Now if you do File -> Examples you will see three folders IOShieldEEPROM, IOShieldOled and IOShieldTemp. Open the sketch IOShieldTemp_Demo:

mpide4

Next choose the board (in our case UNO32):

mpide_board

And Serial Port to which the board is connected:

mpide_serial_port

To be sure of what you are doing, I advise that you read my previous tutorial here in this blog  LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Now we are ready to upload the sketch to the board. Click the Upload button on MPIDE environment.

If successful you will see the following results at bottom of MPIDE environment:

mpide_result

We are now ready to check what is being sent to our COM21 port (your PC’s may be other) in Tools -> Serial Monitor:

mpide5

A new window will pop up showing the readings sent to our PC’s serial port:

mpide6

We are  getting readings in ºC and ºF.

We will need now to modify our code in order to allow easy manipulations by LabVIEW communicating with micrcontroller through VISA.

Find //Print Temperature to serial port in IOShieldTemp_Demo sketch and substitute everyting up to delay(1000);  with the following code:

Serial.print(tempC);
Serial.print(",");
Serial.print(tempF);
Serial.print(",");
Serial.println("");

So the code with void loop will now look like as shown:

void loop()
{
float tempF, tempC;

//Get Temperature in Celsius.
tempC = IOShieldTemp.getTemp();

// Convert the result to Fahrenheit.
tempF = IOShieldTemp.convCtoF(tempC);

//Print Temperature to serial port
Serial.print(tempC);
Serial.print(",");
Serial.print(tempF);
Serial.print(",");
Serial.println("");
delay(1000);
}

We check again what is being sent by RS232 in Tools -> Serial Monitor:

mpide7

The readings now are in a convenient format for LabVIEW hopefully. Exit MPIDE environment in order to free the serial port.

b) Write VI in LabVIEW to read the values of temperature processed by UNO32

You need to have VISA and LabVIEW installed in your PC.  I advise you to read my previous post in this blog LabVIEW Interface for chipKIT Digilent UNO32 Development Board.

Launch LabVIEW (my licensed version is LabVIEW 2010). Search for basic serial write and read.vi

Image1

Download it from NI’s website:

Image2

And download it to a convenient directory, and run it by opening with LabVIEW.

abrir_vi_serial

Press Ctrl + E in your PC’s keyboard to get into Block Diagram of LabVIEW’s VI, and identify two Case Structures as shown:

acrescentar_loop

Add While Do structure around them:

Image5jpg

Next, delete the Write bytes to port loop and make adjustments to get the following result:

Image7jpg

We are now ready to run the VI and see what we get. View the Front Panel and choose the right port of communication which in our case is COM21 :

Image8

Once port is selected Run the V,I clicking on the button Run 

You will see immediately that some results are appearing on the Front Panel’s read string field. If you change bytes to read to 14 you will see immediately at least one line of readings:

leitura_vi

You may get some inconsistencies in reading but this will be sorted out next.

We will now go back to the Block Diagram and make changes to get the right readings for later manipulation.

We will add character termination ‘\n’ to our VISA configuration, selecting it first:

visa_mod6

And then with right button of your mouse create a constant on VISA serial:

visa_mod3

The constant assumed will be ‘\n’ i.e. line return which in decimal is number 10.

visa_mod7

Now we are ready to go back to Front Panel and Run the VI. The results will be not very consistent. Change bytes to read to 20 and bingo you will get a line of clear readings:

visa_mod5

You can play with Basic I/O shield to check if readings are coming from the sensor. Place a finger on the sensor, and temperature reading will approximate to those of your body temperature:

sensor

It is fair to ask that you need save the VI, perhaps with a new name such as basic_serial_read.vi

Create a Flat Sequence within the Case Structure as shown bringing the read string within it:

flat_sequence

Now right-click inside this loop and search palette ‘scan string’:

visa_mod17

And select ‘Scan From String’:

visa_mod18

And place it on Block Diagram as shown:

flat_sequence1

Now we will split the string to get both readings we are obtaining from UNO32 as shown:

visa_mod8

The constant ‘%[^,]’ will split the first reading wich we can then display:

visa_mod9

By now surely you know how to create Constant and Indicator (tip: point with mouse at the connection and right click your mouse and in the menu choose Create whatever you wanto to do).

We will now obtain the rest of string adding again the decimal string pallete and as shown we will need to add one more constant to let the second Scan palette know where the second part of the string is which will be after comma ‘,’ which in fact is the first character:

visa_mod10

So we add constant 1:

visa_mod11

Edit ‘output1’ to ‘Temp. ºC” and ‘output2’ to ‘Temp. ºF’.

Finally we will do only one last thing that will fix bytes to read to 20, so that we do not need to change this value on the Front Panel everytime we reinitiate our VI.

visa_mod12

We will delete bytes to read control and replace with constant with number 20 in it:

visa_mod13

Make sure the Front Panel looks a bit like the following image:

visa_mod14

Make sure you have save your VI. Now after setting the port, run the VI.  You will see results as shown:

visa_mod15

We are almost finished with our work. We will show a graphic display of centigrade temperature (there is more room for improvement but we will point these out when concluding).

In Front Panel place Thermometer’ found in Numeric Indicator set by right-clicking with mouse:

visa_mod16

Thermometer reads numbers and not strings. So in our Block Diagram we need to place ‘decimal string’ palette. Do a search for it:

decimal_string

Choose ‘Decimal String to Number’  and place it as shown next to Thermometer:

visa_mod19

Now if you go back to the Front Panel and Run the VI you will see the thermometer displaying the value read in centigrades:

visa_mod20

Now in Block Diagram we will first change the description ‘Visa rsource name’ to ‘Port Number’:

visa_mod21

And we will hide all other resources that are not needed on Front Panel, such as ‘baud rate’ etc., leaving out ‘Port Number’ that we may need to set:

visa_mod22

So the final Front Panel should look like the following image shows:

visa_mod23

Save the final work as IOShield_LV_Temp.vi.

Run VI and I think you should see something like the following image:

visa_mod24

On the Block Diagram you can click the Highlight Execution button

visa_mod26b

You can see in slow motion the running of VI.

You can download IOShield_LV_Temp.zip at free repository Bitbucket The zip file  contains the VI we have just written

You may watch a video on this project at Youtube:

Conclusions

My main aim was to demonstrate that one can combine two powerful tools at disposal of engineers and students: LabVIEW and chipKIT Digilent UNO32.

There is room for improvement with UI (user interface) and to turn this project into full PID control.  Also the LabVIEW VI can have more controls to cater for errors, and other situations such as Alarms.

I will appreciate any comments on the project, specially if there are any errors.

Advertisements

About Tayeb

Electronics engineer, part-time webmaster and owner of "Aliatron", a tech-oriented company registered in Portugal and Mozambique.
This entry was posted in Electronic Projects, Programming and tagged , , , , , , . Bookmark the permalink.

5 Responses to LabVIEW and VISA interface, with chipKIT Digilent UNO32 and Basic I/O Shield

  1. Pingback: Remote Viewing with NI LabVIEW, Digilent UNO32 and Basic I/O Shield | RedAcacia

  2. Meher HOUEIDI says:

    I have a project wich control the movement fo a person indoor a house, in which a would like to add a picture in my Labview user interface which contains the plan of the house in 2-D on the first job a person like a point which move from the cordinates stemming from Visa

  3. Haitham says:

    HI I appreciate your help and sharing your project, I have used this project to get distances by using three PmodMAXSONAR and its works good, but I need to write the readings to excel or csv file.

    Thanks

    • Tayeb says:

      Thank you for sharing. With LabVIEW you can write the readings to a csv file. Just Google it, you will find out how to do it. Once you have project working and published do share here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s