I've been researching this for a while now and I can't find anything conclusive on how to do what I want to do. 

Background

Im using the APM 2.6, which has the ATmega2560

Im working on a drone copter/plane hybrid, it will be an airplane with tilt rotors, and will be able to do VTOL.  I am almost done with all the coding, calibration, and control schemes for it, except for one last item. I have four motors that will be able to rotate (point horizontal or vertical that is) individually via a four servos. That adds up to 8 outputs. I need one last servo to control a rudder, and the only option now is to use one of A0-A12 pins and change them to a digital output. 

Problem

According to HERE (scroll to the bottom) the way to make the analog pins act as a digital output pin, you add 54 to the Analog pin number. So if I wanted to write to A6, i would say write(60, PWMValue). I want to write a PWM value, but i have only gotten either 5V or 0V to output from A6. Could some provide code or commands/functions on how to initiliaze and analog pin to a digital output and then how to write a PWM value to it. 

To add to the confusion, ive looked at the pin mapping schematic HERE. If you look at the link, there are three columns, the "Pin Number", "Pin Name", and "Mapped Pin Name". From looking at examples, when i want to write to one of the standard output PWM pins (1-8) I can use the command rcout.write(1, 1500). Where the first argument "1" is the corresponds to the "Mapped Pin Name". So what is confusing is, if i follow the directions of adding 54, when i say write(60,PWMvalue), there is no corresponding digital pin 60 underneath the "Mapped Pin Name" column. So how does it know where to write to?. So maybe then, it knows to look at the absolute pin indexed number? But if that is the case, then it would be writing to Digital Pin 30, so then should i be saying write(60, PWMvalue)?

If someone could give me the commands/code on how to do this that would be great. Really any help would be great. 

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

Join diydrones

Email me when people reply –

Replies

  • Hi Eric!

    Haven`t you had any problems attaching the servos to outputs 5-8? I mean, aren`t they used for anything more in the code? (I am working with arducopter). What changes have you done in the code, such as "enable output ch"...? I want to put some servos but I'm not sure what changes should I do in the code. On the other hand, regarding RC_FUNCTION parameters, are they all implemented in Arducopter 3.1? Because I'm trying some of them and they do not work.

    Thank you for your help

    • I did not use the Arducopter code, my team and I wrote all of our own code from scratch, the ground up, but loaded much of the same libraries. This made it so we knew exactly what was being initialized and how everything was being used. 

      The websites the proved most helpful for us figuring stuff out was initially, 

      https://ghowen.me/build-your-own-quadcopter-autopilot/

      then, 

      http://dev.ardupilot.com/

      I can't really answer your question, because similar to you, it quickly became overwhelming to try to figure out how to change something, or add a total new flight mode and control system in the thousands of lines of code. 

      ghowen.me
      • Thank you very much for answering! Yes, it's really overwhelming working with such a big code made by others instead of oneself.

        Looking up in the code, I have seen that it uses 3 timers in order to set outputs frequency. The thing is that channel 5 uses the same timer (and consequently the same frequency) as channels 3 and 4. It is located in HAL APM2 RCoutput library. I want to change output channel 5's frequency to 50 Hz, or saying it in another way, I want channel 5 to use the same timer as channels 6, 7 and 8. As you are also using code of libraries, do you have any idea about how to do it? I find it quite difficult to solve.

        Thank you again

This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…