Skip to main content
Code formatting.
Source Link
Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81

i am trying to send data via Labview to my arduino board using serial communication.My problem is that the arduino reads only the first byte of sent data then when i change it ,it doesn't react.
For example when i start the communication i send '0' to arduino.I sees it.but while it is running i send '1' but it doesn't behave accordingly to it.
I noticed also that the board 'sees' sometime the new value after a random period of time.

    void setup()  
{ 
      Serial.begin(9600); 
      pinMode(13, OUTPUT); 
     } 

  char data='F';
data = 'F';

void loop() 
    { 
   

      data 
 = data=SerialSerial.read();
 
 

    delay(50); 

    if (data=='0'data == '0')
    {
        digitalWrite(13, HIGH);
        delay(1000);
        digitalWrite(13, LOW);
        delay(1000);
 } 
   }
    if (data=='1'data == '1')
    {
        digitalWrite(13, HIGH);
        delay(4000);
        digitalWrite(13, LOW);
        delay(4000);
 } 
  data='4'; }

         data = '4';
} 

i am trying to send data via Labview to my arduino board using serial communication.My problem is that the arduino reads only the first byte of sent data then when i change it ,it doesn't react.
For example when i start the communication i send '0' to arduino.I sees it.but while it is running i send '1' but it doesn't behave accordingly to it.
I noticed also that the board 'sees' sometime the new value after a random period of time.

    void setup() { 
      Serial.begin(9600); 
      pinMode(13,OUTPUT); 
     } 

  char data='F';
  void loop() 
    { 
   

       
  data=Serial.read();
 
 

  delay(50);
 if (data=='0')
  {
    digitalWrite(13,HIGH);
    delay(1000);
   digitalWrite(13,LOW);
 delay(1000);
 } 
 
if (data=='1')
 {
  digitalWrite(13,HIGH);
  delay(4000);
  digitalWrite(13,LOW);
  delay(4000);
 } 
  data='4';

           } 

i am trying to send data via Labview to my arduino board using serial communication.My problem is that the arduino reads only the first byte of sent data then when i change it ,it doesn't react.
For example when i start the communication i send '0' to arduino.I sees it.but while it is running i send '1' but it doesn't behave accordingly to it.
I noticed also that the board 'sees' sometime the new value after a random period of time.

void setup() 
{
    Serial.begin(9600);
    pinMode(13, OUTPUT);
}

char data = 'F';

void loop()
{
    data = Serial.read();
    delay(50); 

    if (data == '0')
    {
        digitalWrite(13, HIGH);
        delay(1000);
        digitalWrite(13, LOW);
        delay(1000);
    }
    if (data == '1')
    {
        digitalWrite(13, HIGH);
        delay(4000);
        digitalWrite(13, LOW);
        delay(4000);
    }

    data = '4';
}
Source Link
ChiPlusPlus
  • 153
  • 1
  • 1
  • 9

Arduino serial communication synchronisation

i am trying to send data via Labview to my arduino board using serial communication.My problem is that the arduino reads only the first byte of sent data then when i change it ,it doesn't react.
For example when i start the communication i send '0' to arduino.I sees it.but while it is running i send '1' but it doesn't behave accordingly to it.
I noticed also that the board 'sees' sometime the new value after a random period of time.

    void setup() { 
      Serial.begin(9600); 
      pinMode(13,OUTPUT); 
     } 

  char data='F';
  void loop() 
    { 
   

       
 data=Serial.read();

 

 delay(50);
 if (data=='0')
  {
    digitalWrite(13,HIGH);
    delay(1000);
   digitalWrite(13,LOW);
 delay(1000);
 } 

if (data=='1')
 {
  digitalWrite(13,HIGH);
  delay(4000);
  digitalWrite(13,LOW);
  delay(4000);
 } 
 data='4';

           }