Bash, serial I/O and Arduino

后端 未结 10 2306
眼角桃花
眼角桃花 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:16

    Check to see if sending data to / receiving data from the Arduino unit is working by using a different app such as Cornflake (serial terminal for Mac OS X) - instead of using the Arduino IDE & the Serial Monitor.

    In addition, you may want to check out if you could benefit from switching to Xcode (in terms of debugging features, etc.).

    See: Setting up Xcode to Compile & Upload to an Arduino ATMega328 (Duemilanove)

    0 讨论(0)
  • 2020-12-23 19:17

    Try using the tool stty:

    stty -F /dev/my_serial_port <baud_rate> cs8 cread clocal
    

    As always, read the manpage before applying the above. cread allows you to receive data. You may want to omit clocal if you are using flow control. If you aren't sure what the above settings are, ask, and I can write up a more complete answer.

    0 讨论(0)
  • 2020-12-23 19:17

    A one-liner Something that works really well for datalogging, and acting on data:

    Summary
    • monitoring: the arduino output can trigger actions on the computer
    • data-logging: it simultaneously save that streaming data to a file
    • notchecked? sending-messages: I haven't tried sending data yet to the arduino, but see the second example, might be able to send a message to the serial port via some cmdline util.

    the following timestamps and sends to stdout

    cat /dev/cu.usbmodem1421 | awk '{ for (i=0; i<NF; i++) printf $i + system("echo  , `date`")}'
    

    Sample Output:

    enter image description here

    This method can even be adapted to monitor and act upon the data in real time:

    cat /dev/cu.usbmodem1421 | awk '{ for (i=0; i<NF; i++) printf $i + system("echo , `date`)}'
    

    more examples here: https://github.com/gskielian/Arduino-DataLogging/tree/master/Bash-One-Liner

    0 讨论(0)
  • 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>&-

    0 讨论(0)
提交回复
热议问题