0

This question already has an answer here:

So I am trying to make a Mac OSX program with Cocoa that will be able to control my Arduino via serial. I currently have the C command

popen("echo 7 > /dev/cu.usbmodem1411", "r");

to try to send the number 7 over serial to the Arduino. I know that the path /dev/cu.usbmodem1411 is correct because the Arduino is responding, however it seems to "crash" or simply restart whenever this command is received from the Mac. Sorry this may be a question for StackOverflow, but I thought I would start here.

marked as duplicate by Chris Stratton, Madivad, TheDoctor, The Guy with The Hat, Nick Gammon Jan 11 '16 at 9:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Nope, doesnt seem to do the trick – woakley5 Nov 17 '15 at 0:05
  • Are you sure you are sending "the number 7"? I don't know how echo on the Mac works, but are you sending a string with the character '7' in or ASCII 7 or integer 7. And how are you reading it at the other end? – Code Gorilla Nov 17 '15 at 3:50
  • @Matt I'm actually not sure, is there a better way to do this? I was attempting to send an integer 7 – woakley5 Nov 17 '15 at 16:46
  • @woakley5 I would guess that you are sending ASCII character 7. Can you use SoftSerial on the Arduino, and change you program to echo the data received from the Mac. Echo the byte values received, not the characters, because if you print 7 it ring the bell :) – Code Gorilla Nov 17 '15 at 19:57
  • 1
    Despite the poster's denial, this is in fact a duplicate of the reset-on-open issue, and especially now that they seem to have abandoned the question, closing it as a duplicate (as it originally should have been) is the only way we are going to stop it from being periodically churned back up. – Chris Stratton Dec 19 '15 at 14:57
0

I think the problem is more going to be that you don't have a serial connection to the arduino. ie, if you look in the Arduino IDE, you assign a serial port to the application. When you upload your sketch, a connection is made, the arduino resets (by design) and your sketch is uploaded.

What it appears you are doing here is opening a new connection and sending the character (which is ASCII) which in turn sends the arduino into reboot to look out for a sketch being uploaded.

I'm not familiar with popen and maybe you can use it and keep the connection open and even monitor the data stream, but I would say instead of writing directly to the device as you've done, use an application that will initialise the port properly (ie open it and leave it open) so that you can continue to use/monitor it.

A quick google search has brought up Mike's PBX Cookbook which has some good info about it. I've personally used minicom (a guide for installing minicom) and CoolTerm, I have used Screen but it was so long ago I don't remember why I moved on.

edit: I just followed the link submitted by the first commenter (sorry name not available in the edit screen), and although you've responded with "that's not it", it actually is, you just haven't realised it since your popen command is actually opening the port and triggering the RTS mentioned in that post

  • Automatic activation of the modem control signals (which trigger the reset) is something which the host operating system can be configured to do or not do. – Chris Stratton Nov 20 '15 at 6:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.