Arduino only does something when serial message is received from Serial Monitor.

Hello all, I'm back with another issue. Right now, I have my arduino hooked up to a motor shield (r3) and I have it polling for serial input. I am basically sending the characters i and o over serial, but I cannot get it to work outside the Serial Monitor. I have an OS X app that sends serial commands that works fine with my Arduino Micro, but doesn't on my Uno.
Code:

//Arduino Control

int ledPin =  13;    // LED connected to digital pin 13
int incomingByte = 0;	// for incoming serial data
int dirA = 12;

int speedA = 3;



// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);
  
   pinMode (dirA, OUTPUT);

  pinMode (speedA, OUTPUT);
 
  Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                     
{
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    Serial.print(incomingByte);
    if(incomingByte == 105){
      digitalWrite (dirA, HIGH);
      analogWrite (speedA, 255);
      delay(600);
   digitalWrite (dirA, LOW);
         analogWrite (speedA, 0);

   
    }
    else if(incomingByte == 111){
   digitalWrite (dirA, LOW);
   
   digitalWrite (dirA, HIGH);
     analogWrite (speedA, 255);
    delay(600);
      analogWrite (speedA, 0);
    }
  }
}

OS X code:

    ORSSerialPort *serialPort = [ORSSerialPort serialPortWithPath:@"/dev/cu.usbmodem1d11"];
    serialPort.baudRate = [NSNumber numberWithInteger:9600];
    [serialPort open];
    NSData *someData;
    _state = characteristic;
    if(characteristic.boolValue == YES){
        NSLog(@"yes!");
        someData = [@"i" dataUsingEncoding:NSUTF8StringEncoding];
      //  popen("echo i > /dev/cu.usbmodem1d11", "r");

    }else{
        NSLog(@"no!");
        someData = [@"o" dataUsingEncoding:NSUTF8StringEncoding];
           // popen("echo o > /dev/cu.usbmodem1d11", "r");

    }
    [serialPort sendData:someData];
    [serialPort close];

[serialPort open];
NSData *someData;
[serialPort sendData:someData];
[serialPort close];
Open the serial port, resetting the Arduino. Without waiting for the Arduino to reset, send it one byte. Then, close the serial port, resetting the Arduino again.

And the Arduino does nothing. I can't imagine why. Can you?

I haven't got a Micro but it may well not be affected by opening and closing the serial port in the way that an Uno or Mega is.

Your OSX code should open the serial port at the start of the session and leave it open until you are finished.

It's a good idea to have the Arduino send a message from setup() - such as Serial..println("Arduino is ready") - and the OSX program should wait for that before trying to send anything.

This demo illustrates the idea.

...R

After you upload your code to the arduino, you could put a 100 ohm resistor between the arduino +5v pin and the arduino reset pin to prevent the arduino from resetting when the pc comport is opened/closed.

    if(incomingByte == 105){

...

else if(incomingByte == 111){

Wouldn't this be a lot easier to read?

    if(incomingByte == 'i'){

...

    else if(incomingByte == 'o'){