Read signal from RC receiver

Hi

I am trying to connect my Arduino Micro to my Turnigy 9X receiver without success. The Arduino doesn't react at all on the signal.
I have connected the signal cable from Ch6 on the receiver to Pin 2 on my Arduino. Then I tried using interrupts, like this:

// Never changes, constants
const int quadPin = 2;

 
void setup()
{
  Serial.begin(9600);          //  setup serial

  pinMode(quadPin, INPUT);
  
  attachInterrupt(0, ch2Changed, CHANGE); // Attach interupt on digital channel 2. Calls ch2Changed
}

void loop()
{
  //Serial.println("Something");
  delay(100);
}

void ch2Changed()
{
  if(digitalRead(quadPin) == HIGH)
  {
    Serial.println("Pin is HIGH!");
  }
  else
  {
    Serial.println("Pin is LOW!");
  }
}

When running this and flicking the switch on my Turnigy 9X nothing happens. It never registers any changes.

Why could this be?

I measured the signal from Ch6 and when the switch on my controller is OFF it's at ~.2V and when it's ON it's at ~.35V. Is that too low? Or can I even measure like this at all? I guess it's a PPM signal that comes from the receiver...

Any guidance or ideas are highly appreciated.

I guess it's a PPM signal that comes from the receiver...

Most likely. And, those are read using pulseIn(), not interrupts.

Serial output in an ISR is a really bad idea. Interrupts are disabled in an ISR, and are essential for Serial output to happen.

PaulS:

I guess it's a PPM signal that comes from the receiver...

Most likely. And, those are read using pulseIn(), not interrupts.

Serial output in an ISR is a really bad idea. Interrupts are disabled in an ISR, and are essential for Serial output to happen.

Thank you for your answer.

Hmmm, according to RCArduino: How To Read an RC Receiver With A Microcontroller - Part 1 pulseIn() is a very bad idea for this and interrupts are better.
I'm very new to this so I'm not sure which is better :slight_smile:

Anyway, I've tried with pulseIn() as well and I get nothing. :-/

EDIT:
Actually, now it's working with pulseIn()! Perhaps I used the wrong pin before when I tried it... Anyway, it seems to work :slight_smile:

I guess it's a PPM signal that comes from the receiver...

The output from the receiver pin is a PWM signal. Each receiver channel forms part of a PPM data stream. The position of the data in the stream allows the receiver to distinguish between the channels. Note that each channel is a PWM signal even if the transmitter control is an on/off switch, such as gear up/down, rather than one that is proportional to the movement of a control stick or slider.

I see that you have got the signal decoding working using pulseIn. When I was experimenting with reading an RC signal with the Arduino I used this simple program to investigate the values being output by the receiver.

byte receiverPin = 7;
unsigned long duration;

void setup()
{
  Serial.begin(115200);
  pinMode(receiverPin, INPUT);
}

void loop()
{
  duration = pulseIn(receiverPin, HIGH);
  Serial.println(duration);
  delay(100);
}

DuaneB has some useful resources on this subject.

AWOL:
DuaneB has some useful resources on this subject.

Yes, I believe I linked to his blog in a post above. He uses interrupts. I wonder why my interrupts never fired...

Perhaps my signal is HIGH all the time. When I used pulseIn() I get 1050 when the switch is off and 1880 when it's on. So maybe that change doesn't trigger the interrupt?

When I used pulseIn() I get 1050 when the switch is off and 1880 when it's on. So maybe that change doesn't trigger the interrupt?

Those values are pulse lengths not voltages. The voltage will be varying between 0 and 5V so the interrupt should trigger on every change. Can you try the interrupt with RISING or FALLING ?

Perhaps my code would be usefull for you, I have a Turnigy 9X too. You could see any idea. Sorry but my blog is in spanish.