Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cloudydayagain

macrumors newbie
Original poster
May 17, 2015
10
0
I have Arduino Uno connected via USB to my Mac (Yosemite).

I try to get sensor data to Mac.

This works in Terminal app:

Code:
screen /dev/cu.usbmodem14131 9600

I tried to run this in AppleScript Editor and it gives error "must be connected to a terminal":

Code:
do shell script "screen /dev/cu.usbmodem14131 9600"
 
Last edited by a moderator:

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
Is there just the one line in your AppleScript? Or is it part of a larger script?

If it's part of a larger script, please post the whole thing, and please use CODE tags.

If that's the only line in the AppleScript, then it can't possibly work because there's no way you can input or output anything to it. The 'screen' command requires a tty, either a real character device or a pseudo-tty. A Terminal window is normally opened to a pseudo-tty, whose name is like ttyp1. That 'p' in the name means a pseudo-tty.


You should probably describe your goal or intention, i.e. what you want to achieve or accomplish, rather than posting how you're trying to achieve it.

If we know what your goal is, we may be able to tell you how to achieve it. Not knowing the goal, all anyone can do is tell you why what you posted didn't work. The brief description you gave is too vague. "I try to get sensor data to Mac." doesn't say anything about the context of the sensor data.

For example, if your goal is to have a double-clickable AppleScript that opens a Terminal window and runs 'screen' to connect to your Arduino, that's a clear and attainable goal. But it's also a completely different goal than making an AppleScript that automatically tells the Arduino to do something.
 

cloudydayagain

macrumors newbie
Original poster
May 17, 2015
10
0
Is there just the one line in your AppleScript? Or is it part of a larger script?

Code:
do shell script "screen /dev/cu.usbmodem14131 9600 >> path_to_text_file.txt"

This is part of script. Everything else works but i have never used screen before and never communicated with serial/terminal/tty things and it fails. Path to text file is okay too.

I want to get sensor data from Arduino Uno to text file in my Mac. I don't want to use SD-card in Arduino for logging in this case.

Connection between Arduino and Mac works because i can see sensor data in Arduino serial window and Mac Terminal app.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Code:
do shell script "screen /dev/cu.usbmodem14131 9600 >> path_to_text_file.txt"
This is part of script. Everything else works but i have never used screen before and never communicated with serial/terminal/tty things and it fails. Path to text file is okay too.

I want to get sensor data from Arduino Uno to text file in my Mac. I don't want to use SD-card in Arduino for logging in this case.

Connection between Arduino and Mac works because i can see sensor data in Arduino serial window and Mac Terminal app.

If you have no intention of using a terminal, why are you using screen? As mentioned, screen requires a terminal.
 

cloudydayagain

macrumors newbie
Original poster
May 17, 2015
10
0
If you have no intention of using a terminal, why are you using screen? As mentioned, screen requires a terminal.

I didn't know screen is not suitable in this case.

What i should use and what is correct code which works? Thanks
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
I checked out cat manual and it talks about reading files.

Arduino sends stream of data.

Yeah, and what do you think /dev/cu.usbmodem14131 is? It's a file. So have you tried cat? You should be able to do this in Terminal directly, the only question about launching this from Applescript is if the script waits indefinitely and then kills cat when aborted.
 

cloudydayagain

macrumors newbie
Original poster
May 17, 2015
10
0
Yep. In Unix, everything is a file. So try:

Code:
cat /dev/cu.usbmodem14131 > /path/to/file.txt

I get this error:

cat: /dev/cu.usbmodem14131: No such file or directory
cat: 9600: No such file or directory

Maybe this 9600 is baud rate and it is wrong?
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
I get this error:

cat: /dev/cu.usbmodem14131: No such file or directory
cat: 9600: No such file or directory

Maybe this 9600 is baud rate and it is wrong?

But you said that this file worked with 'screen' in your first post. Perhaps try: ls /dev/cu.* and see what comes up.

9600 is baud rate, but it's an argument to 'screen' so you don't need that now.
 

cloudydayagain

macrumors newbie
Original poster
May 17, 2015
10
0
But you said that this file worked with 'screen' in your first post. Perhaps try: ls /dev/cu.* and see what comes up.

9600 is baud rate, but it's an argument to 'screen' so you don't need that now.

Thanks. Works but not.

