AttatchInterrupt Constantly interrupts

I am a new to electronics. I am trying to setup the radio control for the arduino. I hooked up the Reciever's Channel 1 to the Arduino Mega 2560's Digital pin 2, Reciever Vin to Arduino 5V, and Ground to Ard Ground. Here is my Source Code.

void setup() {
Serial.begin(9600);
attachInterrupt(0 , blink, CHANGE);
}

void loop() {
Serial.println("I AM IN THE LOOP");

}

void blink()
{

Serial.println("I AM IN THE INTERRUPT");
}
I tried using other interrupt pins,3.3 V instead of 5 and also tried Arduino Uno and differnt kinds of Interrupt Values like RISING, LOW and FALLING but it constantly prints " I AM IN THE INTERRUPT" without me touching the transmitter. Any suggestions.

Connect the interrupt pin to +5 with a 10K resistor.
Then, with a wire, touch that pin to Gnd - letting go will result a RISING interrupt.

int times = 0;
volatile boolean Detect = false;  // Interrupt Note 

void setup()
{
  //Serial.begin(9600);
  attachInterrupt(0,Activity,RISING);  // Ext_Int on D2
  Serial.println("Initiated..");
}

void loop()
{
  if (Detect == true)
  {
    Action();
  }
}

void Activity()   // this is the Interrupt !
{
  Detect = true;
}

void Action ()
{
  Detect = false;
  times ++;
  Serial.println("INTerrupt!");
  Serial.println(times,DEC);
  Serial.println("waiting");
}

I am sorry I don't follow. I am trying to get an interrupt from the radio transmitter. So, when I move the channel 1 handle on the tranmitter it generates a Interrupt,
Since, the reciever's channel is connected to the interrupt pin. And again it's not that I am not getting any interrupt, but I am getting a constant interrupt regardless of me moving the transmitter handle . I am sorry i am a beginner. Does that makes sense?

OK

Given

khadkara:
I am a new to electronics.

and

khadkara:
i am a beginner.

I was trying to establish a baseline here.
Less than reasonable?

What he was trying to do was break the problem into smaller problems.
a) first make sure the interrupt works as it should
b) then connect the receiver.

And. Btw. don't use Serial in interrupt. Could cause corruption

As for your case, it is unknown how the signal looks from your receiver. What kind of output is it? does it need pull-up (i.e. the 10K resistor)?
happen to have a scope?
he interrupt alternative will work so then your problem shoudl be found in either crap connections or the receiver might be sending out garbage.

An RC receiver puts out PWM to the servos, right?

groundfungus:
An RC receiver puts out PWM to the servos, right?

Yes. So it is constantly turning on and off and causing an interrupt, which I think was your point.

I see what you are doing.. Ok I tried your code. And, yes it did interrupt when i touch the pin to the ground.

nicoverduin:
What he was trying to do was break the problem into smaller problems.
a) first make sure the interrupt works as it should
b) then connect the receiver.

And. Btw. don't use Serial in interrupt. Could cause corruption

As for your case, it is unknown how the signal looks from your receiver. What kind of output is it? does it need pull-up (i.e. the 10K resistor)?
happen to have a scope?
he interrupt alternative will work so then your problem shoudl be found in either crap connections or the receiver might be sending out garbage.

I see. I have triple checked my connection, and I think there should be no problem with the connection. I also tried with the 10K resistor same problem. So now I am leaning towards the " reciever might be sending out garbage" . So how do I resolve this or check if it is sendin garbage. ? Thank you

UKHeliBob:

groundfungus:
An RC receiver puts out PWM to the servos, right?

Yes. So it is constantly turning on and off and causing an interrupt, which I think was your point.

So you probably don't need the Arduino at the receiver end?

khadkara:

