Serial Port fails after minutes of operation

Hi.

Please watch the video below.

So it's Leap Motion(hand position)-> Processing -> Arduino-> two servo motors(speed control).

Arduino Uno, Ada Fruit motor shield with 12V external power are used.

It works, but looks like Serial port fails after a minute (time varies) and arduino port disappears.

Works fine when relaunch processing script or USB cable replugged.

Is there a possibility that motors drain too much current from USB port despite the external power source and the computer shuts it down? It's Macbook Pro + OSX.

Thanks in advance.

================================================================
processing code

import com.onformative.leap.;
import com.leapmotion.leap.
;
import processing.serial.*;

PVector hand1_Pos = new PVector();
PVector hand2_Pos = new PVector();

ArrayList hands;

LeapMotionP5 leap;

int z[]=new int[2];

Serial port;

void setup() {
size(700, 700);
leap = new LeapMotionP5(this);

// set com port.
println("Available serial ports:");
println(Serial.list());
String portName = Serial.list()[2];
port = new Serial(this, portName , 57600);
}

void draw() {
hands = leap.getHandList();

background(0);
hand1_Pos = leap.getPosition(leap.getHand(0));
z[0]=(int)hand1_Pos.y;

fill(255,0,0); //Red
ellipse(hand1_Pos.x, hand1_Pos.y, 20, 20);

if(hands.size()>1){ // to prevent IndexOutOfBoundsException error
hand2_Pos = leap.getPosition(leap.getHand(1));
z[1]=(int)hand2_Pos.y;

fill(0,255,0); //Green
ellipse(hand2_Pos.x, hand2_Pos.y, 20, 20);
}

for (int i=0; i<z.length; i++){
port.write(z*);*

  • }*

  • println(z[0]+" , "+z[1]);*

}
================================================================
arduino code
================================================================
#include <Servo.h>
Servo myServoL;
Servo myServoR;
int angleL, angleR ;
int valR, valL;
void setup() {

  • Serial.begin(57600);*

  • myServoL.attach(9);*

  • myServoR.attach(10);*

  • myServoL.write(0);*

  • myServoR.write(0);*
    }
    void loop() {

  • byte z1=0;*

  • byte z2=0;*

  • if (Serial.available()) {*

  • // Read values from Processing*

  • z1 = Serial.read();*

  • if(Serial.available()>2){*

  • z2 = Serial.read();*

  • }*

  • // servo*

  • valL = (int)map(z1,0,700, 1, 10); // lower pitch string*

  • valR = (int)map(z2,0,700, 1,10);*

  • for(angleL=70; angleL<100; angleL+=valL){*

  • myServoL.write(angleL);*

  • delay(10);*

  • }*

  • for(angleR=70; angleR<100; angleR+=valR){*

  • myServoR.write(angleR);*

  • delay(10);*

  • }*

  • for(angleL=100; angleL>=70; angleL=-valL){*

  • myServoL.write(angleL);*

  • }*

  • for(angleR=100; angleR>=70; angleR=-valR){*

  • myServoR.write(angleR);*

  • }*

  • }*
    }

Please edit your post and put your sketch in code tags (See item 7 here)

Is there a possibility that motors drain too much current from USB port despite the external power source and the computer shuts it down? It's Macbook Pro + OSX.

Yes.
But it is more likely that interference from the motors is causing something to reset.
Try extra decoupling capacitors across the servo and an inductor in seriese with each servo mounted close to the motor.