Go Down

Topic: Using serial without listening (Read 1 time) previous topic - next topic

7487

Hello,
So, I am communicating with my arduino uno R3 though echo in debian linux. This works great, and i can get stuff back (For debugging i sent the same command back to the computer).

All fine so far.

However, now I dont really need the debugging stuff back anymore, so I removed the parts that send stuff back, making the arduino just listen.
Stuff still works great as long as i use
Code: [Select]
cat /dev/ttyACM0 > ~/debug.txt

And the file is empty as you would expect since I dont really send stuff back anymore from the arduino.
However, if I dont listen and handle the serial port on the computer with the above command, i cant really send commands either. I mean I can, and the rx light still blinks on the arduino, but the arduino does not execute the commands. The problem is then solved by letting cat /dev/ttyACM0 > ~/debug.txt run.

I kind of dont know whats wrong here, I dont see the tx light blink on the arduino, so i dont think its the serial buffer being full (If thats even a thing on the arduino), so I'd really appreciate any help on this.

robtillaart

Can you post your sketch?
There might be a design flaw?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

7487

Sure score!
Code: [Select]

#include <RCSwitch.h>
#include <util/delay.h>

#define BIT_LENGHT 24
#define TRANSMIT_PIN 10

RCSwitch NEXA_Switch = RCSwitch();


String readString;

void setup() {
  Serial.begin(115200);
  while (!Serial) {;} // wait for serial port to connect. Needed for Leonardo only
  NEXA_Switch.enableTransmit(TRANSMIT_PIN);  // Using Pin #10
}

void loop() {
 
  while (Serial.available()) {
    delay(3);  //delay to allow buffer to fill
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }

  }
  if (readString.length() >0) {
    unsigned long tmp=(unsigned long)atol(readString.c_str());
    //Serial.println(tmp); //see what was received
    NEXA_Switch.send(tmp , BIT_LENGHT);
    readString="";
  }
}


The part that changes is
//Serial.println(tmp); //see what was received
And nither option works without cat /dev/ttyACM0

On the computer side, serial options are set with the stty command (Correct baudrate etc)

7487

So I've been testing, and cat
Code: [Select]
cat /dev/tty9 > /dev/ttyACM0 also works.
/dev/tty9 is not in use so its not sending anything to the ttyACM0, but it seems like it is keeping it alive.
I've also in my code put in extra time for the buffers to fill up and tried sending an extra char before the "real" code, which did not work without the cat /dev command running, although it did with with, so the code was sound:ish.

The theory i have is that the serial connection is not working properly without being in use, but I still dont understand how.

sureshn

Use serialEvent() to read inputs commands (e.g.: blink the led on Arduino).  Process your command to blink within loop().  If you have to blink your led asynchronously, you have to implement your blink routine without delays.  You don't have to output messages from Arduino to your computer for blink routine.

Robin2

I don't like serialEvent() because you have no control over when it triggers.

Using if (Serial.available() > 0) {   allows you to decide when you deal with the incoming data.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sureshn

Some more techniques such as interrupts and notifications may also be used in which case interrupt/notification handlers have to be written.

Go Up