I have an arduino connected to /dev/ttyUSB0. I try to send '1' to it using

echo 1 > /dev/ttyUSB0

but nothing seems to happen. However, if I do this beforehand:

tail -f /dev/ttyUSB0 &

and try the echo command again, it works. Why is this?

  • What is it you were expecting to happen? – goldilocks Nov 19 '16 at 15:33
  • The arduino reads the serial port and if I send it a 1 it switches some remote control sockets on. If I send it a 2 it switches them off. It doesn't send any kind of reply back on the serial connection - I removed that in case it was causing the problem. – Chris Oakey Nov 19 '16 at 16:00
  • Note that echo by default adds a newline which I presume the dev interface passes straight through, so that will actually be two bytes, 1\n, although that doesn't make much difference to what you're describing. You can use echo -n to suppress that. – goldilocks Nov 19 '16 at 16:23
  • The arduino code reads the first byte and then discards the remainder. What I don't understand is why it works when I have another process tail the port – Chris Oakey Nov 19 '16 at 16:57
  • I've never tried using the serial port this way. My first guess is that the TX line only goes high when it is opened by an application, and without that transmitting a few bytes probably won't work. You could verify this with a multimeter. I think the hardware pulls it low by default and there's no reason for the OS driver to change that unless the "device" is actually in use. UART communication is about the line dropping, not rising, in pulses. A continuously low RX (opposite the Pi's TX) would indicate no connection to the Arduino. – goldilocks Nov 19 '16 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.