two arduino talking via TX and RX

Hi
I have a question

I have a arduino Mega and UNO.

So currently I have the mega Serial1.print(50);

the Uno on lcd.print gets 5348

which from my understanding is the DEC code of 50 which is fine.

I also have the mega sending 48 which on uno is 5248

the issue is the Serial read is tiggering the print with just the 48

I need the Uno to read the entire number so I can do a

if "Something" == '5348')
 {
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("STONEHALL TERMINUS");

The overall aim is for the Mega to send number to the UNO and the Uno to print to the Lcd the information I require. the longest number I need is only 2 digits

Hope it makes sense to what I am trying to do.

ps I didnt post a full code as I dont have a working code even after 5 hours today working on it.

Have you tried Serial1.print("50");

thejmr:
ps I didnt post a full code as I dont have a working code even after 5 hours today working on it.

Post the code that represents your best attempt. Parts of the problem exist outside the snippet you posted.

Note that single quotes 'a' are only used with single characters and "double" quotes must be used with multiple characters.

...R

Serial1.print("<50>");

on the sender.

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

on the receiver. Where it says "Process the packet", you simply want

lcd.print(inData);

Below is some serial-to-serial test code I've used between two arduinos.

//zoomkat 3-5-12 simple delimited ',' string tx/rx 
//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino rx pin to the receiving arduino rx pin. 
//Connect the arduino grounds together. 
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.print(readString); //prints string to serial port out
        Serial.println(','); //prints delimiting ","
        //do stuff with the captured readString 
        readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Ill post an extract. I have somewhat working using single bytes

this code is from the UNO so the board driving the LCD and RX the Code

void loop()
{
  if (Serial.available() >0)
  incomingByte = (Serial.read());
 if (digitalRead(LED ==LOW))
{  
  if (incomingByte == 65)
 {
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("STONEHALL TERMINUS");
   delay(1000);
 }
 if (incomingByte == 33)
 {
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("STONEHALL TERMINUS");
   lcd.setCursor(0,1);
   lcd.print("CALL ON?");
   lcd.setCursor(0,2);
   lcd.print ("1 = YES 0 = NO");
   lcd.setCursor(0,3);
   if (digitalRead(Call ==LOW))
  { 
   digitalWrite(LED,HIGH);
   delay(100);
   lcd.print("1");
   Serial.print("1");
   digitalWrite(LED,LOW);
   delay (200);
   lcd.clear();
  }
   lcd.blink();
   
 }

 if (incomingByte == 66)
 {
  
   lcd.setCursor(0,2);
   lcd.print("READY");
   delay(200);

the Mega TX code

void loop()
{
  if (Serial1.available() >0)
  incomingByte = (Serial1.read());
  if(digitalRead(R1) ==LOW)
  {
    delay(100);
    digitalWrite (LED,HIGH);
    digitalWrite (R1,LOW);
    delay(50);
    //PLATFORM 1
    if (digitalRead(R2) ==LOW)
    {
      delay(100);
      Serial1.print("C");
      delay(500);
      if (val < 300)
      {
      digitalWrite(T1,LOW);
      digitalWrite(T2,LOW);
      delay(250);
      digitalWrite(T1,HIGH);
      digitalWrite(T2,HIGH);
      Serial1.write("#"); //POINTS ARE SET
      digitalWrite (Fl1,HIGH);
      digitalWrite(Pl1,HIGH);
      digitalWrite(LED,LOW);
      digitalWrite(R2,LOW);
      digitalWrite(R1,HIGH);
      digitalWrite(R2,HIGH);
      delay (2000);
      digitalWrite (Fl1,LOW);
      digitalWrite(Pl1,LOW);
      }
if (val >= 400) 
{
  Serial1.print("!");
  delay(1000);
if (incomingByte ==49)
  {
    digitalWrite(T1,LOW);
      digitalWrite(T2,LOW);
      delay(250);
      digitalWrite(T1,HIGH);
      digitalWrite(T2,HIGH);
      Serial1.write("#"); //POINTS ARE SET
      digitalWrite (Fl1,HIGH);
      digitalWrite(Pl1,HIGH);
      digitalWrite(LED,LOW);
      digitalWrite(R2,LOW);
      digitalWrite(R1,HIGH);
      digitalWrite(R2,HIGH);
      delay (2000);
      digitalWrite (Fl1,LOW);
      digitalWrite(Pl1,LOW);
      
}
if (incomingByte == 48)
{
        digitalWrite(R2,LOW);
      digitalWrite(R1,HIGH);
      digitalWrite(R2,HIGH);
}
}

Its all In DECIMAL CODE

The two boards do talk to each other in single bytes so like "C" is "67"

but I want to send in the long run "21" which I know is "5049"

so the Above codes are the codes that relate to each other and is the test code

but I want to send in the long run "21" which I know is "5049"

Not sure just what you want to do, but the below is a way to convert a received character String like "200" into the number 200.

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int num = readString.toInt();
    Serial.print("your number is: ");
    Serial.println(num);
    Serial.println();
    readString=""; //empty for next input
  }

Maybe this Thread serial input basics will be useful.

Why won't you post your full code?

...R

thank you for both your reply's I will check both of the out Thank you again

48 has another name. It is '0'. You can use either one.
If you want easier to read code and you mean text 0 then code '0'.
Same with 49 is '1'.

These are called ASCII (American Standard Code for Information Interchange) codes.

 if (digitalRead(LED ==LOW))

Read from pin 0 or 1, based on whether you have defined LED to be LOW or not. Why?

GoForSmoke:
48 has another name. It is '0'. You can use either one.
If you want easier to read code and you mean text 0 then code '0'.
Same with 49 is '1'.

These are called ASCII (American Standard Code for Information Interchange) codes.

Yes thay is what I am meaning Currently I am just sending "1" and the uno reading it as "49" which i know is the ASCII I know that from the starter handbook.

zoomkat:
Not sure just what you want to do, but the below is a way to convert a received character String like "200" into the number 200.

  if (readString.length() >0) {

Serial.println(readString);  //so you can see the captured string
    int num = readString.toInt();
    Serial.print("your number is: ");
    Serial.println(num);
    Serial.println();
    readString=""; //empty for next input
  }

Sorry for the two posts but . what it is I am doing is building a Signal center for my model railway with some help i got it started and now I wanna go to the next step I am having 1 Mega board controling all the relays and one Mega in the Main board handling lights and buttons and the UNo having the lcd and in time a numeric keypad. so the two mega will communicate via WIFI waiting for that mega to arrive and the mega and a uno Via Cable. The only other issue I am having with my Uno code is the LCD is always blinking like its always updating and clearing I will attach the complete code.
but the blinking lcd can wait for now. The reason I need to be sending that string is because there are so many different outcomes many the same it easyier to talk in numbers or a letter and number :slight_smile: thanks for your help again will check out the other responses now tomorrow.
the other reason for all the board is the wiring to a minimal as currently there is loads

attached file is
LCD_Driver is the UNO
signal_Box is the current Mega when the other mega arrives this code will get split up

LCD_Driver.ino (6.94 KB)

signal_Box.ino (21.5 KB)