Using Terminal for Serial Commands

by ckeyes on Sat Nov 19, 2011 1:44 pm

Hey,

I've seen that it may be possible to send the Arduino a serial command from Terminal on a Mac using something like:
./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s a

That particular command has as error, " No such file or directory".

Any idea what may work?

Thanks,

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am

Re: Using Terminal for Serial Commands

by cstratton on Sat Nov 19, 2011 2:04 pm

On a unix-like os, saying './arduino-serial' instructs the shell to run a program found in the current directory, rather than to search the path for that command. So this would only work if you are currently in the directory where that is found.

You can try it without the ./ - just type 'arduino-serial' and the rest of the command line and see if it is found then.

If not, you would have to figure out where this program comes from and where it lives that's not in the path, or how to install it.

However, there's no real requirement that you use that program. If you are using the arduino IDE, there's probably a serial monitor available in the drop down menu.

And surely there are many generic terminal emulator programs available for the Macintosh. You just need one where you can put in the special device string for the serial port, and have it not send modem control AT commands (since the arduino is not a modem). If it twiddles with flow control lines, you may have to wait a bit after starting it for the bootloader to time out and your sketch to start up.
User avatar
cstratton
 
Posts: 253
Joined: Wed Sep 29, 2010 2:52 pm

Re: Using Terminal for Serial Commands

by ckeyes on Sat Nov 19, 2011 2:31 pm

Thanks. Tried using just: arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s a
but returns "command not found"

Being a complete noobie at this I'm not sure where or what the arduino-serial is or where it may be.
Did a search on it and came up empty.

Is there some other command that may work with Terminal that may work?

Thanks,

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am

Re: Using Terminal for Serial Commands

by cstratton on Sat Nov 19, 2011 3:02 pm

Within the arduino environment, "Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin(). "
User avatar
cstratton
 
Posts: 253
Joined: Wed Sep 29, 2010 2:52 pm

Re: Using Terminal for Serial Commands

by ckeyes on Sat Nov 19, 2011 5:12 pm

Thanks, did that, but still no joy.

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am

Re: Using Terminal for Serial Commands

by cstratton on Sat Nov 19, 2011 6:47 pm

ckeyes wrote:Thanks, did that, but still no joy.


Why, what happened when you clicked the serial monitor button?
User avatar
cstratton
 
Posts: 253
Joined: Wed Sep 29, 2010 2:52 pm

Re: Using Terminal for Serial Commands

by ckeyes on Sat Nov 19, 2011 7:41 pm

It works fine from the serial monitor in the Arduino app if I enter an "a", or whatever.
I just need to send the same command from Terminal.

Thanks,

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am

Re: Using Terminal for Serial Commands

by stephanie on Sat Nov 19, 2011 7:48 pm

From the Terminal command prompt, you can use the 'screen' command to connect to the Arduino and then send commands through that.

Code: Select all | TOGGLE FULL SIZE
screen /dev/tty.usbmodem621
will 'connect' you to the Arduino, assuming the arduino is '/dev/tty.usbmodem621'. Then whatever you type in terminal is sent directly to the Arduino. To exit out of screen, you have to type Ctrl-A then Ctrl-\.

You can read some more info about using screen here: http://hints.macworld.com/article.php?s ... 9133825654

Edited to add - if you want to use something like a shell script to send commands rather than using the terminal, then I think you can use echo to send text to the Arduino, like this:
Code: Select all | TOGGLE FULL SIZE
echo "some text" > /dev/tty.usbmodem621


Cheers!
User avatar
stephanie
 
Posts: 295
Joined: Sat Dec 11, 2010 12:17 am
Location: Canada

Re: Using Terminal for Serial Commands

by cstratton on Sat Nov 19, 2011 8:46 pm

If using those data-only solutions you may need to use something like stty to set the baud rate for the computer end if it hasn't been previously set by running something such as the arduino IDE since boot.

There may also be tty control bit settings which could cause unintended auto resets to the bootloader on port open/close.
User avatar
cstratton
 
Posts: 253
Joined: Wed Sep 29, 2010 2:52 pm

Re: Using Terminal for Serial Commands

by ckeyes on Sun Nov 20, 2011 12:54 am

screen /dev/tty.usbmodemb21

returns a "Sorry, could not find a PTY"

Any help?

Thanks,

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am

Re: Using Terminal for Serial Commands

by cstratton on Sun Nov 20, 2011 1:26 am

Hmm, not having a mac to play with... that does look like the usual syntax on unix-ish systems though

are you sure that the specified device file is (still) the correct one for the arudino?

What do you get if you ls -l that device file?

Does the arduino IDE or its serial monitor still have the port open

IIRC macs don't have the issue with non-root users accessing usb peripheral device files that cause us to write udev rules on linux

Just thinking out loud...
User avatar
cstratton
 
Posts: 253
Joined: Wed Sep 29, 2010 2:52 pm

Re: Using Terminal for Serial Commands

by jamesc4s on Sun Nov 20, 2011 9:30 am

ckeyes wrote:./arduino-serial -b 9600 -p /dev/tty.usbmodemb21 -d 2000 -s a

That particular command has as error, " No such file or directory".

Not a surprise, there is no command called "arduino-serial".

ckeyes wrote:screen /dev/tty.usbmodemb21

type:
screen /dev/tty.usbmodem<TAB>

<TAB> is the auto-completion for bash. once the file name / serial handle is completed add 9600 to the end of the command line.

Once screen is running, press <CTRL>-A, <CTRL>-\ to exit.
User avatar
jamesc4s
 
Posts: 115
Joined: Sun Sep 26, 2010 10:49 pm
Location: Austin, TX

Re: Using Terminal for Serial Commands

by ckeyes on Sun Nov 20, 2011 12:30 pm

Thanks James, but you lost me. Not sure what you mean by this: "once the file name / serial handle is completed add 9600 to the end of the command line."

Sorry, complete noob at this.

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am

Re: Using Terminal for Serial Commands

by jamesc4s on Sun Nov 20, 2011 3:51 pm

Sorry, then you probably shouldn't be mucking around in the terminal.

What were you trying to do at a high level?
User avatar
jamesc4s
 
Posts: 115
Joined: Sun Sep 26, 2010 10:49 pm
Location: Austin, TX

Re: Using Terminal for Serial Commands

by ckeyes on Sun Nov 20, 2011 5:47 pm

Simply send the Arduino an "a".

Carl
ckeyes
 
Posts: 36
Joined: Tue Oct 11, 2011 1:19 am