Adafruit 16 channel PWM Servo Shield

I need help with Adafruit 16PWM shield.
I connected 6 Analog Feedback Servos to 16PWM Shield
and I would like to record Servos movements an replay them back.
Any help is welcomed.
I used the following code:

// Example code for recording and playing back servo motion with a 
// analog feedback servo

#include <Servo.h>
#include <EEPROM.h>

#define CALIB_MAX 512
#define CALIB_MIN 100
#define SAMPLE_DELAY 25 // in ms, 50ms seems good

uint8_t recordButtonPin = 12;
uint8_t playButtonPin = 7;
uint8_t servoPin = 9;
uint8_t feedbackPin = A0;
uint8_t ledPin = 13;

Servo myServo;  
void setup() {
  pinMode(recordButtonPin, INPUT);
  digitalWrite(recordButtonPin, HIGH);
  pinMode(playButtonPin, INPUT);
  digitalWrite(playButtonPin, HIGH);
  pinMode(ledPin, OUTPUT);
  Serial.println("Servo RecordPlay");

void loop() {
 if (! digitalRead(recordButtonPin)) {
   // wait for released
   while (! digitalRead(recordButtonPin));
   // OK released!
   recordServo(servoPin, feedbackPin, recordButtonPin);
  if (! digitalRead(playButtonPin)) {
   // wait for released
   while (! digitalRead(playButtonPin));
   // OK released!
   playServo(servoPin, playButtonPin);

void playServo(uint8_t servoPin, uint8_t buttonPin) {
  uint16_t addr = 0;

  while (digitalRead(buttonPin)) {    
    uint8_t x =;
    Serial.print("Read EE: "); Serial.print(x);
    if (x == 255) break;
    // map to 0-180 degrees
    x = map(x, 0, 254, 0, 180);
    Serial.print(" -> "); Serial.println(x);
    if (addr == 512) break;

void recordServo(uint8_t servoPin, uint8_t analogPin, uint8_t buttonPin) {
  uint16_t addr = 0;
  digitalWrite(ledPin, HIGH);

  pinMode(analogPin, INPUT); 
  while (digitalRead(buttonPin)) {
     uint16_t a = analogRead(analogPin);
     Serial.print("Read analog: "); Serial.print(a);
     if (a < CALIB_MIN) a = CALIB_MIN;
     if (a > CALIB_MAX) a = CALIB_MAX;
     a = map(a, CALIB_MIN, CALIB_MAX, 0, 254);
     Serial.print(" -> "); Serial.println(a);
     EEPROM.write(addr, a);
     if (addr == 512) break;
  if (addr != 512) EEPROM.write(addr, 255);

  digitalWrite(ledPin, LOW);


Well that only records one analog channel and you said you had 6. Writing EEPROM is slow, you do know this? Calling delay isn't a great idea - if you want accurate sample timing you'll need to schedule samples, not delay between them.

And I don't see how you can record when the servos are active, they will simply hold position? Or are these special servos?

yes they are special Analog Feedback Servos 1213
I’ struggling wit PWM 16.
I would be happy at this stage with only one servo.

Shake the EEPROM...

But what adafruit PWM shield are you using? I have one that has the I2C interface. So you need to control it by, you guessed it, I2C. I made a small subroutine to control my PWM shield:

void sendWire(int Addr, int Data)
    long value = map(Data, 0x00, 0xFF, 0x0180, 0x02E7);
    Wire.write(0x06 + (Addr*4));

where Addr is the PWM channel address, and Data is the PWM value from 0 to 255. I added the map() function because the motors I used have a specific range of PWM to operate with (Linear motors from some weird company...)

EDIT: I have this one:

EDIT 2: I forgot, you need to set the PWM shield before using it. I have used:

  setWire(0x00, 0x11);
  setWire(0xFE, 0x47);    //0x3F worked-ish
  setWire(0x00, 0x20);

void setWire(int Addr, int Data)

But check the datasheet for your own parameters!

yes I have Adafruit 16-channel PWM/Servo Shield over 12C

novio8: yes I have Adafruit 16-channel PWM/Servo Shield over 12C

But you haven't got any I2C commands in your code, or the adafruit PWM shield library... I'd say, start there?


Just to be sure, the library can be downloaded here:

And there are also some examples to follow.