0

platform:Arduino UNO, Arduino Mega2560, HC-05

Here shows the detail.

enter image description here

In Arduino UNO(Master), I encode

Serial.print("A 1 2 3 4 5;");

In Arduino Mega2560(slave), I encode

  void setup() 
{
    //connect to the PC
    Serial.begin(9600);
    //connect to the Arduino UNO(By bluetooth)
    Serial1.begin(38400); 
}

void loop()
{
    //its value > 0
    Serial.println(Serial1.available());   
    //output : 128 or 248
    Serial.print(Serial1.read());
    delay(1000);          
}

The value of Serial.available() > 0 is true, but the print result of Serial.print(Serial1.read()); is abnormal. it print

enter image description here

I want to know the reason and its solution.Thanks!

LIFUGUAN
  • 73
  • 6
  • Where do the new line characters come from? You don't print them on the Mega. And you are only reading a byte every second. How are you sending it? A lot faster? Seems your RX buffer is always almost full. – gre_gor Jul 05 '18 at 10:17
  • Oo,I forgot it........Sorry. – LIFUGUAN Jul 09 '18 at 07:47

1 Answers1

0

I'm assuming that you made sure that both the Bluetooth devices are connected properly and the baud rates are matched. Now, one problem might be the buffer might be full. On the sender's side, provide a delay equal to or slightly higher than the delay on the receiver's side. Next, on the receiver side, change void loop to this:

void loop(){
    if(Serial1.avaialable() > 0){
        char value = Serial1.read();
        Serial.println(value);
        delay(1000);
    }
}