Divergence in reading

1

I made a sketch for Arduino MEGA, where it receives data by Serial2 and displays in the Serial, the communication happens but the byte sent is not the same as received, for example:

Send 0x01, receive 0x7F Send 0x99, receive 0x33

    void setup()
    {
      Serial.begin(9600, SERIAL_8N1);   //Monitor
      Serial2.begin(9600, SERIAL_8N1);  //Leitor

      Serial.println("Waiting...");
    }

    void loop()
    {
      byte data;

      if ( Serial2.available() ) {
        Serial.println("Leitor...");

        do { 
          data = Serial2.read();

          Serial.print("0x");
          Serial.println(data, HEX);
        } while (Serial2.available());

      }
}

I tried to change the configuration to 8N2, 7N1 among others but the serial sending as in the image below:

This is not the first time I try to read something for another MEGA serial that is not zero, and the same thing happens.

    
asked by anonymous 23.10.2018 / 21:54

0 answers