Linux -> Arduino works fine, Arduino -> Linux not

I have a program which opens /dev/ttyUSB0 for read/write access. Through this file handle, I can send data to the Arduino just fine. It receives it. However, I cannot receive anything back from the Arduino.

The Arduino is loaded with an RS-232 loopback program, so anything I send to the Arduino, I should see come right back. I can confirm this is happening with Minicom. So I know that it's possible to exchange data.

However, when I use my own C code to do this, absolutely nothing happens. It's like the Arduino is a Data Roach Motel -- Data goes in, but does not come back out. The RX light flashes, the TX light does not.

I need to know why, but nothing I've tried helps. I even ran strace minicom to try and see, at a system-call level, if I'm doing anything differently than Minicom. While my call traces aren't precisely the same, the differences that exist are not sufficient to explain the errant behavior (e.g., Minicom opens the serial port non-blocking, whereas I'm in blocking mode).

The only way I can get to run and test my program is if I (1) first run minicom, then (2) type CTRL-A Z J to suspend Minicom, and then (3) run my software which opens /dev/ttyUSB0 as described above.

I really need to know what is happening here. :( Can anyone please help?[1]

Thanks in advance!!


  1. I don't have much faith though -- most of the messages along a similar line as this go unanswered. :( I'll try to keep debugging this in the mean-time, and will post my findings here if I stumble across anything.

KC5TJA,

Since it works if you run minicom first, it sounds like it might be an stty problem. I’d try this:

  1. Run minicom.
  2. run the shell command: stty -a < /dev/ttyUSB0
  3. Exit minicom
  4. Run your program
  5. While your program is running, stty -a </dev/ttyUSB0 again.

Compare the outputs from the two stty’s. You might want to save their outputs to files so you can diff them.

The problem is probably something like not setting “-icanon”.

Regards,

-Mike