Lukasz Kujawa
Lukasz Kujawa

Reputation: 3096

Write to MAC's serial port to talk to Arduino (fopen( /dev/tty.usbmodem1431) hangs forver)

I have a problem with TTY device on MAC. I created a script which talks to Arduino and works well on Linux. Problem I'm having with MAC is I can't "fopen" the device. For example, if I do

echo "foo" > /dev/tty.usbmodem1431

It hangs forever blocking the port. It works well from Arduino's Serial Monitor so theoretically I should be able talking to it.

OK. I found the solution. I have to write to

/dev/cu.usbmodem1431

I still don't know why TTY don't want to work.

Upvotes: 4

Views: 7981

Answers (2)

user1139880
user1139880

Reputation: 1838

What speed are you using? The default speed of Max OSX is 9600. Give it a try (when you set serial in your arduino program). stty does not seem to change the speed as one would expect.

Upvotes: 1

user2466910
user2466910

Reputation:

You can use tty with:

stty -f /dev/tty.usbmodem1431 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

echo "hello" > /dev/tty.usbmodem1431

Where 115200 is your Serial.begin speed.

Upvotes: 2

Related Questions