[quote author=Runaway Pancake link=topic=184283.msg1364937#msg1364937 date=1377362769]
OK

Given

khadkara:
I am a new to electronics.

and

khadkara:
i am a beginner.

I was trying to establish a baseline here.
Less than reasonable?

I see what you are doing.. Ok I tried your code. And, yes it did interrupt when i touch the pin to the ground.
[/quote]

So, the interrupt works when the pin goes to 0V. Now, ask yourself how often the output from the RC channel goes to 0V bearing in mind the previous answers.

Are you sure that you need to use an interrupt at all ?

Try this

int pin = 7;  //connect the receiver output to this pin.  You also need a common ground or power the Rx from the Arduino
unsigned long duration;

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

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

GoForSmoke:

UKHeliBob:

groundfungus:
An RC receiver puts out PWM to the servos, right?

Yes. So it is constantly turning on and off and causing an interrupt, which I think was your point.

So you probably don't need the Arduino at the receiver end?

You can have better control if you use arduino in the middle, SInce you can write your own PWM based on the Transmitter's response. This takes away the hassle of configuring your radio transmitter.

UKHeliBob:

khadkara:

[quote author=Runaway Pancake link=topic=184283.msg1364937#msg1364937 date=1377362769]
OK

Given

khadkara:
I am a new to electronics.

and

khadkara:
i am a beginner.

I was trying to establish a baseline here.
Less than reasonable?

I see what you are doing.. Ok I tried your code. And, yes it did interrupt when i touch the pin to the ground.

So, the interrupt works when the pin goes to 0V. Now, ask yourself how often the output from the RC channel goes to 0V bearing in mind the previous answers.

Are you sure that you need to use an interrupt at all ?

Try this

int pin = 7;  //connect the receiver output to this pin.  You also need a common ground or power the Rx from the Arduino
unsigned long duration;

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

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

[/quote]

Yes this works Fine. But this is a small problem I took out from my Project. It's a quadcopter Project. I am doing Radio control through Interrupt and PID tuning in the void loop()

Understood, but because the output from the receiver is a PWM signal which constantly goes from zero to five volts and back an interrupt is not going to work as far as I can see.

How long does one iteration of your loop() function take compared to how often you need to read the inputs from the receiver ?

How about reading the inputs in loop() and using a timer interrupt to trigger the PID calculations ?

Are you using a PID library or have you written your own ? The PID library that I have used has a method to set the sample time Arduino Playground - HomePage

UKHeliBob:
Understood, but because the output from the receiver is a PWM signal which constantly goes from zero to five volts and back an interrupt is not going to work as far as I can see.

How long does one iteration of your loop() function take compared to how often you need to read the inputs from the receiver ?

How about reading the inputs in loop() and using a timer interrupt to trigger the PID calculations ?

Are you using a PID library or have you written your own ? The PID library that I have used has a method to set the sample time Arduino Playground - HomePage

That is a simple approach. Sounds great. I will go that route then... But just curious... Is there no way to configure the radio PWM signal to a regular signal

Ok I saw a similar problem before.

Tel me are you using a Mega you bouth from China? And also are you using a nrf24 unit?

If it's the case, your problem probably reside in a faulty 3,3volt alimentation on you Mega unit. Just try to use a external power supply that give 3,3v Like a computer power supply.

Is there no way to configure the radio PWM signal to a regular signal

What is a "regular signal"?

Frédéric_Plante:
Ok I saw a similar problem before.

Tel me are you using a Mega you bouth from China? And also are you using a nrf24 unit?

If it's the case, your problem probably reside in a faulty 3,3volt alimentation on you Mega unit. Just try to use a external power supply that give 3,3v Like a computer power supply.

Yes ... I tried with the Mega From China.. But, I also tried a geniune Arduino UNO from adafruit.com . It's the same.. But it makes sense I think. Because the radio transmitter sends PWM. And even when I don't move the transmitter handle it's sending 0 , 2.6 , 0 , 2.6.... when the handle is moves to the right 0, 3. 2 and on left 0, 2.0 .. So if there is an interrupt on Change or Rising or Falling ,, it will constantly interrupt because of the Pulses. Don't you think ?

AWOL:

Is there no way to configure the radio PWM signal to a regular signal

What is a "regular signal"?

Oops!! I meant to configue the Transmitter not to send Pulse, But constant voltage.

I meant to configue the Transmitter not to send Pulse, But constant voltage.

What kind of equipment are we talking about here?
What good would an interrupt do in such a situation?