admin管理员组文章数量:1125719
I'm trying to control a brushless motor from an ESP32-devkit-v1 with an ESC with BLHeli S firmware. I've watched a LOT of videos, manuals, ChatGPT, etc., with no success. The following code got me at least a musical response from the ESC: the three-note startup chime twice, a low tone, a double high tone, and then four quick ascending tones repeat for a while. I've tried using DShot, too, without success. If anyone can point out what I'm missing or point me toward a resource that can help, that would be awesome.
Auxiliary info: The esp32 is connected and powered by my computer. The ESC is powered by a spare 60w desktop PSU; I cut a Molex connector off and connected the 12v wire and ground to the ESC, although the PSU only delivers about 10.5v. It's pretty stable, tho, so I don't think that's an issue.
#include <Arduino.h>
// GPIO pin for ESC signal
const int escPin = 18;
// PWM configuration
const int freq = 50; // 50 Hz for ESC control
const int resolution = 16; // 16-bit resolution
const int channel = 0; // PWM channel
void setThrottle(int dutyCycle);
void calibrateESC();
void setup() {
// Initialize serial communication
Serial.begin(115200);
Serial.println("Initializing ESC...");
// Configure the PWM channel
ledcSetup(channel, freq, resolution);
ledcAttachPin(escPin, channel);
// Send initial ESC calibration signals
calibrateESC();
}
void loop() {
// Example: Gradually increase motor speed
Serial.println("Increasing throttle...");
for (int dutyCycle = 1000; dutyCycle <= 2000; dutyCycle += 100) {
setThrottle(dutyCycle);
delay(500);
}
Serial.println("Stopping motor...");
setThrottle(1000); // Stop the motor
delay(2000);
}
void calibrateESC() {
Serial.println("Calibrating ESC...");
setThrottle(2000); // Maximum throttle
delay(2000); // Wait for ESC to recognize max throttle
setThrottle(1000); // Minimum throttle
delay(2000); // Wait for ESC to arm
Serial.println("ESC calibration complete.");
}
void setThrottle(int dutyCycle) {
// Map 1000-2000 µs to 16-bit resolution
int pwmValue = map(dutyCycle, 1000, 2000, 0, 65535);
ledcWrite(channel, pwmValue);
}
本文标签: arduinoprogramming ESP32 to control BLHeli S ESCStack Overflow
版权声明:本文标题:arduino - programming ESP32 to control BLHeli S ESC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736673344a1947043.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论