07-15-2015 04:57 AM
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.
07-15-2015 05:03 AM
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.
07-20-2015 02:15 AM
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!
07-20-2015 02:15 AM - edited 07-20-2015 02:17 AM
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!
07-20-2015 02:28 AM
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…
07-20-2015 02:45 AM
Thanks for your reply!
I'm still new to labview.. what is the correct termchar you mentioned?
07-20-2015 02:51 AM
07-20-2015 03:19 AM
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
}
07-20-2015 03:28 AM - edited 07-20-2015 03:29 AM
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.)
07-20-2015 04:56 AM
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?