Skip to main content
added 489 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

Add the flag -hupcl to your stty command. That will disable the assertion of DTR which is resetting the board.

 hupcl (-hupcl)
             Stop asserting modem control (do not stop asserting modem
             control) on last close.

The first time it is run there will be a reset, since setting that flag entails opening the port, which causes a reset. So you need to add a delay long enough to get past the bootloader - minimum 2 seconds, best make it 3.

You can do that with the sleep command: sleep 3

Note that you now won't be able to upload a new sketch since you have disabled the auto-reset feature that allows you to enter the bootloader, so before uploading a new sketch you need to turn the reset back on with

stty -F $tty hupcl

If you don't disable the reset then every operation in your script that opens and then closes the serial port will trigger a reset of the board. So in summary try this:

#!/bin/bash
tty=/dev/ttyUSB0
stty -F $tty cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -hupcl
sleep 3
echo temp >$tty
read reply <$tty
echo "$reply"
stty -F $tty hupcl

Add the flag -hupcl to your stty command. That will disable the assertion of DTR which is resetting the board.

 hupcl (-hupcl)
             Stop asserting modem control (do not stop asserting modem
             control) on last close.

The first time it is run there will be a reset, since setting that flag entails opening the port, which causes a reset. So you need to add a delay long enough to get past the bootloader - minimum 2 seconds, best make it 3.

You can do that with the sleep command: sleep 3

Note that you now won't be able to upload a new sketch since you have disabled the auto-reset feature that allows you to enter the bootloader, so before uploading a new sketch you need to turn the reset back on with

stty -F $tty hupcl

Add the flag -hupcl to your stty command. That will disable the assertion of DTR which is resetting the board.

 hupcl (-hupcl)
             Stop asserting modem control (do not stop asserting modem
             control) on last close.

The first time it is run there will be a reset, since setting that flag entails opening the port, which causes a reset. So you need to add a delay long enough to get past the bootloader - minimum 2 seconds, best make it 3.

You can do that with the sleep command: sleep 3

Note that you now won't be able to upload a new sketch since you have disabled the auto-reset feature that allows you to enter the bootloader, so before uploading a new sketch you need to turn the reset back on with

stty -F $tty hupcl

If you don't disable the reset then every operation in your script that opens and then closes the serial port will trigger a reset of the board. So in summary try this:

#!/bin/bash
tty=/dev/ttyUSB0
stty -F $tty cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -hupcl
sleep 3
echo temp >$tty
read reply <$tty
echo "$reply"
stty -F $tty hupcl
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

Add the flag -hupcl to your stty command. That will disable the assertion of DTR which is resetting the board.

 hupcl (-hupcl)
             Stop asserting modem control (do not stop asserting modem
             control) on last close.

The first time it is run there will be a reset, since setting that flag entails opening the port, which causes a reset. So you need to add a delay long enough to get past the bootloader - minimum 2 seconds, best make it 3.

You can do that with the sleep command: sleep 3

Note that you now won't be able to upload a new sketch since you have disabled the auto-reset feature that allows you to enter the bootloader, so before uploading a new sketch you need to turn the reset back on with

stty -F $tty hupcl