LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino signal to labview (HELP!)

Hey everyone! I'm stuck with acquiring the signal from the arduino to labview.. I'm using serial communication with the USB port and the code is this:

 int sensorValue;
double Voltage = 0;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
sensorValue = analogRead(A0);
Voltage = (sensorValue / 1023.0) * 5000;
Serial.print(Voltage);

}


The readings I get from the labview is strange. It doesn't matter whether the AC supply is on/off and the data showed in labview is varying. I'm using ACS712 current sensor to measure.
I'm using this VI to see the incoming signal.

0 Kudos
Message 1 of 26
(4,409 Views)

This isn't a LabVIEW question, it's an Arduino one so you should ask it on an Arduino site. Forget LabVIEW for now and just look at the output on the Arduino IDE's serial monitor.

0 Kudos
Message 2 of 26
(4,395 Views)

I've got the readings working, but now the signal is weird.. I'm trying DC now and the signal I get should be a smooth line but instead it's showing spikes?

I really need help with this guys, my project deadline is coming nearer and nearer. Thank you!

 

0 Kudos
Message 3 of 26
(4,302 Views)

I've got the readings working, but now the signal is weird.. I'm trying DC now and the signal I get should be a smooth line but instead it's showing spikes?

The waveform will go back to 0 as soon as it displays the DC value on the wavechart.

I really need help with this guys, my project deadline is coming nearer and nearer. Thank you!

 

0 Kudos
Message 4 of 26
(4,301 Views)

Hi lamela,

 

I'm trying DC now and the signal I get should be a smooth line but instead it's showing spikes?

Yes, I would expect that too…

 

The waveform will go back to 0 as soon as it displays the DC value on the wavechart.

Yes, that's what you get - with YOUR VI…

 

You're using BytesAtPort function: when this function gives back "zero bytes in buffer" you read exactly zero bytes. Those zero bytes will get converted to ZERO as you didn't include any error checking in your VI. And this ZERO will get displayed - after some RubeGoldberg conversions from integer to float to DDT…

 

Get rid of BytesAtPort, use the correct termchar and your whole serial data communication will be (nearly) fool-proof. And learn about LabVIEW basics as debugging…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 26
(4,286 Views)

Thanks for your reply!

I'm still new to labview.. what is the correct termchar you mentioned?

0 Kudos
Message 6 of 26
(4,270 Views)

Hi lamela,

 

the "correct" termchar is the char you use in your Arduino to terminate each message. Set the very same char with VISASerialPortInit!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 26
(4,262 Views)

Sorry! I'm not very sure with the termchar part..

Here is my arduino code:

 

const int analogIn = A0;
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;

void setup(){
Serial.begin(9600);
}

void loop(){

RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);

Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point


}

 

0 Kudos
Message 8 of 26
(4,230 Views)

Hi lamela,

 

Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point

So you should receive something like "\t mV = 1.234".

I would change this part to get a string like "mV=1.234\n", where \n is the termchar (LF=linefeed=0x0A)…

(Additionally you reduce the overhead of 3 SPACE and 1 TAB chars.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 26
(4,227 Views)

I changed the part but the code doesn't seem to work?

I'm not getting any readings or signal displayed in the labview.. 

If I use back the code from previously, I will get the same problem from the picture. What should I do?

0 Kudos
Message 10 of 26
(4,163 Views)