Programing a 16 Chanel Adafruit Servo shield connected to my Arduino Uno

Background:

My father and I have jumped into the deepens and are creating a humanoid head which eyes and eye lids move individually. The reason for this is that I am off to University in September and will be working with Arduino and adafruit boards along with C++ and Python to create new technologies within the Digital media sector.

Just got used to using the Arduino Uno and its compiler using the Servo.h library. This system is simple to work with as you address the pins and work the movement of the servo in degrees.

My Challenge (don’t like saying problem them)!

In order to operate 3 servos individually we were recommended to use a Adafruit servo shield. Purchased this and learnt how to connect it up to the Arduino Uno board and work 1 servo using the sample code provided.

However I have been through the internet trying to find how to connect multiple servos with not much luck. The same with converting the degree angles we already using to pulses.

Question:

Does any people here have the necessary knowledge to help me.

C++ Code I compiled with hope to use on the Arduino, in order to give you some idea as to what I am trying to achieve.

// Name: Katia Humanoid Robotic Head Project
// Version: Version 1.1
// Created on: 11-May-2017
// Created by: David W Bullock
// Last Updated: 11-May-2017

// UPDATE INDEX
// =============

// Date of Update Updated by Line # Section Reason
// =========================================================================================================================================================================================
// 11-May-2017 David W Bullock N/a All Project creation date - to create the code that would best drive the prototype eye pod which will control the 3
// servos that inturn controls the eye lid, and eye’s verticle and horizontal movement.
// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// =========================================================================================================================================================================================

// Including the required librarys

#include <Servo.h> // This includes the Adafruit ‘servo’ library

// Setting up the required servo variables.

Servo eyeLid; // This sets up the variable for the eyeLid (to control the verticle - open and close - movement
Servo eyeVer; // This sets up the variable for the eye’s verticle (Ver) movement - up and down
Servo eyeHor; // This sets up the variable for the eye’s horizontal (Hor) movement - left and right

// Attaching individual servos to relevant pins on the arduino Uno board

void setup() {
eyeLid.attach(0); // Attaches the eyeLid servo to Pin 0 on the arduino uno board
eyeVer.attach(1); // Attaches the eyeVer servo to Pin 1 on the arduino uno board
eyeHor.attach(2); // Attaches the eyeHor servo to Pin 2 on the arduino uno board
}

// Seting up the integers

int centerPos = 90; // This integer sets up the central position to 90 degrees
int eyeLidOpen = 70; // This integer sets the eye lid open positon to 70 degrees
int eyeLidClose = 110; // This integer sets the eye lid closed positon to 110 degrees
int eyeUp = 70; // This integer sets the eye up stop position as 70 degrees
int eyeDown = 110; // This integer sets the eye down stop positon as 110 degrees
int eyeLeft = 70; // This integer sets the eye left stop positon as 70 degrees
int eyeRight; // This integer sets the eye right stop position as 110 degrees

// Servo work flow command lines

void loop() {
// This code makes the eye pod work - eye lids open and close and the eye move up, down, left and right in a set order

eyeLid.write(eyeLidOpen); // This opens the eye lid
delay(500); // This gives the servo 500ms to complete action

eyeVer.write(eyeLeft); // This moves the eye position to the leftu7
delay(500); // This gives the servo 500ms to complete action

eyeVer.write(centerPos); // Returns eye to the centre position
delay(500); // This gives the servo 500ms to complete action

eyeHor.write(eyeUp); // This moves the eye position to the up position
delay(500); // This gives the servo 500ms to complete action

eyeHor.write(eyeDown); // This moves the eye position to the down position
delay(500); // This gives the servo 500ms to complete action

eyeHor.write(centerPos); // This moves the eye positoin to the centre positon
delay(500); // This gives the servo 500ms to complete action

eyeLid.write(eyeLidClose); // This closes the eye lid.

// Once these commands have been completed the program will loop until stopped.

}

It is not a good idea to use pins 0 and 1 as they are needed for serial communication with your PC - including uploading programs.

An Uno can operate up to 12 servos without needing an shield - but the servos do need their own power supply and the shiled might simplify that.

If you want a responsive program you must get rid of all the delay()s. Have a look at how millis() is used to manage timing without blocking in Several things at a time

It may also be useful to look at Planning and Implementing a Program

...R