Many users are asking how to access UART through a shell script. The script is shown below:
#!/bin/sh if [ $# -ne 1 ]; then echo "Usage: $0 MESSAGE" exit 1 else msg=$1 fi delay=3 uart_id=1 rate=115200 setup() { uart_id=1 delay=3 echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio0 echo 3 > /sys/devices/virtual/misc/gpio/mode/gpio1 } loop() { echo "connect your PC with the board via uart${uart_id}, baund rate $rate" sudo chmod 777 /dev/ttyS${uart_id} 2>/dev/null killall microcom > /dev/null 2>&1 killall busybox > /dev/null 2>&1 busybox microcom -s $rate /dev/ttyS${uart_id} 2>/dev/null & while [ 1 ]; do echo -e "$msg\r\n" > /dev/ttyS${uart_id} sleep $delay done } main() { setup loop } main
Copy and paste the code, and saved to a file named ‘uart_test.sh’.
Usage:
Usage: uart_test.sh MESSAGE
Leave a Reply
You must be logged in to post a comment.