LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

problem when running labview

I have a project with the following process :

I use the Arduino as the microcontroller. My question, in the 29th second, suddenly the number of arrays (visible in the probe watch windows) changed itself. but at 34th second back to normal. it was repeated at 60th second. and continue to occur as long as the program is run, although not given input.

anyone know why this could happen?i need a help

0 Kudos
Message 1 of 6
(4,002 Views)

estimated, would be very useful if you put the piece of code where the problem occurs, to better understand the problem

0 Kudos
Message 2 of 6
(3,209 Views)

this is my VI project:

Untitled.jpg

and this is the arduino program:

int level;

void setup()

{

  Serial.begin(9600);

  pinMode(2,INPUT);

  pinMode(3,INPUT);

  pinMode(4,OUTPUT);

  pinMode(5,INPUT);  

  pinMode(6,OUTPUT);

  pinMode(7,INPUT);  

  pinMode(8,OUTPUT);

  pinMode(9,INPUT);   

  pinMode(10,INPUT); 

void loop()

{

if ((digitalRead(2) == HIGH) && (digitalRead(3) == LOW))

{

    level++; 

    if (level>100)

    {

    int lebih=level-100;

    level=level-lebih;

    cetak();

    on ();

    indikator();

    Serial.write (' ');

    }

    else

    {

      cetak();

      on ();

      indikator();

      Serial.write ('U');

    }

}

if ((digitalRead(3) == HIGH) && (digitalRead(2) == LOW))

{

    level--; 

    if (level<=0)

    {

     level=level-level;

     cetak();

     on ();

     indikator();

     Serial.write (' ');

    }

    else

    {

      cetak();

      on ();

      indikator(); 

      Serial.write ('D');

    }

}

if (((digitalRead(3) == LOW) && (digitalRead(2) == LOW))||((digitalRead(3) == HIGH) && (digitalRead(2) == HIGH)))

{

  cetak();

  on ();

  indikator();

  Serial.write (' ');

}

if (digitalRead (5)==HIGH)

{Serial.write('B');}

else

{Serial.write('N');}

if (digitalRead (7)==HIGH)

{Serial.write('T');}

else

{Serial.write('N');}

if (digitalRead (9)==HIGH)

{Serial.write('A');}

else

{Serial.write('N');}

int suhu =analogRead (5);

suhu=map(suhu,0,1023,0,100);

Serial.write (highByte (suhu));

Serial.write (lowByte (suhu));

}

void cetak()

{

  Serial.write(level);

  delay(100);

}

void on()

{

  if (digitalRead (10)==HIGH)

  {Serial.write ('H');}

  else

  {Serial.write ('M');}

}

void indikator()

{

if(Serial.available()) 

{

int data1=Serial.read ();

int data2=Serial.read ();

int data3=Serial.read ();

if (data1=='B')

{digitalWrite(4,HIGH);}

else

{digitalWrite(4,LOW);}

  if (data2=='T')

{digitalWrite(6,HIGH);}

else

{digitalWrite(6,LOW);}

  if (data3=='A')

{digitalWrite(8,HIGH);}

else

{digitalWrite(8,LOW);}

}

}

0 Kudos
Message 3 of 6
(3,209 Views)

You should put shift registers on the error wires and OR the error boolean with your stop button to stop the loop.  This will make the loop exit if there is an error. (But I don't think that is the problem here...just good practice in general)

The array is probably empty some loop iterations because the arudino has not sent any serial data yet.  There is nothing synchronizing the two (LV and the arduino that is).  What you probably want to do is poll the serial port until the expected number of bytes is available, then read and process those bytes, then go back to polling for the expected number of bytes.

Have you tried using the LabVIEW Interface for Arduino for this project?  It takes care of a lot of synchronization and and other infrastructure for you.

Thanks!

-Sam K

LIFA Developer

0 Kudos
Message 4 of 6
(3,209 Views)

thanks

but i'm still confuse where is the error that you purpose?can you show me, sir?

0 Kudos
Message 5 of 6
(3,209 Views)

Essentially the flaw is that you are simply reading what ever data is available on the serial port.  This may or may not be all 8 bytes that you are assuming so you are basically just reading random values from the Arduino serial stream.

Like Sammy, I would recommend trying to do this using LIFA (LabVIEW Interface for Arduino) because it will prevent the issue that you are seeing as I stated above.

0 Kudos
Message 6 of 6
(3,209 Views)