Using ESP32 to move brushless motor using esc

Hi first of all i unable to move the motor and I'm not sure if my coding correct or not or there is another problem . Both my esc signal wire connected to esp32 gpio26 and 27. Below is my code.

#include <driver/ledc.h>

// Pin configuration
const int motorPin1 = 26;  // Pin connected to motor 1 ESC
const int motorPin2 = 27;  // Pin connected to motor 2 ESC

// LEDC settings for motor 1
const int ledcChannel1 = 0;      // LEDC channel for motor 1
const int ledcResolution1 = 12;  // LEDC resolution (bits) for motor 1
const int ledcFrequency1 = 50;   // LEDC frequency (Hz) for motor 1

// LEDC settings for motor 2
const int ledcChannel2 = 1;      // LEDC channel for motor 2
const int ledcResolution2 = 12;  // LEDC resolution (bits) for motor 2
const int ledcFrequency2 = 50;   // LEDC frequency (Hz) for motor 2

const int minPulseWidth = 1000;  // Minimum pulse width in microseconds
const int maxPulseWidth = 2000;  // Maximum pulse width in microseconds

void setup() {
  // Configure motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);

  // Configure LEDC timers for motor 1 and motor 2
  ledcSetup(ledcChannel1, ledcFrequency1, ledcResolution1);
  ledcSetup(ledcChannel2, ledcFrequency2, ledcResolution2);

  // Attach motor pins to the respective LEDC channels
  ledcAttachPin(motorPin1, ledcChannel1);
  ledcAttachPin(motorPin2, ledcChannel2);
}

void loop() {
  // Set motor 1 speed to maximum throttle
  setMotorSpeed(motorPin1, maxPulseWidth);

  // Set motor 2 speed to maximum throttle
  setMotorSpeed(motorPin2, maxPulseWidth);
}

// Function to set the motor speed
void setMotorSpeed(int motorPin, int pulseWidth) {
  int ledcChannel;

  // Determine the LEDC channel based on the motor pin
  if (motorPin == motorPin1) {
    ledcChannel = ledcChannel1;
  } else if (motorPin == motorPin2) {
    ledcChannel = ledcChannel2;
  } else {
    return;  // Invalid motor pin
  }

  ledcWrite(ledcChannel, pulseWidth);
}

Do the hardware logic levels match?

You will have to provide a lot of more information if you want effective help.

Almost any ESC expects a specified servo-signal on power-on.
A lot of ESCs must be calibrated to min and max-values to know what each pulse-length of the servo-signal shall mean.

An ESP32 has a voltage of 3.3V. It might be that the ESC is not working properly with 3.3V but expects a 5V signal.

And these details are inside the manual of the ESC. So provide a link to where the manual can be downloaded or attach a PDF-file to a posting

Do you have a simple RC-servo for crosschecking if the servo-signal is created properly?
Do you have a digital multimeter that can measure frequency and duty-cycle?
Do you have a second microcontroller which you could use to check how the servo-signal looks like?

Did you connect ground of your ESP32 with the ground of the powersupply of your ESC?
Are you using a extra powersupply for your ESC? You can't supply the ESC from the ESP32. Your ESC MUST have their own power-supply that is capable to deliver the current your brushless-motor needs.

This current is pretty high even for small motors
Even if your brushless motor has a diameter of just 20 mm the current will be minimum 5A and can go up for bigger motors to 30A - 50A !!

best regards Stefan

1 Like

could you provide a schematic?

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