LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Multiple analogue data using VISA in Arduino

I am trying to separate the Voltage and current value coming from serial port using VISA. But only first value is reading. What would be the error? This is my LabVIEW fileThis is my LabVIEW file

 

This is my Arduino code 



void setup() {
  Serial.begin(115200);

  
}



void loop() {

  float voltage = analogRead(A0);
  float current = analogRead(A1);
  Serial.print(voltage);
  Serial.print(",");
  Serial.println(current);
  delay(100);
  
}
0 Kudos
Message 1 of 11
(1,372 Views)

Hi Gappiya,

 

why do you convert a string of two values into a 2D array of data?

Why do you try to index row 0 and 1?

Why do you use such a format string for this specific conversion function?

 

Suggestion:

Replace SpreadsheetStringToArray by ScanFromString and use the same format string to get two outputs from your two values (per message)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(1,369 Views)

The Spreadsheet String To Array function defaults to using the tab as the delimiter while your sketch is using a comma.  But that does not matter here since you would be better off here just simply using Scan From String to parse the string into the two values.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 11
(1,337 Views)

@Gappiya wrote:

I am trying to separate the Voltage and current value coming from serial port using VISA. But only first value is reading. What would be the error? This is my LabVIEW fileThis is my LabVIEW file

 

This is my Arduino code 



void setup() {
  Serial.begin(115200);

  
}



void loop() {

  float voltage = analogRead(A0);
  float current = analogRead(A1);
  Serial.print(voltage);
  Serial.print(",");
  Serial.println(current);
  delay(100);
  
}

For such a simple task, LINX or Hobbyist toolkit will simplify the code a lot.

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019TmpSAE&l=en-US

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 4 of 11
(1,331 Views)

Knight Of NI thanks for solution i have added ScanFromString and this errors came up. 

image.pngimage.png

0 Kudos
Message 5 of 11
(1,327 Views)

Hi Gappiya,

 

why do you want to apply Waveform functions on scalar samples?

Why do you even need ExpressVIs for the task? (ToDDT is an ExpressVI…)

 

Why don't you handle errors programmatically?

Did you receive the string as expected by ScanFromString?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 11
(1,312 Views)

Hi GerdW

 

I used Waveform functions to offset the signal (2.5V to zero)

I used ToDDT because Waveform functions accept Dynamic data

What string should include for the ScanFromString (%f,%f or %f)

 

Thank you

0 Kudos
Message 7 of 11
(1,303 Views)

Hi Gappiya,

 


@Gappiya wrote:

I used Waveform functions to offset the signal (2.5V to zero)

I used ToDDT because Waveform functions accept Dynamic data


  • You can use a simple add function to apply an offset.
  • Waveform functions accept waveforms, otherwise they show a coercion dot. Do you know what a coercion dot indicates?

@Gappiya wrote:

What string should include for the ScanFromString (%f,%f or %f)


How does the received string look like when error 1 pops up?

The format string should match the format of the received string (or vice-versa)…

 

Your code:

Serial.print(voltage);
Serial.print(",");
Serial.println(current);

results in a message like "1.234,5.678\n" (with "\n" marking the LF char added by println), so the format string should be "%f,%f".

Is your computer set to use English numeric format with the point (".") as decimal separator char?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 11
(1,301 Views)

@Gappiya wrote:

I used Waveform functions to offset the signal (2.5V to zero)

I used ToDDT because Waveform functions accept Dynamic data

What string should include for the ScanFromString (%f,%f or %f)

1. Just use the Add function to the sample.

2. The Waveform functions accept Waveforms, which can be coerced from the DDT.  But if you just use the Add function instead of the Waveform Scale & Offset, there is no need for the ToDDT.

3. The format string should be "%f,%f".  If there is a possibility your system uses the comma decimal separator, you should use "%.;%f,%f".  The "%.;" forces the Scan From String to use the period as the decimal separator.

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 11
(1,287 Views)

Thank you very much for the comment. I did the modifications but neither "%f,%f" or "%.;%f,%f" working. still i am getting same error image.png

0 Kudos
Message 10 of 11
(1,273 Views)