I'm honestly not sure how it compiles -- I don't think println can work like that (concatenating a string and an int, it's likely using the address and making a real memory mess instead). Try updating these two lines:
Code:
Serial.println("servoNum:"+servoNum);
Serial.println("servoPos:"+servoPos);
To this:
Code:
Serial.print("servoNum:");
Serial.println(servoNum);
Serial.print("servoPos:");
Serial.println(servoPos);
Also, you're sending ascii -- which is not the same as a binary number, so you have to change these lines:
Code:
servoNum = cmd[0]*10 + cmd[1];
servoPos = cmd[3]*1000 + cmd[4]*100 + cmd[5]*10 + cmd[6];
To something like this:
Code:
servoNum = (cmd[0]-48)*10 + (cmd[1]-48);
servoPos = (cmd[3]-48)*1000 + (cmd[4]-48)*100 + (cmd[5]-48)*10 + (cmd[6]-48);
Because the ASCII representation of 0 is 48, and 1 is 49, etc..
-Fergs
Bookmarks