Arduino nano ESP32 + ESC BLDC motor control

When trying to control the esc with PWM from servo library it only lets me control 2 out of the 4 escs, It only generates the PWM signal to 2 out of 4 digital pins. How do I fix this?

#include <ESP32Servo.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

Servo esc1;
Servo esc2;
Servo esc3;
Servo esc4;
int throttle1;

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";

struct Data_Package{
  byte roll;
  byte pitch;
  byte throttle;
  byte yaw;
};

Data_Package data;

unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;

void setup() {
  Serial.begin(57600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_2MBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();
  esc1.attach(6);
  esc2.attach(5);
  esc3.attach(4);
  esc4.attach(3);
}
void loop(){

  if (radio.available()) {
    radio.read(&data, sizeof(Data_Package));
    lastReceiveTime = millis(); 
  }
  currentTime = millis();
  if ( currentTime - lastReceiveTime > 1000 ) { 
  };
  throttle1 = map(data.throttle,90,180,1000,2000);
  esc1.writeMicroseconds(throttle1);
  esc2.writeMicroseconds(throttle1);
  esc3.writeMicroseconds(throttle1);
  esc4.writeMicroseconds(throttle1);
  Serial.println(throttle1);

Can be an insufficient power supply.

I have a 11.1V lipo 3s battery connected to each motor, that isnt the problem.

Have the ESCs all got a GND connection that is common with the ESP32 board ?

Yes, they do.

If you swap the connection to a working ESC and a non working ESC does the problem stay with the ESC or the pin ?

When I swap the connections the other 2 that were working stop working and the 2 that werent working now spin. I dont think there is a problem with pins or the esc, for some reason the arduino nano esp32 wont give 4 signals at the same time.

Fixed the problem. I used Deneyap Servo library.

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