Arduino drone help

Hello, I just finished building my Arduino Nano based drone, but the drone won´t turn on. I have tested everything but couldn´t fix the problem. I have also built an arduino transmitter, everything is in the videos and pictures. I am new to this kind of stuff, so I don´t know what else could be wrong. I have calibrated the ESCs, I am using SimonK 12A. When I open the Multiwii config software, the values from transmitter are good and responding to my movements. Could anyone please help me? It is a school project and I need to finish it ASAP. Thanks for any kind of help.
Transmitter:

Drone:

Start-up beeps: https://youtu.be/TEFFJJdlijU
Communication test: https://www.youtube.com/watch?v=N9ySzXoXQmg

Hi @samuelzatovic

Could you post your code? Don't forget to use code tags </>.

Could you also post your schematic, or a diagram of the transmitter and the receiver?

Here is the transmitter code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
  
const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(9, 10); 
struct MyData {
  byte throttle;
  byte yaw;
  byte pitch;
  byte roll;
};

MyData data;

void resetData() 
{
  data.throttle = 0;
  data.yaw = 127;
  data.pitch = 127;
  data.roll = 127;
}

void setup()
{
  
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  resetData();
}

int mapJoystickValues(int val, int lower, int middle, int upper, bool reverse)
{
  val = constrain(val, lower, upper);
  if ( val < middle )
    val = map(val, lower, middle, 0, 128);
  else
    val = map(val, middle, upper, 128, 255);
  return ( reverse ? 255 - val : val );
}

void loop()
{
  data.throttle = mapJoystickValues( analogRead(A3), 0, 500, 1023, true );
  data.yaw      = mapJoystickValues( analogRead(A2), 0, 500, 1023, false );
  data.pitch    = mapJoystickValues( analogRead(A1), 0, 500, 1023, true );
  data.roll     = mapJoystickValues( analogRead(A0), 0, 500, 1023, false );

  radio.write(&data, sizeof(MyData));
}

And here is the receiver:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define channel_number 6  
#define sigPin 2 
#define PPM_FrLen 27000
#define PPM_PulseLen 400
int ppm[channel_number];
const uint64_t pipeIn =  0xE8E8F0F0E1LL;
RF24 radio(9, 8);
struct MyData {
  byte throttle;
  byte yaw;
  byte pitch;
  byte roll;
};

MyData data;

void resetData() 
{
  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.yaw,      0, 255, 1000, 2000);
  ppm[2] = map(data.pitch,    0, 255, 1000, 2000);
  ppm[3] = map(data.roll,     0, 255, 1000, 2000);
  }

void setupPPM() {
  pinMode(sigPin, OUTPUT);
  digitalWrite(sigPin, 0); 
  cli();
  TCCR1A = 0;
  TCCR1B = 0;

  OCR1A = 100;
  TCCR1B |= (1 << WGM12);
  TCCR1B |= (1 << CS11);
  TIMSK1 |= (1 << OCIE1A);
  sei();
}
void setup()
{  
  resetData();
  setupPPM();
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.setAutoAck(false);

  radio.openReadingPipe(1,pipeIn);
  radio.startListening();
}
unsigned long lastRecvTime = 0;

void recvData()
{  
  while ( radio.available() ) {        
    radio.read(&data, sizeof(MyData));
    lastRecvTime = millis();
  }
}
void loop()
{
  recvData();

  unsigned long now = millis();
  if ( now - lastRecvTime > 1000 ) {
    resetData();
  }
  
  setPPMValuesFromData();
}

#define clockMultiplier 2

ISR(TIMER1_COMPA_vect){
  static boolean state = true;

  TCNT1 = 0;

  if ( state ) {
    PORTD = PORTD & ~B00000100;
    OCR1A = PPM_PulseLen * clockMultiplier;
    state = false;
  }
  else {
    static byte cur_chan_numb;
    static unsigned int calc_rest;

    PORTD = PORTD | B00000100;
    state = true;
    if(cur_chan_numb >= channel_number) {
      cur_chan_numb = 0;
      calc_rest += PPM_PulseLen;
      OCR1A = (PPM_FrLen - calc_rest) * clockMultiplier;
      calc_rest = 0;
    }
    else {
      OCR1A = (ppm[cur_chan_numb] - PPM_PulseLen) * clockMultiplier;
      calc_rest += ppm[cur_chan_numb];
      cur_chan_numb++;
    }     
  }
}

I am using the NRF24 radio module to make the communication.

Also, here are the schematics:
here is the transmitter:


and this is the receiver:

Did one or more tests fail? In that case, which test?

Assuming that helpers will set aside time for watching videos is a way to make helpers skip Your question. Helpers work for free on their free time and it's not unlimited.

1 Like

FInally I got it working! The problem was probably in incorrectly calibrated joysticks. I made a simple code to test them and each of them was sending a bit wrong values. After calibration the drone started and is working perfectly. Thanks for your replies! :slight_smile:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.