3
votes

I have set up my Arduino so when I send a "0" via the serial monitor, a stepper motor turns a given amount.

I want to include this in a bash script, but I can only get this to work when the arduino serial monitor is open and entering echo 0 > /dev/tty.usbserial641 in bash. I assume this is because serial monitor is opening the connection for me.

In my struggle to open the connection in bash (without serial monitor open) I have tried all manner of options with stty -f /dev/tty.usbserial641 and have also tried connecting reset to ground with a 10uF capacitor.

Can any help me open the connection in bash without the use of arduino serial monitor?

System: Arduino Uno rev3 OS X 10.8.4

Many thanks, hcaw

2

2 Answers

5
votes

Do the commands below work for you.

 # stty -F /dev/ttyUSB0 9600 cs8 -cstopb
 # sleep 0.1
 # echo "0" > /dev/ttyUSB0

There is a difference between the value 0 and the ascii char 0 (48). Which one you trying to send, and which one are you trying to receive?

If you want to read the port from the terminal you can do it like this

head -n 1 /dev/ttyUSB0  //the number after n is how many lines you want to read

As a last note, I am a fan of pySerial. I would much rather write an interface in python than shell scripts.

2
votes

I found a great binary written in C that solves my problem called Arduino-serial. Here's the link. I hope this helps people with similar problems!