0% found this document useful (0 votes)
11 views2 pages

Esc Low Speed

This document contains Arduino code for controlling an ESC (Electronic Speed Controller) using a PCA9685 PWM driver. It includes setup and calibration functions, as well as a loop to demonstrate speed control by setting PWM values. The code allows for ramping up and down the speed of a motor connected to the ESC.

Uploaded by

alaminuiu07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Esc Low Speed

This document contains Arduino code for controlling an ESC (Electronic Speed Controller) using a PCA9685 PWM driver. It includes setup and calibration functions, as well as a loop to demonstrate speed control by setting PWM values. The code allows for ramping up and down the speed of a motor connected to the ESC.

Uploaded by

alaminuiu07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Wire.

h>
#include <Adafruit_PWMServoDriver.h>

// Create the PCA9685 PWM driver object


Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// ESC Calibration parameters


const int ESC_MIN = 204; // Minimum PWM value (adjust based on your ESC)
const int ESC_MAX = 409; // Maximum PWM value (adjust based on your ESC)

void setup() {
Serial.begin(9600);
Serial.println("Initializing PCA9685 and ESC control");

pwm.begin();
pwm.setPWMFreq(50); // Set frequency to 50 Hz for the ESC
calibrateESC(); // Call function to calibrate ESC
}

void loop() {
// Example: Ramp up the speed from min to max
//for (int pulse = ESC_MIN; pulse <= ESC_MAX; pulse++) {
pwm.setPWM(0, 0, 204 ); // Set PWM on channel 0
delay(2000);
pwm.setPWM(0, 0, 221 ); // Set PWM on channel 0
delay(2000); // Small delay to observe change
// }

// Hold at max speed for 2 seconds


// delay(2000);

// Ramp down the speed


//for (int pulse = ESC_MAX; pulse >= ESC_MIN; pulse--) {
//pwm.setPWM(0, 0, ESC_MAX); // Set PWM on channel 0
//delay(2000); // Small delay to observe change
// }

// Hold at min speed for 2 seconds


//delay(2000);
}
void calibrateESC() {
Serial.println("Calibrating ESC...");
pwm.setPWM(0, 0, ESC_MAX); // Send maximum signal to ESC
delay(2000); // Wait for ESC to recognize max throttle
pwm.setPWM(0, 0, ESC_MIN); // Send minimum signal to ESC
delay(2000); // Wait for ESC to recognize min throttle
Serial.println("Calibration complete.");
}

You might also like