Communication between 2 arduinos UNO, UART

HELLO,
I am making a simle code to communicat 2 arduinos Uno . the first board send a binary msg and the second one recieve it
you find here my code that i used . the problem is that in the monitor of the reciever I don't have the same msg that the first board have sent!!
could you please tell me wat's wrong with the code?

//master sending a msg
byte msg= 0b10110110;
void setup() {
    // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(msg);
}


// receive msg

byte recieved_data = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() > 0){
    recieved_data = Serial.read();
    Serial.println(recieved_data,BIN);

  }

}

@thalesmaissa, your topic has been moved to a more suitable location on the forum.

What does it print at the receiver side?

You are aware that the USB connection makes use of pins 0 and 1?

thank you .

no i don't know that so i have to change and use other pins using the librery softwareSerial??

here what i get in the serial:

anyone can help please??
I realy need to solve this problem to continue my work.

Use SoftwareSerial. And don't send data like a maniac ( :wink: ) Just add a delay of e.g. 500 ms or 1 second.

Note that one of the beauties of the Arduino environment is that you can easily test things.

your code is working fine from what I can see! :slight_smile:

since you are using 'println' what you are transmitting is the ASCII value for characters '1', '8', '2' + CRLF

With println, you are sending a TEXT string, not a byte with value 182. to do the latter, you would use Serial.write().

Hope that helps....

thank you for your request I understand.
I am going to try with serial write

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.