3

I'm trying to communicate with NodeMCU (CP210x USB/UART) from command-line. However it does not respond to my commands. I have set the correct baudrate via stty 9600 raw.

echo "gpio.write(0,gpio.LOW)" >/dev/ttyUSB0

It works when some other program is using / listening on the /dev/ttyUSB0 (minicom, screen or even cat /dev/ttyUSB0).

When no other program is using the tty, it does not work. I have confirmed the stty settings are the same all the time.

From the error messages from NodeMCU I confirmed that it receives only first 4 characters of my command (when no other prog is using the port), so as a workaround I have made this work:

echo -n "gpio" >/dev/ttyUSB0
echo -n ".wri" >/dev/ttyUSB0
echo -n "te(0" >/dev/ttyUSB0
echo -n ",gpi" >/dev/ttyUSB0
echo -n "o.LO" >/dev/ttyUSB0
echo    "W)"   >/dev/ttyUSB0

Can someone explain me what is happening and how to fix it?

  • @DmitryGrigoryev do you think that having cat /dev/ttyUSB0 in 2nd window changes the flow control somehow? Also the stty -a shows the same settings in both cases, so the flow control is set the same. – Marki555 Dec 17 '15 at 23:30
  • Is the other end expecting hardware or software flow control? – Aaron D. Marasco Dec 18 '15 at 1:09
  • When the port is opened by a process, its DTR signal is asserted. It's possible the signal goes down before the buffer has been completely written (echo has closed the port but there's still data in the buffer). Try (echo "gpio.write(0,gpio.LOW)"; sleep 1) >/dev/ttyUSB0 – wurtel Dec 18 '15 at 7:56
  • @wurtel Interesting idea, however it doesn't work... maybe DTR is asserted only when device is opened for input? Do you know of any way how to assert DTR from command-line? – Marki555 Dec 18 '15 at 14:14
  • input or output shouldn't make any difference in my experience, although as this is a USB device the driver may not have implemented the normal serial IO behaviour correctly. – wurtel Dec 18 '15 at 14:25

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.