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
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.
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.
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;
}
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.