I am trying to control some stepper motors using an app I am writing in Objective-C and my Arduino board. I use popen to send a byte (the letter a) to my Arduino and count the steps taken (Xc):
-(IBAction)PlusX:(id)sender{
popen("echo a > /dev/tty.usbmodem621", "r");
Xc = Xc +1;
_lXc.stringValue = @(Xc);
[NSThread sleepForTimeInterval:0.16f];
}
My Arduino reads this in the void loop and makes a step.
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
Serial.println(incomingByte);
if(incomingByte == 'a'){
MotorX->step(1, FORWARD, SINGLE);
}
}
This al works pretty much as expected. Except after byte/step/action 144 the Objective-C app keeps counting the steps correctly, however they don't appear in Arduino's serial monitor and the motor stops making steps. Is there anybody who knows why this keeps happening?
Thanks
popen()to communicate via serial. Open the tty via NSFileHandle or NSStream, then write the bytes to it as needed. - bbum