Replies: 2 comments
-
|
A test program wit OpenShot125 seems to run fine: #include <Arduino.h>
#include <array>
#include "esp32-hal-ledc.h"
#include "led_blinker.h"
constexpr std::array<uint8_t,4> esc_pins {33, 25, 26, 27}; // GPIO pins for ESCs
constexpr std::array<int,4> esc_ch {0, 1, 2, 3}; // LEDC channels for ESCs
constexpr uint8_t INTERNAL_LED_PIN = 2; // onboard LED
constexpr uint32_t ONESHOT_FREQ = 4000; // 250 µs period
constexpr uint8_t PWM_BITS = 10; // 0‑1023
constexpr uint16_t DUTY_MIN = 512; // 125 µs
constexpr uint16_t DUTY_MAX = 1023; // 250 µs
LedBlinker blinker(INTERNAL_LED_PIN);
void setup() {
Serial.begin(115200);
blinker.setup();
for (size_t i = 0; i < esc_pins.size(); ++i) {
bool ok = ledcAttachChannel(esc_pins[i], ONESHOT_FREQ,PWM_BITS,esc_ch[i]);
if (!ok) {
Serial.printf("Cannot attach pin %d to channel %d\n", esc_pins[i], esc_ch[i]);
while (true) { blinker.start(5); }
}
}
for (auto ch : esc_ch) ledcWriteChannel(ch, DUTY_MAX);
delay(3000);
for (auto ch : esc_ch) ledcWriteChannel(ch, DUTY_MIN);
delay(3000);
}
void loop() {
static uint16_t duty = DUTY_MIN;
static int16_t step = 4; // ramp speed
static uint8_t motor0b = 0;
static bool atMin = true;
duty += step;
if (duty >= DUTY_MAX || duty <= DUTY_MIN) step = -step;
if (duty <= DUTY_MIN && !atMin) {
atMin = true;
motor0b = (motor0b + 1) % esc_pins.size();
blinker.start(motor0b + 1); // 1‑4 blinks
Serial.printf("Motor %d\n", motor0b + 1);
}
if (duty > DUTY_MIN) atMin = false;
ledcWriteChannel(esc_ch[motor0b], duty);
blinker.update();
delay(10);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Hmmm. This looks like a PlatformIO issue. If I compile the same thing in Arduino IDE, it works, but I would very much like not to have to use Arduino IDE, as I'm used to my PlatformIO workflow (with remote builds and some automation which I want to later include in the project too). I'll investigate more. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm on ESP32, running Madflight v2.1.0. I'm compiling via PlatformIO (with pioarduino to get the latest Arduino framework for ESP). I'm trying to get a basic Quad running, but it doesn't recognize my motors.
I've tried to put some debug Serial prints to find where it gets stuck, and I think the
bool found = ledcAttachChannel(pin, freq, bits, ch);`line in
ESP32_PWM_v3.hnever returns, and keeps spamming the serial console with errors:In the main file, I'm calling:
The pins are 33, 25, 26, 27.
The same error appears when trying to use OpenShot125
PWM::begin(pin=33,freq=2000,min_us=125.000000,max_us=250.000000), then the errors start printing endlessly.Beta Was this translation helpful? Give feedback.
All reactions