2
\$\begingroup\$

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.

[UPDATE] After a great deal of discussion on http://forum.arduino.cc/index.php?topic=184283.0 I came to this conclusion. Radio generates PWM signal .. If you have an interrupt pin connected to a channel. It will interrupt regardless of what you do because it is constantly generating a PWM. So I am leaning towards interrupt is not a good idea for radio control.

\$\endgroup\$
6
  • \$\begingroup\$ What kind of receiver are you using? Some of the cheap OOK receiver modules will receive junk the whole time there's not a carrier. \$\endgroup\$ – PeterJ Aug 24 '13 at 4:42
  • \$\begingroup\$ Yes it is a hobbyking T6A V2 6 channel reciever 30 dollar kit. \$\endgroup\$ – Rabin Aug 24 '13 at 14:39
  • \$\begingroup\$ I don't know if this is the right way to check ,, But when I check the data line of the reciever, the Voltage is 0.27 constant, On change of the transmitter handle the voltagegoes to 0.32/ 0.22. So I don't think there is any junk. Or what do you think? – Rabin 52 mins ago \$\endgroup\$ – Rabin Aug 24 '13 at 15:58
  • \$\begingroup\$ If I'm not mistaken - this is a model aircraft remote. The receiver drives "servos" directly - it is not a logic on/off output. It provides a PWM type output that controls a servo with a varying frequency pulse stream. You would have to decipher the output as such - not by sampling for logical on/off. \$\endgroup\$ – Ron J. Aug 24 '13 at 20:48
  • \$\begingroup\$ Yes you are correct. \$\endgroup\$ – Rabin Aug 24 '13 at 20:50
1
\$\begingroup\$

As you've determined that kind of receiver will have a PWM output to control a servo, the Wikipedia Servo Control article has some good information about it. If you wanted to use it anyway the normal neutral position will be 1.5mS so you could use something like the following code that uses the pulseIn function to treat a pulse of 1.75mS or longer as being on:

#define MY_PIN 0

void setup() {
    Serial.begin(9600);
    pinMode(MY_PIN, INPUT);
}

void loop() {
   if (pulseIn(MY_PIN, HIGH) >= 1750)
      Serial.println("TX on");        
}

Note that the typical period between pulses is 20mS so your code will be stalled in pulseIn for around that period. If that's a problem you could go back to using the interrupt and set it for CHANGE and keep track of the time between when the line goes high and low again. It would be something like the following untested code:

#define MY_PIN 0 // Make sure this matches the interrupt line
unsigned long start_micros = 0;
unsigned long last_duration = 0;

void setup() {
    Serial.begin(9600);
    pinMode(MY_PIN, INPUT);
    attachInterrupt(0 , PWM_handler, CHANGE);
}

void loop() {
   if (last_duration >= 1750)
      Serial.println("TX on");        
}

void PWM_hander()
{
    if (digitalRead(MY_PIN) == HIGH)
        start_micros = micros();
    else
        last_duration = micros() - start_micros;
}
\$\endgroup\$
0
\$\begingroup\$

I am unsure if the receiver has an open collector output or not, but it is quite likely. I believe the interrupt pin is pin 2. Add a pinMode( 2 , INPUT_PULLUP ); before the attachInterrupt.

Also your interrupt routine may be a bit long (in duration). It is better to just flash LED on pin 13 or set a flag in the interrupt routine then do some smart stuff with that flag in the main loop.

You may want to check with an oscilloscope if the LED is constantly on or not.

\$\endgroup\$
4
  • \$\begingroup\$ I tried the LED with the pinMode( 2 , INPUT_PULLUP ); The LED constantly flashes.. That means its still going in the interrupt \$\endgroup\$ – Rabin Aug 24 '13 at 15:05
  • \$\begingroup\$ Does the flashing stop if you disconnect pin 2? \$\endgroup\$ – jippie Aug 24 '13 at 15:08
  • \$\begingroup\$ Yes the flashing stops when I turn off my transmitter or disconnct pin 2 \$\endgroup\$ – Rabin Aug 24 '13 at 15:11
  • \$\begingroup\$ Then it seems an issue with the receiver, not with Arduino. \$\endgroup\$ – jippie Aug 24 '13 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.