communication between 2 Arduino Mega

Hi,

it's my first time making a serial communication between 2 Arduinos, and I have a problem>

I'm sending an integer "550", to check. but in the receiver, shows "535348".

my code is this..

sending Mega

    int val5=550;

    void setup() {
  
    Serial.begin(9600);
    
    Serial.print(val5);
    }

    void loop() {


    }

the receiver Mega

    int incomingByte;

    void setup() {

    //Serial1.begin(9600);
    Serial.begin(9600);

    }

    void loop() {


    if (Serial.available()) {

    incomingByte = Serial.read();
    Serial.print(incomingByte);

    }
    }

as you can see, I'm only sending 550, each time I press Reset. I have checked with putty, and is sending the integer in the COM port of the sender. but the value that I receive in the receiver port is the one that I mentioned. I have tried with Serial.write, assigning the integer as other type of numbers....(byte, long...etc)

I think that its just a beginner's mistake....

please help me if you know what is happening.

thank you!

Serial.print is sending a string "550". Is that what you expect?

well, I was expecting to send a number, an integer...also I tried the same with Serial.write, without changing anything in the receiver code. but I still have the same problem.

This is what you are sending.
535348

53 = '5'
53 = '5'
48 = '0'

ohh I see... so it's sending digit by digit in binary and reading in the same way.

how can I fix this? do I have to make a loop to save digit by digit in a vector?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example.

I think your receiving Mega should receive on (say) Serial1 and send to the Serial Monitor using Serial.

At the moment I am using this program on a Mega to receive data and pass it on to the Serial Monitor

// Example 3 - Receive with start- and end-markers

const byte numChars = 32;
char receivedChars[numChars];

boolean newData = false;

void setup() {
    Serial.begin(9600);
    Serial.println("<Mega is ready>");
    Serial1.begin(9600);
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (Serial1.available() > 0 && newData == false) {
        rc = Serial1.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

...R