Hey so the problem I'm having is that i'm following a guide for building an Arduino based drone. I'm waiting for some parts to arrive from China for the radio communication. In the meantime i have been trying to cut out the radio control, and just run the Arduino flight controller with a second Arduino generating the PPM signal the flight controller needs.
The FC (Flight controller) by default takes a PPM signal as input, and controls the drone and generates PWM signals going out to the motor's of the drone.
The flight controller (Arduino) is run by a platform called Multiwii.
(the code can be found at Google Code Archive - Long-term storage for Google Code Project Hosting.)
I'm using version 2.4
The Arduino nano that i want to generate the PPM signal, for the Flight Controller. Is currently connected to a PS2 joystick breakout board from which i'm hoping to control the Throttle and roll values for the drone.
I tried to piece together part of code from the tutorial i follow for the drone and some sample code from the Arduino Adeept starter kit. Now also with a bit of my own code.
Here is the code i used for the second Arduino (PPM generator or wired controller)
////////////////////// Joystick configruation /////////////////////////
int JoyStick_X = 0; //PS2 joystick X-axis is defined, ANALOG IN of Pin0
int JoyStick_Y = 1; //PS2 joystick Y axis is defined, ANALOG IN of Pin1
int JoyStick_Z = 3; //Defined PS2 joystick Z axis,
int Joystick_aux = 4; //Aux Channel to fill multiwii requirements
///////////////////////////////////////////////////////////////////////
////////////////////////// PPM Configruation //////////////////////////
#define channel_number 4 //Set the number of channels
#define sigPin 2 // Set PPM signal output pin on arduino
#define PPM_FrLen 27000 //set the PPM frame lenght in microseconds (1ms == 1000 microS)
#define PPM_PulseLen 400 // Set the pulse length
///////////////////////////////////////////////////////////////////////
int ppm[channel_number];
struct MyData {
byte throttle;
byte roll;
byte pitch;
byte yaw;
};
MyData data;
void resetData()
{
// 'safe' values to use when no radio input is detected
data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
setPPMValuesFromData();
}
void setPPMValuesFromData()
{
ppm[0] = map(data.throttle, 0, 255, 1000, 2000);
ppm[1] = map(data.roll, 0, 255, 1000, 2000);
ppm[2] = map(data.pitch, 0, 255, 1000, 2000);
ppm[3] = map(data.yaw, 0, 255, 1000, 2000);
}
void setupPPM() {
pinMode(sigPin, OUTPUT);
digitalWrite(sigPin, 0);
cli();
TCCR1A = 0; // set entire TCCR1 register to 0
TCCR1B = 0;
OCR1A = 100; // compare match register (not very important, sets the timeout for the first interrupt)
TCCR1B |= (1 << WGM12); // turn on CTC mode
TCCR1B |= (1 << CS11); // 8 prescaler: 0,5 microseconds at 16mhz
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
sei();
}
void reciveData()
{
}
void setup(void)
{
resetData();
//setupPPM();
Serial.begin(9600);
pinMode(JoyStick_Z, INPUT_PULLUP); //Z axis is defined as an input PS2
}
void loop(void)
{
data.throttle = map(analogRead(A1), 0, 1023, 0, 255);
data.roll = map(analogRead(A0), 0, 1023, 0, 255);
data.pitch = map(digitalRead (JoyStick_Z), 1, 0, 127, 255);
data.yaw = map(digitalRead (Joystick_aux), 0, 1, 0, 255);
//int x,y,z;
//x=analogRead(JoyStick_X);
//y=analogRead(JoyStick_Y);
//z=digitalRead(JoyStick_Z);
Serial.print("Throttle "); Serial.print(data.throttle); Serial.print(" ");
Serial.print("Roll "); Serial.print(data.roll); Serial.print(" ");
Serial.print("Pitch "); Serial.print(data.pitch); Serial.print(" ");
Serial.print("Yaw "); Serial.print(data.yaw); Serial.print("\n");
setPPMValuesFromData();
//delay(1);
}
And my Wiring diagram is attached below.