• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramUARTSample Shell Script Used to Access UART of pcDuino ...
Previous Next

Sample Shell Script Used to Access UART of pcDuino1/2/3

Posted by: admin , May 5, 2014

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

Tags: UART

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors