Reading PWM from a receiver

Hey all.I know this subject has been covered in many ways, but I am hoping that someone can assist me. I hope someone can have the patience to answer a few of my VERY NEWB questions.What I am trying to do is to send PWM to an arduino on an air vehicle which will then send the appropriate servo controls. Simple enough some may say, but I am in a bind since I just cannot get my head wrapped around this and frankly, I think my research has gotten me confused.My BASIC NEED is to be able to see the pulsewidth values in Milliseconds or in PWM values on Serial Monitor and see the values change as the sticks and knobs are moved.I know some may say, why not just use RC to control the servos without the Arduino? The answer to that is that I want to eventually turn control over to the Arduino like in ArduPilot, and use the Arduino as an IMU sort of. The ArduPilot code has been interesting to analyze but I have not gotten closer to my VERY BASIC need. Being able to look at the ArduPilot Pro code would likely be a very good insight......but that is not available to my knowledge.I have tried ServoDecode, ServoTimer2 and SerialServer libraries and I can capture the PPM for the channels alright on Pin 8, but it does not show me the changes to the pulsewidth when the sticks are moved. I thought I might have what I needed by downloading Chris' RCTest code but since I don't want to move anything like motors for thrust or vectoring and tried to uncomment the Servo stuff it doesn't do anything. When I compile it and run, it does nothing. It just sits there and the servos just jitter and sometimes go to extreme lock..I just need to see the pulsewidths and move SERVOS accordingly.. Jordi in his thread to Hack a receiver was a good piece of code, but the next file he released to read the PPM just displays a scattered array of numbers that don't relate to anything. In that code, and in finding the PPM string I get a value that goes like 214567. Is this a MicroSecond value and how could one convert this to a Milli-Second value? Multiply by 1000?Thanks to all in advance for any help or direction you may send my way.Happy Holidays to all.Jim
E-mail me when people leave their comments –

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

Join diydrones

Comments

  • 3D Robotics
    It's based on the Servo library. It takes about 20-30% of available CPU capacity to read each channel, so you'll find that reading four channels slows down the code a lot. Servotimer is more efficient but is limited to just two channels.
  • Hold the train Chris,

    Got it to read the pulses now. I had followed the pinout in the code but the pin numbers didn't match up and once I connected to PD7 to D7, it started working. Now Do I just repeat the code for these two channels for the next two channels so I can read channels 1-4 on the serial monitor. This code is based on Servo or Servotimer1?

    Jim
  • 3D Robotics
    It looks like I may have commented the code wrong. The code I'm looking at shows the RC input is on pins D6 and D7:

    Channel1Value = pulseIn (PD7, HIGH, 20000); //read RC channel 1
    Channel2Value = pulseIn (PD6, HIGH, 20000); //read RC channel 2
  • Hey Chris.

    The setup is my receiver is on, the servo pins are connected to pins 5&6. When I start the code it states: Ready.
    Then is says Channel 1: 0
    Initial Throttle: 1497
    Channel 2: 0
    0 -224
    Initial Steer: 0
    Channel 1: 0

    then on the next cycle it just repeats endlessly.

    Any Clues? The receiver drives servos fine on all channels.

    Jim
  • 3D Robotics
    Ah. Okay, you mean PWM. Big difference (can you correct the post title and body so people aren't confused?)

    When you run my RCTest code, it should be sending Channel 1 and Channel 2 readings to your serial monitor. (Ignore all the motor stuff--it doesn't matter if they're connected or not). Are you seeing those?
  • Thank you Chris. What I am referring to is to be able to read the pulse that leaves the receiver and goes to the servos. I have modified my receiver to be able to attach the output stream to Pin 8 and I also have tried pulseIn as you all do. PPM PWM whatever it is. I need to be able to read it on the Serial Monitor to see the changing values as the sticks/knobs are moved. I would be using serialPrint to the screen. In the RC Test code, I thought this might be useful and meet my basic need, but the motor control stuff threw my brain into a tizzy.

    Have looked at the Paparazzi link you mentioned and thank you. Still the question remains to be able to see the pulses on Serial Monitor.
  • 3D Robotics
    All of our code is to read PWM, but you're talking about PPM. PWM is the signal that goes to the servos. PPM can only be read if you tap a special pin on the chips in older (non spread spectrum) RC receivers.

    (see this from the Paparazzi site for a fuller explanation)

    Which did you mean?
This reply was deleted.