RC-Reciever to Servo -- Problem with RC-Lib


First of all to my Project. I am building a radio controlled model car, driven by two engines at the rear wheels.
I would like to realise a tourque vectoring programm. Therefor i want to read the Throttle-Signal and the Steering signal from the reciever, apply my algorithm and put out the Signal for the engine controllers.
I also want to control the steering over the controller. At first just put it through 1:1, but maybe realize a stabilization programm or something.

However i want to use the RC-Lib with ServoIn and ServoOut here:

The ServoIn Function itself works perfectly. I can read the Signal fom the Reciver and see the values if i print it at the Serial.

The ServoOut Function itself also works perfectly. If i write a constant Number in the Output buffer, the servos react correct.

Both functions together also work if i write a constant number to the Output Buffer.
As soon i write a variable to the Output Buffer i get unexplainable Problems. If i wrte a Variable to it usually the Secound Output i use simply doesn’t work…sometimes two work, sometimes only one. Its not really reproduceable.
The variables are correct, because i also print them on the Serial.

My code (doesn’t work) at the moment is this:

#include <ServoIn.h>
#include <ServoOut.h>
#include <Timer1.h>

#define INPUTS 3
#define OUTPUTS 3

uint8_t  g_pinsIn[OUTPUTS] = {8, 9, 10};
uint16_t g_values[INPUTS];                    // output buffer for ServoIn
uint8_t  g_workIn[SERVOIN_WORK_SIZE(INPUTS)]; // we need to have a work buffer for the ServoIn class
rc::ServoIn g_ServoIn(g_values, g_workIn, INPUTS);
uint8_t  g_pinsOut[OUTPUTS] = {2, 3, 4};    // Output pins
uint16_t g_input[OUTPUTS];                     // Input buffer for servoOut, microseconds
uint8_t  g_work[SERVOOUT_WORK_SIZE(OUTPUTS)];  // we need to have a work buffer for the ServoOut class

void setup()
	// Initialize timer1, this is required for all features that use Timer1
	// (PPMIn/PPMOut/ServoIn/ServoOut)
	// We use pin 8-11 as Servo input pins
	for (uint8_t i = 0;  i < INPUTS; ++i)
		pinMode(g_pinsIn[i], INPUT);
	// We use pin change interrupts to detect changes in the signal
	// If you're unfamiliar with how this works, please look up some
	// article or tutorial on the subject.	
	// only allow pin change interrupts for PB0-3 (digital pins 8-11)
	PCMSK0 = (1 << PCINT0) | (1 << PCINT1) | (1 << PCINT2);	
	// enable pin change interrupt 0
	PCICR = (1 << PCIE0);
	// start listening
	for (uint8_t i = 0;  i < SERVOS; ++i)
		// set up output pins
		pinMode(g_pinsOut[i], OUTPUT);		
		// put them low
		digitalWrite(g_pinsOut[i], LOW);		
		// fill input buffer
		g_input[i] = 1500;

void loop()
	// update incoming values
	// update outgoing values

// Interrupt handling code below, this needs cleaning

static uint8_t lastB = 0;

// Pin change port 0 interrupt
	// we need to call the ServoIn ISR here, keep code in the ISR to a minimum!
	uint8_t newB = PINB;
	uint8_t chgB = newB ^ lastB; // bitwise XOR will set all bits that have changed
	lastB = newB;
	// has any of the pins changed?
	if (chgB)
		// find out which pin has changed
		if (chgB & _BV(0))
			g_ServoIn.pinChanged(0, newB & _BV(0));
		if (chgB & _BV(1))
			g_ServoIn.pinChanged(1, newB & _BV(1));
		if (chgB & _BV(2))
			g_ServoIn.pinChanged(2, newB & _BV(2));
		if (chgB & _BV(3))
			g_ServoIn.pinChanged(3, newB & _BV(3));

Did already someone work with the RC-Lib? In the shown case, i get the Signal from the first Reciever channel at the secound and the thierd output and the first output doesn’t work.

If i replace this:


with this:


it works and i get the three signals with 1000us, 1500us and 2000us at the correct output ports.

I am really confused and don’t know why it isn’t working with variables.

First off - I have never used this library - so this might be the "blind-leading-the-blind" - that said...

...I have to ask - what version of the library are you using?

Because in the examples I see that come with the latest version of the library - specifically the examples referencing ServoIn and ServoOut - neither one of them show the setup and use of an ISR routine or a pin-change interrupt.

I tend to wonder if somehow that may be related to the issue you're having?

Beyond that, I can't offer anything else, other than to ask whether you have successfully been able to execute and use the "ServoOut" example that comes with the library (which seems to be the closest library example to what your example code is doing)?

Hello, thank you for your answer.
I am using the ArduinoRCLib-0.3, wich is as far i can tell the latest version.

The ServoOut example doesn't use the pin-change interrupt but the ServoIn example does.

Yes i tried the ServoOut example as it is with Potentiometers and it works perfectly.