more clear docs

This commit is contained in:
2025-04-01 10:54:25 +02:00
parent 9a1ca56ac1
commit 718cbe66d8

View File

@@ -71,6 +71,65 @@ During that time I used this code
```
It has an automatic arming sequence when the MCU starts with the esc and motor. But there is one small problem. I couldn't get the motor armed using this script even though I set the escpin to the correct pin. After inspecting the code a bit more I realized that escpin wasn't used anywhere and ledcChannel was the actual pin where the PWM signal would get generated. After I changed ledcChannel to the correct pin the motor armed and I could start if by sending the MCU "1".
??? Correct code
```cpp
const int potPin = 4;
// LEDC channel and timer configuration
const int ledcChannel = D2;
const int ledcTimer = 0;
const int pwmFreq = 50; // 50Hz frequency (20ms period)
const int pwmResolution = 16; // 16-bit resolution
// Pulse widths (in microseconds) for min and max throttle
const int minPulseWidth = 1200; // 1ms for min throttle
const int maxPulseWidth = 1940; // 2ms for max throttle
int incomingByte = 0;
// Function to convert pulse width to LEDC duty cycle
int pulseWidthToDutyCycle(int pulseWidth) {
int maxDuty = (1 << pwmResolution) - 1;
return (pulseWidth * maxDuty) / 20000; // Convert to 16-bit duty cycle
}
void setup() {
Serial.begin(115200);
// Set up the PWM signal on the escPin
ledcAttach(ledcChannel, pwmFreq, pwmResolution);
// Start the ESC calibration sequence
Serial.println("Starting ESC...");
// Step 2: Send minimum throttle (1ms pulse width)
Serial.println("Setting min throttle...");
ledcWrite(ledcChannel, pulseWidthToDutyCycle(minPulseWidth));
// At this point, the ESC should be calibrated
Serial.println("ESC calibration complete.");
delay(2000);
}
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
}
//min 1100, max 1940
if (incomingByte == 48) {
ledcWrite(ledcChannel, pulseWidthToDutyCycle(1100));
Serial.println("low");
} else if (incomingByte == 49) {
ledcWrite(ledcChannel, pulseWidthToDutyCycle(1940));
Serial.println("high");
}
// Reset incomingByte after processing
// Small delay to allow for serial input processing
}
```
<video controls src="PXL_20250327_140301518(1)(1)(1).mp4" title="Title"></video>
In the loop section of the code is a method where it accepts serial communication back. Byte 49 represents ascii character 1 and byte 48 represents 0.
@@ -102,3 +161,7 @@ Here you can see it hit the maximum of the power supply (60watts). If it goes an
Here are the files to build the PSU yourself. I don't recommend building it without making a top lid. Otherwise you will have a very hard time assembling it.
Link to PSU: https://git.smikkelbakje.nl/Smikkelbakje/Labvoeding
## Power
Right now I'm facing the issue of powering the motors. My power supply can't handle the current draw from my motors. So I needed something that could output a lot of power while staying stable. That's where li-po batteries luckily come in. I have a bit of experience with handling them. The maximum amount of voltage I can put on my motors is 6S but the Electronic speed controllers can only go up to 4S. So that's what I'm going for. For now I will keep trying to test with my current power supply.