Unable to move third servo on Nano ESP32

Hello Everyone. I am new to the forums here. I am trying to control three MG90S servos on an Arduino Nano ESP32 using the ESP32Servo library. The first two servos move fine. However when I attach the third servo via programming, it is unresponsive. I have troubleshot by swapping servos around, and it seems that only two can be controlled at a time, regardless of which write command they are given (eg, Yaw and Roll / Pitch and Yaw ...). Here is the code I am using.

#include <Wire.h>
#include "JY901.h"
#include "ESP32Servo.h"

Servo servoPitch;
Servo servoRoll;
Servo servoYaw;

void setup() 
{
  Serial.begin(9600);
  JY901.StartIIC();
  servoPitch.attach(2);
  servoRoll.attach(3);
  servoYaw.attach(4);
} 

void loop() 
{
  float pitchAngle = ((float)JY901.stcAngle.Angle[0]/32768*180); //Calculation for the Pitch angle
  float rollAngle = ((float)JY901.stcAngle.Angle[1]/32768*180); //Calculation for the Roll angle
  float yawAngle = ((float)JY901.stcAngle.Angle[2]/32768*180); //Calculation for the Yaw angle
  float servoPitchPos = map(-(pitchAngle), -90, 90, 0, 180); // Mapping servos for range of motion
  float servoRollPos = map(-(rollAngle), -90, 90, 0, 180);
  float servoYawPos = map(-(yawAngle), -90, 90, 0, 180);

  servoPitch.write(servoPitchPos); // Commanding servos to move based off of IMU
  servoRoll.write(servoRollPos);
  servoYaw.write(servoYawPos);


  JY901.GetAngle();
    Serial.print("Pitch:");
    Serial.print(pitchAngle);
    Serial.println();
    Serial.print("Roll: ");
    Serial.print(rollAngle);
    Serial.println();
    Serial.print("Yaw: ");
    Serial.println(yawAngle);

    Serial.print("Yaw Servo Position: ");
    Serial.println(servoYawPos);

/* 

JY901.GetLonLat();
  Serial.print("Longitude:");
  Serial.print(JY901.stcLonLat.lLon/10000000);
  Serial.print("Deg");
  Serial.print((double)(JY901.stcLonLat.lLon % 10000000)/1e5);
  Serial.print("m Lattitude:");
  Serial.print(JY901.stcLonLat.lLat/10000000);
  Serial.print("Deg");
  Serial.print((double)(JY901.stcLonLat.lLat % 10000000)/1e5);
  Serial.println("m");
  
JY901.GetGPSV();
  Serial.print("GPSHeight:");
  Serial.print((float)JY901.stcGPSV.sGPSHeight/10);
  Serial.print("m GPSYaw:");
  Serial.print((float)JY901.stcGPSV.sGPSYaw/10);
  Serial.print("Deg GPSV:");
  Serial.print((float)JY901.stcGPSV.lGPSVelocity/1000);
  Serial.println("km/h");
*/

  Serial.println("");
  delay(1);
}

I am using a WT901 IMU to provide input to the servo positions. The servos are powered by a separate 5v power source. I am using pins D2, D3, D4 to send commands to the servos. From the serial output I can see that the Yaw servo is being commanded to move because the position that is sent to the servo is moving with the yaw rate, however the servo provides no movement, and again I have swapped it with several other servos and there is no resolve.

Can you post an annotated schematic showing exactly how you have it wired. Be sure to include all connections, power, ground and power sources. Links to the hardware items technical information is also needed.

1 Like

Just curious - how does it go with a test sketch that only moves 3 servos (everything else omitted) ?

1 Like

Here is the test code I have used:


#include "ESP32Servo.h"

Servo srv1;
Servo srv2;
Servo srv3;


void setup() {
  srv1.attach(2);
  srv2.attach(3);
  srv3.attach(4);

}

void loop() {
  srv1.write(20);
  srv2.write(20);
  srv3.write(20);
  delay(500);
  srv1.write(30);
  srv2.write(30);
  srv3.write(30);
  delay(500);
  
}

Same issue, only the first two defined servos (srv1, srv2) are moving.

Yes I will post one, please allow me some time. I have not written up a schematic yet.

Maybe you thought it unimportant or it's missing, but I see no pin declarations.

ESP32Servo/examples/Multiple-Servo-Example-Arduino/Multiple-Servo-Example-Arduino.ino at master · madhephaestus/ESP32Servo · GitHub

ESP32Servo.cpp:

// Recommend only the following pins 2,4,12-19,21-23,25-27,32-33

but also, a little later

// Servo availible on: 2,4,5,12-19,21-23,25-27,32-33

It shows how it is actually connected and if properly annotated it also gives information on the rest of the hardware. For the most part pictures are very difficult to follow at best. Word problems describe a basic schematic but without it in contex It is hard fo follow. Pin numbers and names indicate different things on different units.

It also is a way for the designer to check what has been done and be sure it is wired correctly. I can read a schematic if a very short time where a frizzy I need to look up each part, try to guess for the most part what is connected to what. For me I can help several other people in the time I try to figure out one of them things. Schematics is the language of electronics and a good constructed schematic can convey much more information then then a dozen or so questions.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.