Using Arduino as an autopilot

Hi every one,

I’m working on an octocopter that I would like to be auto-piloted. To do that, I’m considering to use my Arduino Mega 2560 to generate PWM signals to « mimic » a receiver.
I’m using a SP Racing F3 and cleanflight.

So more precisely, instead of using a RC command, I want the embedded arduino to send directly the PWM command to my SP-F3 input channels.

Then the first thing I need to know is the exact nature of the PWM signal that I found here : http://diydrones.com/forum/topics/pwm-output-waveforms-from-spektrum-receiver
So apparently the PWM range go from 1ms to 2ms above a general 20ms period signal. I am pretty much OK with that, knowing that cleanflight receiver range go from 1000 to 2000 (so 1000μs to 2000μs I guess).

So I try to use this very simple Arduino code to generate a PWM signal that is supposed to  command a channel:

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  digitalWrite(13, HIGH);
  delayMicroseconds(1300);
  digitalWrite(13, LOW);
  delayMicroseconds(20000 - 1300);
}

and I connect Arduino’s GND to SP F3’s ground, and pin 13 to any PWM channel: It absolutely doesn’t work ! On cleanflight I look to different channels and absolutely nothing changes.

So have anyone ever done that ? I’m wondering what is wrong in all of that. I know that there are better ways to generate PWM but I’m just using the simple way first. I’d love to have an oscilloscope to help me but I dont :(

Has anyone an idea ? Any suggestion is welcome :)

And to finish, excuse my grammar, I’m not a native speaker.

++

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi there, so yesterday night everything has been sorted out :).
    I finally found a magic PPM generation code here : https://quadmeup.com/generate-ppm-signal-with-arduino/
    And everything worked.

    I can control all channels with my arduino with a single PPM pin. Then the arduino can totally command the copter without me !

    So guys if you want to pass some informations from an arduino to your FC, to go a bit further in automation, just do it ;)

    Generate PPM signal with Arduino
    In the beginning of this year I’ve written a short tutorial how to read PWM signals from RC radio with Arduino. While it is can be useful when buildi…
  • Chris, you're so right... Thanks. I'll try that tonight and hopefully I'll come back with good news :)

    Chris Anderson said:

    That's the wrong function. PWM signals are generated by analogWrite(pin,value), not digitalWrite

    https://www.arduino.cc/en/Reference/AnalogWrite

  • 3D Robotics

    That's the wrong function. PWM signals are generated by analogWrite(pin,value), not digitalWrite

    https://www.arduino.cc/en/Reference/AnalogWrite

This reply was deleted.

Activity