UNO R3 Board - Servo controller help

Hi all, I am a complete novice and would very much appreciate some advice on the following project I wish to start please.

I have a fully anatomical skeleton, I want to add two standard size servos, one to move the jaw up/down and one to move the head left/right.

I also want to add voice(s) to the routine, so I can make the skeleton say a phrase with basic lip sync, as its a skeleton lip sync does not have to be perfect.

I have purchased an UNO R3 board and two Servos with the appropriate ‘kg’ rating for my project.

However, I have no idea how to program this board, I was hoping to be able to use a piece of software like VSA or equivalent but from what I can see I need to upload a piece of code to my UNO to emulate a Maestro board to do this?

I have been unable to successfully compile the code I found pasted below, it gives errors:-


// Serial Servo
// by Paul H. Dietz, 4/22/2014
//
// Allows an Arduino UNO to act like a Scott Edwards Mini Serial Servo Controller.
//
// Data Format:
//
// 9600 baud, 8-N-1
//
// Sync byte (255), Servo Num (2-13), Postion (0-254)
//
// Position to us:
//
// 6 * Position + 738
//
// 0 → 738us, 254 → 2262us
//
// This code is in the public domain. Use at your own risk.

#include <Servo.h>

byte ServoNum, ServoPos;

// Byte count for input
byte inCNT=0;

// create servo objects
Servo servo2, servo3, servo4, servo5, servo6, servo7, servo8, servo9, servo10, servo11, servo12, servo13;

void setup()
{
// Initialize serial:
Serial.begin(9600);

// Initialize Servos
servo2.attach(2);
servo3.attach(3);
servo4.attach(4);
servo5.attach(5);
servo6.attach(6);
servo7.attach(7);
servo8.attach(8);
servo9.attach(9);
servo10.attach(10);
servo11.attach(11);
servo12.attach(12);
servo13.attach(13);

}

/* Wait for data, then process

inCNT keeps track of current state:

0 – Waiting for sync byte
1 – Sync byte received
2 – Sync byte and ServoNum received

*/
void loop() {
while (Serial.available()) {
// get the new byte:
byte inByte = Serial.read();
if (inByte == 255){
// Sync found
inCNT = 1;
}
else {
if (inCNT == 1) {
ServoNum = inByte;
inCNT = 2;
}
else {
if (inCNT == 2) {
ServoPos = inByte;
setServo();
inCNT = 0;
}
else {
inCNT = 0;
}
}
}
}
}

void setServo() {

switch (ServoNum) {
case 2:
servo2.writeMicroseconds((int)ServoPos6+738);
break;
case 3:
servo3.writeMicroseconds((int)ServoPos
6+738);
break;
case 4:
servo4.writeMicroseconds((int)ServoPos6+738);
break;
case 5:
servo5.writeMicroseconds((int)ServoPos
6+738);
break;
case 6:
servo6.writeMicroseconds((int)ServoPos6+738);
break;
case 7:
servo7.writeMicroseconds((int)ServoPos
6+738);
break;
case 8:
servo8.writeMicroseconds((int)ServoPos6+738);
break;
case 9:
servo9.writeMicroseconds((int)ServoPos
6+738);
break;
case 10:
servo10.writeMicroseconds((int)ServoPos6+738);
break;
case 11:
servo11.writeMicroseconds((int)ServoPos
6+738);
break;
case 12:
servo12.writeMicroseconds((int)ServoPos6+738);
break;
case 13:
servo13.writeMicroseconds((int)ServoPos
6+738);
break;
}
}


Any help you can offer with how to fix the above code and/or what software or process I can use to complete my project would be very much appreciated.

Many thanks in advance for your help and time,

Wayne.

Please read the forum rules - how to use this forum.

Then edit the first post to put your code in code tags like requested.

Then we can try it out on our own machine without the forum software mangling the code, did you put a smiley in sunglasses? No.

That is rather crap code anyway. But we can show you how to make it better when it is posted correctly.

Why do you say 2 servos with code for 12 servos.
Maybe scrap that crap code and start by learning how to control one.

Why do you ask in the forum, when your compiler finds and explains errors in your code?

If you don't know what to do with the error messages, please post them, so that we can know more about your problems.

DrDiettrich:
Why do you ask in the forum, when your compiler finds and explains errors in your code?

Because there are no compiler errors in that code, so I am not sure what he is on about.

Anyway I did unstupidfy it so here it is:-

// Serial Servo
// by Paul H. Dietz, 4/22/2014 - cleaned up and unstupidfied my Grumpy_Mike 30/10/2016 ( UK date format )
//
// Allows an Arduino UNO to act like a Scott Edwards Mini Serial Servo Controller.
//
// Data Format:
//
// 9600 baud, 8-N-1
//
// Sync byte (255), Servo Num (2-13), Postion (0-254)
//
// Position to use:
//
// 6 * Position + 738
//
// 0 -> 738us, 254 -> 2262us
//
// This code is in the public domain. Use at your own risk.

#include <Servo.h>

byte ServoNum, ServoPos;

// Byte count for input
byte inCNT = 0;

// create servo objects
Servo servos[12];
byte servoPin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};  // define what pins the servo is on

void setup()
{
  // Initialize serial:
  Serial.begin(9600);

  // Initialize Servos
  for(int i =0; i<8; i++){
    servos[i].attach(servoPin[i]);  // attaches the servo on pin 2 to the servo object [0]
  }

}

/* Wait for data, then process
  inCNT keeps track of current state:
  0 - Waiting for sync byte
  1 - Sync byte received
  2 - Sync byte and ServoNum received
*/

void loop() {
  while (Serial.available()) {
    // get the new byte:
    byte inByte = Serial.read();
    if (inByte == 255) {
      // Sync found
      inCNT = 1;
    }
    else {
      if (inCNT == 1) {
        ServoNum = inByte;
        inCNT = 2;
      }
      else {
        if (inCNT == 2) {
          ServoPos = inByte;
          setServo();
          inCNT = 0;
        }
        else {
          inCNT = 0;
        }
      }
    }
  }
}

void setServo() {
      servos[ServoNum].writeMicroseconds((int)ServoPos * 6 + 738);
}

@Grumpy_Mike

Thanks for fixing/tidying the code I posted, I have just successfully compiled it. I assume it was some form of syntax error as you you state it was poorly coded.

@Everyone else who replied

As I stated in my post, and I apologise for not following your rules on pasting code, I was unaware of it or would have followed the guidelines, I am a novice and NOT a programmer or coder. If I were I would probably not have needed to ask the question I did but I have to say, I have used many forums for help over the years in many different areas and topics but have never been so berated by the experts who seem more interested in belittling someone who is asking for your help than actually helping with the question.

I offer my thanks to Grumpy_Mike once more for taking the time to tidy my pasted code which now works, thank you it is very much appreciated.

I won't however make the mistake of posting any more questions or requests for help on this forum in the future, if you don't want to help people or have no patients with people who know nothing, what are you doing here?

Kind Regards,

Wayne.

P.S. The Smiley in sunglasses is how this forum software depicts a number 8 in brackets with a semi colon at the end, not put in by myself.