2 things worth to try;-
1. stty set communication parameter
Or maybe it's a configuration option you can set using stty.
stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
u need run it before cat and fine tune it to fit you need.
2. modify the code
void setup()
{
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//...
}
void loop()
{
if (Serial.available() > 0) {
//...