LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read Serial Data from Arduino using labview VISA?

Solved!
Go to solution

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!

 

Download All
Message 1 of 143
(120,322 Views)
Solution
Accepted by topic author Jazlan

- 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 😉

 

 

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 2 of 143
(120,284 Views)

Thanks ABCPrograms. Now I know what I did wrong

0 Kudos
Message 3 of 143
(120,278 Views)

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

Omar
Message 4 of 143
(120,265 Views)

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

Kind regards,

- Bjorn -

Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's 😉
LabVIEW 5.1 - LabVIEW 2012
Message 5 of 143
(120,262 Views)

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!

Message 6 of 143
(120,247 Views)

 


@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 😉
LabVIEW 5.1 - LabVIEW 2012
Message 7 of 143
(120,244 Views)

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

0 Kudos
Message 8 of 143
(120,237 Views)

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 😉
LabVIEW 5.1 - LabVIEW 2012
0 Kudos
Message 9 of 143
(120,217 Views)

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

0 Kudos
Message 10 of 143
(120,100 Views)