PPM Input and output

Hi,
is there a way to read PPM rx with 6 channels into Arduino using channel 5 from the PPM signal for LED output on pin 10, channel 6 for servo output on pin 11, and the other 1-4 channel output stay as PPM and output to pin 12?

RX PPM --> Arduino PPM input pin2 --> Channel 5 output Pin 10 for LED
|--> Channel 6 output Pin 11 for Servo
|--> Channels 1 to 4 stand as PPM output to pin 12

Hard to understand aything in Your post. Please read and follow the advice given in the topic "How to get the best out of forum".

Welcome to the forum. I'd have to say, even for a first post, you've done...poorly.
This is what @Railroader is obliquely referring to:

Is "PPM" perchance supposed to be "PWM" - i.e. are you trying to read six pulse widths simultaneously?

PPM is most likely Pulse Position Modulation which is commonly used with servos.

Ok, I think I understand what you are trying to do.

Reading the PPM input is quite straightforward, there is already code around to do it. Not quite clear what you want to do with the outputs 5 and 6, but sounds doable.

Pro tip. Add Arduino to any search.

arduino ppm

and

PPM-reader - Arduino Reference

if you want to do your own, you could start by reading the library code.

That library is not the only one… so yoi could see how others did it.

Or just try the libraries. It all depends on what kind of fun you want to have,

a7

I can read in PPM and use channels 5 and 6 for LED and servo. I just don't know how I can redirect channels 1 to 4 back out to pin 12 as PPM signal output for the flight controller.

no, PPM is different from PWM.

1 Like

I think so.
Do you have any code written so that we can use your same structure and modify it to do what you need?

Why not just send it the original? No problem to have multiple listeners, just set the FC to ignore the channels you want for yourself.

a7

1 Like

This code handles the input. You can use to catch the PPM pulse on pin 2. Use getRadioPPM to read the value. You'll want to put some "bad value" handling before just passing it on.

volatile byte state = LOW;
volatile byte previous_state= LOW;
volatile unsigned long microsAtLastPulse=0;
volatile unsigned long blankTime=2100;
volatile int channelAmount=6;
volatile int pulseCounter=0;
volatile unsigned long rawValues[10];
void setup()
{
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(2, pulseCatcherISR, RISING);
 }
unsigned long getRadioPPM(int ch_num) {
//call this with the channel number to get the PPM value
  unsigned long valPWM = 0;
  valPWM = rawChannelValue(ch_num);// 1000-2000 based on PPM routine return range.
  return valPWM;
}

void pulseCatcherISR() {
  //Remember the current micros() and calculate the time since the last pulseReceived()
  unsigned long previousMicros = microsAtLastPulse;
  microsAtLastPulse = micros();
  unsigned long time = microsAtLastPulse - previousMicros;
  
  if (time > blankTime) {
      // Blank detected: restart from channel 1 
      pulseCounter = 0;
      state=true;
  } 
  else {
      // Store times between pulses as channel values
      state=false;
      if (pulseCounter < channelAmount) {
          rawValues[pulseCounter] = time;
          ++pulseCounter;
      }
  }
}

unsigned long rawChannelValue(int channel) {
    // Check for channel's validity and return the latest raw channel value or 0
    unsigned value = 0;
    if (channel >= 1 && channel <= channelAmount) {
        //noInterrupts();
        value = rawValues[channel-1];
       //interrupts();
    }
    return value;
}
1 Like

thank you. I will check the code and come back with question :slight_smile:

I tried your code and added this code below but I am not getting any values from the channels..

void loop() {
  // put your main code here, to run repeatedly:
  for (int i = 1; i <= channelAmount; ++i) {
    unsigned long rxvalue = getRadioPPM(i);
    Serial.print("Channel ");
    Serial.print(i);
    Serial.print(": ");
    Serial.println(rxvalue);
  }
  delay(1000); // Delay to slow down the printing
}

Could be your wiring or your RC controller settings. On my RC Controller, I had to go into setup and set it to output in PPM. I also had to figure out which pin on the receiver to connect that relayed the PPM signal. On mine it was pin 1.

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