Bash, serial I/O and Arduino

后端 未结 10 2362
眼角桃花
眼角桃花 2020-12-23 18:53

So, I\'m in a bit over my head, and I feel like I\'m very close to a solution, but it\'s just not working quite yet. Here\'s my situation:

I\'m working with an Ardui

10条回答
  •  鱼传尺愫
    2020-12-23 19:20

    I get the same problem too. I use Arduino Uno with Ubuntu 12.04. After a few hours of searching and trying, I find out that Arduino will reset when the serial device is opened for the first time,but will not reset when the serial device is opened again.

    So, run command - echo "input string" > /dev/ttyXXX in bash will reset Arduino and send "input string" immediately. Arduino need take some time to initialize, and is not quick enough to receive this string. cat /dev/ttyXXX will reset Arduino too.

    When /dev/ttyXXX is opened in somewhere firstly, these commands will work.

    Here is my solution:

    1) open /dev/ttyXXX by redirecting /dev/ttyXXX to file description 3

    exec 3<> /dev/ttyXXX

    2) wait for Arduino's initialization

    sleep 1

    3) communicate with Arduino

    echo "input something" >&3

    cat <&3

    4) close /dev/ttyXXX

    exec 3>&-

提交回复
热议问题