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.