Trying to setup an equivalent of Serial Monitor's "No line ending" on Terminal

Hi, as stated in the title I'm trying to setup a serial port on Terminal (Linux) in order to in the future use a program to write to it, instead of using the Serial Monitor.

Using the code bellow and inputting one character to the Serial Monitor (in "No line ending" mode) I've managed to obtain the behavior I wish, which is for the loop to be iterated once. If other mode is used the loop is iterated twice.

const int trig_out = 5;
const int trig_in = 6;
int np = 11;
int count;
byte dummy;

void setup() {
 pinMode(trig_out,OUTPUT);
 pinMode(trig_in,INPUT);
 digitalWrite(trig_out,LOW);  
 Serial.begin(9600); 
}

void loop() {

 while(!Serial.available()){} //tentar meter input a partir do programa de controlo do dmd para triggar este trigger
 dummy=Serial.read();
   
 for(count=0; count<np; count++){
   digitalWrite(trig_out,HIGH);
   delay(100);
   digitalWrite(trig_out,LOW);
 }
 delay(1000);
}

When opening the serial port through the Terminal though

$ stty -F /dev/ttyACM1 speed 9600
$ cat -v > /dev/ttyACM1

and then giving the same one character input I go back to have the loop iterated twice, from which I'm assuming there's a return being processed as a character and being held.

I've gone through some of the source code of Arduino-1.8.5 (mostly everything respecting the Serial and Monitor keywords), but other than an indexation of line endings I couldn't find any clue that'd help setup the serial port properly on Terminal. I've also read the --help on the stty command and have used most of the extensions I thought could do the trick (ignoring or transforming cr, brk or nl), but have had no luck.

Thank you in advance.

Don't you want to use "echo -n", not "cat -v"?

TolpuddleSartre:
Don't you want to use "echo -n", not "cat -v"?

I've tried, it doesn't even read what I input.

You may be able to solve your problem with suitable Arduino code.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Robin2:
You may be able to solve your problem with suitable Arduino code.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Thank you, but the problem persists. I have used the second example to go through all the characters until '\n' is detected (code bellow), but unless I select "No line ending" mode on Serial Monitor, it yields the same two iterations instead of one.

const int trig_out = 5;
const int trig_in = 6;
int np = 11;
int count;
char dummy='a';
char endMarker = '\n';

void setup() {
  pinMode(trig_out,OUTPUT);
  pinMode(trig_in,INPUT);
  digitalWrite(trig_out,LOW);  
  Serial.begin(9600); 
}

void loop() {

  while(!Serial.available()){} //wait until something is ready to be read

  while(Serial.available()&&dummy!=endMarker){
    dummy=Serial.read();
  }
 
  for(count=0; count<np; count++){
    digitalWrite(trig_out,HIGH);
    delay(100);
    digitalWrite(trig_out,LOW);
  }
  delay(1000);
}

What about \r though?

the usual linebreak is CRLF - \r\n

DrAzzy:
What about \r though?

the usual linebreak is CRLF - \r\n

The same happens.

joaomfras:
Thank you, but the problem persists. I have used the second example to go through all the characters until '\n' is detected (code bellow),

You did not post the code using my tutorial.

...R

Have you tried minicom?

Also found https://superuser.com/questions/714078/wrong-newline-character-over-serial-port-cr-instead-of-lf; might ring more bells to you than to me.

Thanks for the replies, I'll reply back to both of you Monday when I'll have again access to the setup.

I managed to fix it by adding a reading instruction before any of the while cycles, it seems the serial holds a character when the loop restarts for some reason, I'll address it later once everything is working and I can concentrate on performance. For now it's doing what I need. Thanks everyone!

joaomfras:
it seems the serial holds a character when the loop restarts for some reason,

Without seeing your program .... ?

...R