Using an external file to set servo position (Arduino+Processing)

Hi guys,
I’m new to this stuff so please bare with me.
Basically I’m trying to get a servo to move to a position indicated on an external file. The idea is to use Processing to read the file, send the position through serial to Arduino, and the Arduino turns the servo.

Here’s the Arduino code;

#include <Servo.h>

Servo myservo;
int fileInput;
int servoPin = 9;

void setup()


void loop()
while (Serial.available() == 0);
fileInput =;

And here’s the Processing code;

import processing.serial.*;

String lastPos;
int startVal;

int count=0;

Serial port;

void setup()
port = new Serial(this, “COM5”, 9600);
lastPos = loadStrings(“lastPos.txt”);
startVal = int(split(lastPos[0], ‘,’)); // convert string to integer

void draw()

Any help/pointers on how to do this?

The Processing application opens a file. We have no idea what is in that file.

It reads all the records in that file, into an array of Strings.

It splits the first String, at the commas, into an array of Strings, and converts the Strings to ints.

It sends the first one to the Arduino immediately after resetting the Arduino (opening the serial port does that).

The Arduino gets at most one value, which you read and print. Then, you wait for more values to arrive (none ever will) before reading the value and moving the servo.

Now that you know what is wrong, you'll need to decide how to fix the problem(s).