Thanks In0 for your replay. I understand the difficulty to cope with a lot of different boards. Thanks also for the suggestion for a soft reset.
Anyway, I have written a small bash script performing an USB hard reset via RTS. I tested it with arduino nano and nodeMCU v3 esp8266 and it seems to work well.
Since, I think it may be useful for other developers, here it is
#!/bin/bash
# .title : Arduino board hard reset by USB
# .author : Fabrizio Pollastri <mxgbot@gmail.com>
if [[ ! $1 =~ ^[0-9]+$ ]]
then
echo "USAGE: ./arduino_reset.sh <TTYUSB_NUMBER_ONLY>"
exit
fi
SERIALPORT="/dev/ttyUSB$1"
DELAY="1"
echo "
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
main() {
int port_fd = open(\"${SERIALPORT}\",O_RDWR | O_NOCTTY);
if (errno)
printf(\"Error opening %s: %s (%d).\n\",\"${SERIALPORT}\",strerror(errno),errno);
int modem_ctrl,modem_ctrl_saved;
if (ioctl(port_fd,TIOCMGET,&modem_ctrl_saved) == -1)
printf(\"Error getting handshake lines: %s (%d).\n\",strerror(errno),errno);
modem_ctrl = (modem_ctrl_saved | TIOCM_RTS) & ~TIOCM_DTR;
if (ioctl(port_fd,TIOCMSET,&modem_ctrl) == -1)
printf(\"Error setting handshake lines: %s (%d).\n\",strerror(errno),errno);
sleep (${DELAY});
if (ioctl(port_fd,TIOCMSET,&modem_ctrl_saved) == -1)
printf(\"Error setting handshake lines: %s (%d).\n\",strerror(errno),errno);
close(port_fd);
} " | tcc -run -
#### END ####