NI Home > Community > NI Discussion Forums
Reply
Member
Jazlan
Posts: 14
Accepted Solution

How to read Serial Data from Arduino using labview VISA?

Hi =). Im a beginner working reading serial data from an arduino but im facing... Lets do this step by step

 

I constructed a voltage divider circuit that gives an output ranging from 0 to 5V. The output of this circuit is sent to an analog input pin 0 of an Arduino Duemilanove board.

 

1) Firstly I plugged in the cable connecting my laptop USB to the arduino board.

 

2) I went to start->control panel->system->hardware->device manager. Check out Ports(COM & LPT). In my laptop I can see USB Serial Port (COM4). Now I know in Labview I have to read serial data from COM 4.

 

3) For the arduino side, here is the code to read voltage variations inputted to analog pin 0. The last line 'delay' determines the sampling rate of how we want to sample the voltage divider output:

 

int potPin = 0;    // select the input pin for the voltage divider output
int val = 0;       // variable to store the value coming from the sensor

void setup()
{
  Serial.begin(9600);    // opens serial port, sets data rate to 9600 bps
}

void loop() {
  val = analogRead(potPin); // read the value from the voltage divider
  Serial.println(val);
  delay(10);
}

 

I have slightly modified the basic serial read write VI.. I have attached the block diagram used with comments. Basically I tried to read serial data, divide by 1023 and multiply by 5 in order to graph voltage variations from the voltage divider circuit.  However Im not getting the correct voltage output values . The voltage value just keeps going to 0 and coming again as shown in the pic.

 

Could you guys please guide me on what went wrong?

 

Thanks!

 

Active Participant
ABCPrograms
Posts: 352

Re: How to read Serial Data from Arduino using labview VISA?

- you're reading data, even if there is no data on the port. if 0 bytes are read => ""

- in the false case, you have VISA resource wired to the string output tunnel?

- there is no close VISA resource at the end of the VI

- you're not looping this VI when reading bytes

 

I've added an addaption of your VI which you should give a try maybe :smileywink:

 

 

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's :smileywink:
LabVIEW 5.1 - LabVIEW 2012
Member
Jazlan
Posts: 14
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

Thanks ABCPrograms. Now I know what I did wrong

Active Participant
Omar_II
Posts: 421

Re: How to read Serial Data from Arduino using labview VISA?

The VISA ref did not pass through the loop so the close VISA might close the port before it read the bytes.

Omar
Active Participant
ABCPrograms
Posts: 352
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

TRUE Omar, thx for adding this.  BIG ERROR on my behalf.  I should hit myself for missing that :smileywink:

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's :smileywink:
LabVIEW 5.1 - LabVIEW 2012
Member
drog
Posts: 22
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

I had a similar project. My Arduino continuously sends room temperature readings as part of a text string and I wrote a VI to buffer the text, extract the temp digits, display the value and graph the data.

 

I've attached my VI for your reference.

 

Cheers!

Active Participant
ABCPrograms
Posts: 352
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

 


drog wrote:

I had a similar project. My Arduino continuously sends room temperature readings as part of a text string and I wrote a VI to buffer the text, extract the temp digits, display the value and graph the data.

 

I've attached my VI for your reference.

 

Cheers!


Is there a reason why you use "insert into array" in stead of build array (concatenate)???

 

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's :smileywink:
LabVIEW 5.1 - LabVIEW 2012
Member
drog
Posts: 22
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

No real reason. I probably should have used the Build Array function for consistency.

 

Anyone know if there is an advantage to using the "Build Array" vs. "Insert into Array" functions.

 

Cheers

Active Participant
ABCPrograms
Posts: 352
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

Insert into array is normally used to "insert" a value into a array at a certain place.  not at the end, allthough it does work.

Build array is used to add a value (or array) to an array.

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's :smileywink:
LabVIEW 5.1 - LabVIEW 2012
Member
BrHann
Posts: 1
0 Kudos

Re: How to read Serial Data from Arduino using labview VISA?

Hey, I am using LabVIEW v 8.6 and would like to view this VI but cannot open it... could you upload a copy saved as an 8.6 file? Thanks