[Solved] SWserial sends but not receives

HI

I have connected an Arduino Mega2560 wiith an Arduino Uno using Serial3 on the Mega side and SWserial in the Uno side.
I am able to send data from Uno to mega but not in the opposite direction. What i am getting usually is a sequence of numbers eg 42, 17, 49, 42, 17, 49, …

This is the code that i use for testing.

This is on Mega

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial3.begin(9600);
  Serial3.setTimeout(100);
  while (!Serial3) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

}

void loop() {
  // put your main code here, to run repeatedly:
  while (Serial3.available() > 0)
  {
    int value = Serial3.parseInt();
    delay(100);
    Serial.println(value);
    Serial3.println(value);
  }
  delay(100);
}

And this is the Uno code

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
SoftwareSerial serial(10, 13); // RX, TX

int counter = 0;


void setup() {
  // put your setup code here, to run once:
  serial.begin(9600);
  delay(300);
  serial.listen();

  lcd.begin(16, 2);
      lcd.setCursor(0, 0);
    lcd.print("Comm. Test");
}

void loop() {
  // put your main code here, to run repeatedly:
  serial.println(counter);
  delay(100);
  if (serial.available())
  {
    int value = serial.parseInt();
    
    lcd.setCursor(0, 1);
    lcd.print("                ");
    lcd.setCursor(0, 1);
    lcd.print(value);
  }
  counter++;
  delay(50);
}

Thank you in advance for any help.

You should edit your Original Post and change the title to NeoSWSerial so that you catch the attention of its author.

...R

This:

lcd.print(value);

...should be this:

lcd.write(value);

...or this:

lcd.print( (char) value );

It is printing the ASCII value of the character, not the character itself. For example, 49 is the ASCII value of the character '1'.

"You should edit your Original Post and change the title to NeoSWSerial so that you catch the attention of its author."

The problem is not NeoSWSerial specific i face the same problem with default Software serial.

I am using lcd.print with integers quite a lot of time without an issue. Just to make sure i try your suggestion and prints as you say the ASCII value of the numbers but what i want to print is the actual integer number.

I was using the serial.read() function instead of serial.parseInt just to see the actual bytes that i am receiving from the serial port and i forgot to restore it.. I corrected in the original post.

Finally i figured what was the problem. I falsely assumed that println() sending the termination character that needed by parseInt() which proved incorrect.

So i replace in the Mega side the command:

Serial3.println(value);

With:

Serial3.print(value); Serial3.print('\n');

And that works.

babis: Finally i figured what was the problem. I falsely assumed that println() sending the termination character that needed by parseInt() which proved incorrect.

So i replace in the Mega side the command:

Or don't use parseInt().

See Serial Input Basics

...R