Hi, I am building my own quadrocopter, but I have one problem. When I connect receiver directly to regulator and control it with RC, it works normally. But if I connect it via Arduino, then it sometimes start to rotate when it shouldn't rotate or rotate with about 1s breaks. I searched on google but I can't find the basic receiving and sending PPM to regulators and I don't want any completed solution because I want to create my code according to my needs. And I am using Arduino Mega 2560 R3.
My basic code for receiving PPM and sending to regulators:
#include <Servo.h>
Servo esc1;
Servo esc2;
Servo esc3;
Servo esc4;
int esc1_pin = 10;
int esc2_pin = 11;
int esc3_pin = 12;
int esc4_pin = 13;
int ch1;
int ch2;
int ch3;
int ch4;
int ch5;
int ch6;
int ch7;
int ch8;
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
esc1.attach(esc1_pin);
esc2.attach(esc2_pin);
esc3.attach(esc3_pin);
esc4.attach(esc4_pin);
delay(1000);
//Serial.begin(115200);
}
void loop() {
ch1 = pulseIn(2, HIGH, 25000);
ch2 = pulseIn(3, HIGH, 25000);
ch3 = pulseIn(4, HIGH, 25000);
ch4 = pulseIn(5, HIGH, 25000);
ch5 = pulseIn(6, HIGH, 25000);
ch6 = pulseIn(7, HIGH, 25000);
ch7 = pulseIn(8, HIGH, 25000);
ch8 = pulseIn(9, HIGH, 25000);
esc1.writeMicroseconds(ch3);
esc2.writeMicroseconds(ch3);
esc3.writeMicroseconds(ch3);
esc4.writeMicroseconds(ch3);
delay(20);
}
This is my basic program for just receiving and sending pulses but it does I wrote above. Does anybody know, where is the problem? I tried to simulate it via sending data to serial port instead of to regulators and checking in console and it was ok. I suppose that there may be problem with delay but I changed it and didn't helped. Unfortunatelly I don't have osciloscope so I can't check the output pulses. So if anybody where is the problem it would be helpful, other code isn't problem, just the receiving and sending signals doesn't work.