Go Down

Topic: Decoding Radio Control signal pulses (Read 75912 times) previous topic - next topic


I have tried to use ServoDecode on a Duemilanove-Board and it works perfectly - thank you! However, when using the same sketch on the new Mega-Board the library says "no sync" - any insight what needs to be changed?


The chip used on the mega board has the hardware connected differently than the 168. I need to modify the library for it to work (timer1 Input Capture is not connected to an Arduino pin so I will need to use a different timer on the mega board)

If you don't see something posted in a week or so, send me a PM to remind me.  


Thank you so much for extending the library! :)


Hi guys, it is getting dificult to get this task forward, when i compile this sketch, i got some error messages as follows.

// ServoDecodeTest
#include <Servodecode.h>
#include <ServoTimer2.h>  // the servo library

// define the servo pins
#define servo1Pin 2   //the pin the servo is attached to
#define servo2Pin 3

ServoTimer2 servo1;    // declare variables for the servos
ServoTimer2 servo2;

void setup()

void loop()
 int pulsewidth[MAX_CHANNELS];

 if (ServoDecode.getState()!= READY_state) {
   Serial.println("The decoder is not ready");
 else {
   // decoder is ready, do something with the channel pulse widths
   if (ServoDecode.GetChannelPulseWidth(1) > 1500)
   {  // run script 1 if pulse width greater than 1500 ;
     int argumentA = (2250 - ServoDecode.GetChannelPulseWidth(2)) / 200; // some values proportional to stick position
     boolean argumentB = ServoDecode.GetChannelPulseWidth(2) < 1500; // true if channel 2 less than 1500
     runScript1(argumentA, argumentB);
 delay(100); // update 10 times a second

void  runScript1(int argumentA, boolean argumentB)

{ // do something here to control servo...
 delay(5000);  // note that all servo are pulsed by the interrupt handler with their current value every 20ms
 if (argumentA)
 delay(argumentB * 10); //delay a time determined by the transmitter stick position


In file included from C:\Users\ABBA\Desktop\arduino-0013-Servo Decode\hardware\cores\arduino/WProgram.h:4,

c:/users/abba/desktop/arduino-0013-servo decode/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

c:/users/abba/desktop/arduino-0013-servo decode/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

c:/users/abba/desktop/arduino-0013-servo decode/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

In file included from C:\Users\ABBA\Desktop\arduino-0013-Servo Decode\hardware\cores\arduino/WProgram.h:6,

thanks in advance.


Apr 17, 2009, 04:16 pm Last Edit: Apr 17, 2009, 04:41 pm by mem Reason: 1
gmv, from the look of those messages, I think you are not using the latest versions of the libraries, they were both updated to work with recent Arduino releases. Your sketch compiles ok for me (although I needed to remove an extra curly brackets }  before the first else in loop)

Check that you have the latest versions of both libraries.
You can find the latest version of ServoDecode in this thread and ServoTimer2 is here:


Apr 17, 2009, 07:09 pm Last Edit: Apr 17, 2009, 07:31 pm by gmv Reason: 1
Hi mem, many thanks...now i got it compling,..., i´ve loaded the sketch to the board and connected the PPM frame output of my Futaba to pin 8, the servo to pin 3 or 2 but i couldn´t get it moving when i move the sticks of my radio, also on my serial monitor, i got the message "the decoder is not ready ",...do you think it could have anything to do with inverted signals ?......any ideias what could be ? :-/

thanks again


Apr 18, 2009, 05:45 pm Last Edit: Apr 18, 2009, 05:46 pm by mem Reason: 1
Why not try it with the example sketch posted in this thread. If it still doesn't work, then you can try inverting the pulse detection as follows:  replace the line in ServoDecode.cpp:
[font=Courier New]volatile byte pulseEnd = PULSE_START_ON_RISING_EDGE ; // default value[/font]
[font=Courier New]volatile byte pulseEnd = PULSE_START_ON_FALLING_EDGE ; [/font]

delete SevoDecode.o and then rebuild your sketch.


Apr 18, 2009, 10:08 pm Last Edit: Apr 18, 2009, 10:23 pm by gmv Reason: 1
Hi mem, this morning i finally could make it work as expected, now i can drive all servos from my Tx !

Now my next goal is to drive a relay, just using one servo output from the Arduino Board . :)

Any ideias are welcome.



GMV, good to hear you have it working, was it inverting the pulse or something else that got it going?

You can control a relay by using the pulse width returned from the GetChannelPulseWidth method. If the pulse is above (or below) a given threshold you can set a pin high. There is info on connecting relay here if you need it: http://www.arduino.cc/playground/uploads/Learning/relays.pdf


Hi mem, i didn´t inverted the pulses,...., only deleted old arduino´s folders and instaled the new version and created a new sketch based on the servotest sketch that you mentioned on the previous page, made some changes and voilá !

Listen, i´ll try to implement your ideia for driving the relay, but then if i needed to drive 8 relay´s from a single pwm output, do i need any extra library´s or the existing ones (servo.*, servodecode.*, servotimer2:
) are enough ?

Could you give some example of a code from where i could starting working ?  8-)

 thanks in advance


Apr 19, 2009, 12:05 pm Last Edit: Apr 19, 2009, 04:00 pm by mem Reason: 1
gmv, if you post a fragment of your sketch indicating where you want the relays to be triggered I will be happy to guide you with the code. I suggest you start a new thread for your specific application.


This is the pin description of the buddy port of my Sanwa RD6000 (Airtronics equivalen):

1 = ??
2 = Ground
3 = OUT
4 = +V switched
5 = IN

If I am correct, I have to connect pin 2 of buddy port to gnd on Arduino and pin 3 on buddy port to pin 8 of Arduino.

Can anyone confirm?

I have tried it this way and I get the "The decoder is in Failsafe" message all the time.


I have no experience with the sanwa. It is possible that the signal is inverted so it my be worth recompiling the library to use an inverted signal. A search in this thread should turn up the information on how do to it.

some keywords to try in the search are : pulseEnd PULSE_START_ON_FALLING_EDGE


I tried that, but I get
Code: [Select]
The decoder is NOT_SYNCHED

Cx0= 0  Cx1= 0  Cx2= 0  Cx3= 0  Cx4= 0  Cx5= 0  Cx6= 0  Cx7= 0  Cx8= 0

Maybe the voltage level is not high enough?

Go Up