Number in name of modem seems to change now and then so after i used this:

do shell script "cat /dev/cu.usbmodem1413 9600 >> " & path_to_text_file

Then AppleScript Editor script logged to text file, but then i saw in network preferences 2 usb modems so i deleted both. When i connected Uno i didn't get dialog saying new network interface detected. After i tried different USB-cables without usb-hub i got new usb modem to network preferences (without dialog) but it's "not configured" so i'm not sure is that okay?

Port menu shows: cu.usbmodem1413 (Arduino Uno)

Sensor data comes okay to Arduino IDE serial window but now if i try this in AppleScript Editor

do shell script "cat /dev/cu.usbmodem1413 9600 >> " & path_to_text_file

i still get same error:

cat: /dev/cu.usbmodem1413: No such file or directory
cat: 9600: No such file or directory
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Thanks. Works but not.

Number in name of modem seems to change now and then so after i used this:

do shell script "cat /dev/cu.usbmodem1413 9600 >> " & path_to_text_file

Then AppleScript Editor script logged to text file, but then i saw in network preferences 2 usb modems so i deleted both. When i connected Uno i didn't get dialog saying new network interface detected. After i tried different USB-cables without usb-hub i got new usb modem to network preferences (without dialog) but it's "not configured" so i'm not sure is that okay?

Port menu shows: cu.usbmodem1413 (Arduino Uno)

Sensor data comes okay to Arduino IDE serial window but now if i try this in AppleScript Editor

do shell script "cat /dev/cu.usbmodem1413 9600 >> " & path_to_text_file

i still get same error:

cat: /dev/cu.usbmodem1413: No such file or directory
cat: 9600: No such file or directory

Then there is no file called /dev/cu.usbmodem1413, it's not related to cat, you would get the same error with screen.

Both 'screen' and 'cat' are programs, each of them takes arguments, like a file name. In the case of 'screen' it accepts a boud rate argument, cat does not. That's why cat is looking for a file called 9600, there is no such file, and it makes no sense to call 'cat' with 9600 since it's a 'screen' argument.
 

cloudydayagain

macrumors newbie
Original poster
May 17, 2015
10
0
Then there is no file called /dev/cu.usbmodem1413, it's not related to cat, you would get the same error with screen.

Both 'screen' and 'cat' are programs, each of them takes arguments, like a file name. In the case of 'screen' it accepts a boud rate argument, cat does not. That's why cat is looking for a file called 9600, there is no such file, and it makes no sense to call 'cat' with 9600 since it's a 'screen' argument.

Thanks. I have learned lots of new things in past few days about unix.

After i removed 9600, i still get error: "cat: /dev//dev/cu.usbmodem1413: No such file or directory"
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Thanks. I have learned lots of new things in past few days about unix.

After i removed 9600, i still get error: "cat: /dev//dev/cu.usbmodem1413: No such file or directory"

Well, then the file doesn't exist. But as you noted earlier this file appears under slightly different names. But you can list all files called /dev/cu.usbmodem* with a wildcard added.

Code:
ls /dev/cu.usbmodem*

And it may even work to use that wildcard in your 'cat' line, assuming you have one Arduino connected (haven't tried this, but you can). Cat, short for concatenate will concatenate all files to the log. But look for the correct name of the device file first.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,750
8,422
A sea of green
After i removed 9600, i still get error: "cat: /dev//dev/cu.usbmodem1413: No such file or directory"

That command will never work. Look very carefully at the name:
/dev//dev/cu.usbmodem1413
The part I hilited in red shouldn't be there.

If that wasn't exactly what the actual error message was, then you mistyped it in your post. If that was the exact error message, then you should take more care with what command you type or paste in.

When posting error message, please copy and paste them exactly as they appear. It would also be a good idea to copy and paste the exact command you used, rather than retyping it in a post.

Accuracy is important.
 

mfram

Contributor
Jan 23, 2010
1,307
343
San Diego, CA USA
Without using screen you may have to configure the serial port before using cat. You'd do that with the 'stty' command.

To print the confiugration:

Code:
stty -a -f /dev/cu.usbmodem1413

You may have to set the configuration:

Code:
stty -f /dev/cu.usbmodem1413 9600
 

sero

macrumors member
Aug 28, 2008
91
14
what is the screen command you guys are talking about. It can't be GNU screen..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.