Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions drone-flight-controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,28 @@ int status = STOPPED;
int battery_voltage;
// ---------------------------------------------------------------------------

/**
* Configure ESC output pins and feed them a low-throttle pulse for ~5 s so
* they can complete their startup sequence (melody → cell detection → arming
* confirmation) before the rest of setup runs.
* Period: 1000 µs HIGH + 3000 µs LOW = 4 ms → 1250 iterations ≈ 5 s.
*/
void initEscs() {
DDRD |= B11110000; // Set pins 4-7 as outputs
for (int i = 0; i < 1250; i++) {
PORTD |= B11110000; // Set pins 4-7 HIGH
delayMicroseconds(1000); // 1000 µs pulse (minimum throttle)
PORTD &= B00001111; // Set pins 4-7 LOW
delayMicroseconds(3000); // remainder of 4 ms period
}
}

/**
* Setup configuration
*/
void setup() {
initEscs();

// Start I2C communication
Wire.begin();
TWBR = 12; // Set the I2C clock speed to 400kHz.
Expand All @@ -122,9 +140,6 @@ void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

// Set pins #4 #5 #6 #7 as outputs
DDRD |= B11110000;

setupMpu6050Registers();

calibrateMpu6050();
Expand Down