This example does not execute as I expected

the 2nd time around.
At least not to my noob eyes.
The example sketch is “servo” under Adafruit PWM Servo Driver Library
My board is a NODEMCU.

It works fine the 1st time around and the servos move properly, but as limits are reached, and the counters are reset, and the sketch starts over, the servos do not move,
I am curious as to why.

Thanks

/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 8 servos, one after the other on the
  first 8 pins of the PCA9685

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815

  These drivers use I2C to communicate, 2 pins are required to
  interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  150 // This is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // This is the 'maximum' pulse length count (out of 4096)
#define USMIN  600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX  2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates

/*
 Esp.h - ESP8266-specific APIs
 Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
 This file is part of the esp8266 core for Arduino environment.
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

// our servo # counter
uint8_t servonum = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("8 channel Servo test!");

  pwm.begin();
  // In theory the internal oscillator is 25MHz but it really isn't
  // that precise. You can 'calibrate' by tweaking this number till
  // you get the frequency you're expecting!
  pwm.setOscillatorFrequency(27000000);  // The int.osc. is closer to 27MHz
  pwm.setPWMFreq(SERVO_FREQ);  // Analog servos run at ~50 Hz updates

  delay(10);
}

// You can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. It's not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;

  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= SERVO_FREQ;   // Analog servos run at ~60 Hz updates
  Serial.print(pulselength); Serial.println(" us per period");
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit");
  pulse *= 1000000;  // convert input seconds to us
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

void loop() {
  // Drive each servo one at a time using setPWM()
  
  Serial.print("Servo Num  ");
  Serial.println(servonum);
  
  Serial.print("Servo Min ");
  Serial.println(SERVOMIN);
  
  Serial.print("Servo Max ");
  Serial.println(SERVOMAX);
    
    for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) 
    {
      yield();
    pwm.setPWM(servonum, 0, pulselen);
     Serial.print(servonum);
     Serial.print("-");
     Serial.println(pulselen);
      }   
  
  for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) 
  {
    yield();
    pwm.setPWM(servonum, 0, pulselen);
    Serial.print(servonum);
     Serial.print("-");
     Serial.println(pulselen);
     }
  
  // Drive each servo one at a time using writeMicroseconds(), it's not precise due to calculation rounding!
  // The writeMicroseconds() function is used to mimic the Arduino Servo library writeMicroseconds() behavior.
  
  Serial.println("At the microseconds");

  
  Serial.print("Servo Num  ");
  Serial.println(servonum);
  
  Serial.print("Servo USMIN ");
  Serial.println(USMIN);
  
  Serial.print("Servo USMAX ");
  Serial.println(USMAX);
    
    
  for (uint16_t microsec = USMIN; microsec < USMAX; microsec++)
   
  {
    yield();
    pwm.writeMicroseconds(servonum, microsec);
    Serial.print(servonum);
    Serial.print("-");
    Serial.println(microsec);
     }

     for (uint16_t microsec = USMAX; microsec > USMAX; microsec--) 
  {
    yield();
    pwm.writeMicroseconds(servonum, microsec);
    Serial.print(servonum);
    Serial.print("-");
    Serial.println(microsec);
     }

 /* delay(500); */
  /* for (uint16_t microsec = USMAX; microsec > USMIN; microsec--) 
  {
    pwm.writeMicroseconds(servonum, microsec);
  }

  delay(500); */

  servonum++;
  if (servonum > 7) servonum = 0; // Testing the first 8 servo channels
}

What do all the Serial.println()s tell you is happening?

Steve

i didn’t think you could use a PWM output to drive a servo. the [servo control pulse](http://i didn’t think you could use a PWM output to drive a servo. The servo control pulse) is 1-2 msec which would require the PWM freq to be < 250 Hz.

isn’t there a servo library you could use?

gcjr:
i didn’t think you could use a PWM output to drive a servo. The servo control pulse is 1-2 msec which would require the PWM freq to be < 250 Hz.

The Adafruit PCA985 Servo driver doesn’t use hardware PWM (or the Servo library) and the servo signal frequency is controlled by ‘pwm.setPWMFreq(SERVO_FREQ);’ which you can see is set to 50Hz.

Steve

gcjr:
i didn't think you could use a PWM output to drive a servo.

In this case "pwm" is the rather unfortunate name used for an instance of Adafruit_PWMServoDriver

IMHO "servoDriver" would have been a lot more meaningful.

...R