ISR-based Servo Controller Library for ESP8266 (ESP8266_ISR_Servo)

Just created a new ISR-based library enabling you to use 1 Hardware Timer on an ESP8266-based board to control 16-or-more independent servo motors. It’s quite simple to use.

Will soon expand to ESP32 and Arduino Mega, UNO, Nano, etc.

Here is the sample code

#define TIMER_INTERRUPT_DEBUG       1
#define ISR_SERVO_DEBUG             1

#include "ESP8266_ISR_Servo.h"

int servoIndex1  = -1;
int servoIndex2  = -1;

void setup() 
{
  Serial.begin(115200);
  Serial.println("\nStarting");

  servoIndex1 = ISR_Servo.setupServo(D8);
  servoIndex2 = ISR_Servo.setupServo(D7);
  
  if (servoIndex1 != -1)
    Serial.println("Setup Servo1 OK");
  else
    Serial.println("Setup Servo1 failed");

  if (servoIndex2 != -1)
    Serial.println("Setup Servo2 OK");
  else
    Serial.println("Setup Servo2 failed");
}

void loop() 
{
  int position;

  if ( ( servoIndex1 != -1) && ( servoIndex2 != -1) )
  {
    for (position = 0; position <= 180; position++) 
    { 
      // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      ISR_Servo.setPosition(servoIndex1, position);
      ISR_Servo.setPosition(servoIndex2, 180 - position);
      // waits 15ms for the servo to reach the position
      delay(50  /*15*/);
    }
    
    for (position = 180; position >= 0; position--) 
    { 
      // goes from 180 degrees to 0 degrees
      ISR_Servo.setPosition(servoIndex1, position);
      ISR_Servo.setPosition(servoIndex2, 180 - position);
      // waits 15ms for the servo to reach the position
      delay(50  /*15*/);                                  
    }
  }
}

Updated: Dec 17th 2019

ESP8266_ISR_Servo libraries v1.0.1 just got included into Arduino Library Manager.
Now you can install this library directly from Arduino Library Manager.

Updated: Dec 20th 2019

New ESP8266_ISR_Servo libraries v1.0.2 with new example using Blynk widgets to control servos.

Updated Dec 29th 2019

Included in Platform.io

2 Likes