Using Arduino as an autopilot

crtleroy

Member
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.
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.

++
 
:) i do not know the answer and have only begun to look at arduino et al,

but i'm pretty sure you'll be way happy when you find a good ref on the PW format. i know it's real tricky on my flysky, some extra signal param.. but, looking at your code, i'm sure your figures are off by a magnitude.. 20000 is a long time in microseconds....
 
:) i do not know the answer and have only begun to look at arduino et al,

but i'm pretty sure you'll be way happy when you find a good ref on the PW format. i know it's real tricky on my flysky, some extra signal param.. but, looking at your code, i'm sure your figures are off by a magnitude.. 20000 is a long time in microseconds....

Well, look at "pwm output waveforms from spektrum receiver" first result on google (sorry I'm not allowed to put links yet)
this guy look at the signal out from a spektrum receiver, it's definitely a 20ms period signal :/
I'd love to have an oscilloscope so much, but it's so expensive :(
 
yep silly me i saw milliseconds :p get that thing out the way, amputate today!
Oops okay :rolleyes:

Well, for now I don't have an oscilloscope to figure it out, but there are other ways to communicate with the controller : PPM, SBUS... I'm going to have a look.

Any idea with that ?
 
you'll forgive my unqualified interest in teh thread, i'm from audio dsp gradually crossing over to rc.

oscilloscope, for reals you should be able to record the signal with your audio card.. even if it's a cheapie realtek or something ;) they have had 96k for years.. just connect a lead to the mic jack (there's a pic of me doing this in another thread recently). on windows there's a free wav editor called wavosaur that should set up and let you record easily if you don't already have a wav editor.
 
for reals you should be able to record the signal with your audio card..

Hi yay, well I guess it's a splendid idea. Actually I just ordered a dso138, a very-low-cost pocket oscilloscope that can help for not-too-high frequencies. But I think I won't wait for it and will try wavosaur :).

I'm also definitely considering to generate a PPM signal to handle the all 8 channels instead of 8 different PWM signals. And to do that I also definitely need an oscilloscope or some hack to replace it.

I'll try it tonight and hopefully I'll come back with good news :)
 
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 ;)
 
Back
Top