UART didn't receiverd

When I tested simulate in Thinkercad, I could see the data in master side, while no data in slave side.

The sketch:

The code in master side:

// C++ code
//

#define BUTTON 14

char buttonFlag = '0';
char buttonFlagCurre = '0';

void setup()
{
  Serial.begin(9600);
  pinMode(BUTTON, INPUT);
}

void loop()
{
  buttonFlag = digitalRead(BUTTON);
  
  if(buttonFlag != buttonFlagCurre){
    
    if(digitalRead(BUTTON) == LOW){
      Serial.print('0');
    } else{
      Serial.print('1');
    }
    
    buttonFlagCurre = buttonFlag;
  } else{
    ;
  }
}

The code in slave side:

// C++ code
//

#define LED 14

char ledFlag = '0';

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

void loop()
{
  while(Serial.available() > 0){
    ledFlag = Serial.read();
  }
  
  if(ledFlag == '0'){
    digitalWrite(LED, LOW);
  } else{
    digitalWrite(LED, HIGH);
  }

  Serial.print("ledFlag = ");
  Serial.println(ledFlag);
}

I did not look at the code but you are missing the GND to be shared between the 2 boards

1 Like

You are right, thanks very much.

have fun !