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
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)
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.
A one-liner Something that works really well for datalogging, and acting on data:
Summarythe following timestamps and sends to stdout
cat /dev/cu.usbmodem1421 | awk '{ for (i=0; i<NF; i++) printf $i + system("echo , `date`")}'
Sample Output:
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
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>&-