3

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 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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!

1 Comment

I should add, you will need that 10uF cap between reset & ground in order to stop the Arduino auto-resetting every time you send a string over serial :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.