Becoming desperate with serial.read over tty

Hi everybody,

I'm becoming desperate with the connection between Arduino und my computer.

Problematic code looks like this:

String  input  = "";
int chr = Serial.read();
  if (chr > 0) {
    input += (char)chr;
  } else if (chr == -1 && input != "") {
    Serial.println(input);
  }

That works within the Arduino IDE. Entering "Test123" in serial monitor gives me a "Test123" back.
But when trying to communicate via serial connection from my computer, all I get are hieroglyphs "@U???"
Serial.println("Test123"); gives me "Test123". So the problem seems to be the Serial.read()

I printed out the chr variable (that's getting the input from serial.read()). When using the Arduino IDE the serial monitor gives me back
84 : 101 : 115 : 116
for the word "Test". IMHO the correct char codes for "Test".
Via the serial connection it's
54 : 65 : 73 : 74
What's going on there?

Slow down.

What “serial connection”?
Please tell us you’re not trying to connect to RS232.

What code?

Wow...that was fast! :o

The Arduino should be controlled by a perl script that's running on my mac.
The test-perl script for sending looks like this:

use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/tty.usbserial");
$port->baudrate(9600);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
$port->write("Test");

The perl-script for receiving works like expected. Baudrate 9600 is the same in all scripts and the Arduino code.

That all worked for some years between my mac and an Arduino Uno. But with the Arduino Nano I have this strange behavior that's driving me crazy since some hours.

You may want to put back your Arduino Uno and make sure it still works and that nothing has changed.

Got it after 3 hours of trial and error...
Had to prefix and suffix \0 on the perl side.
Maybe a driver-related issue - the Nano needs a driver where the Uno didn't.

use Device::SerialPort;
my $port = Device::SerialPort->new("/dev/tty.usbserial");
$port->baudrate(9600);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
$port->write("\0Test\0");