Problem Controlling 2 Servos in Sync

Hello I am controlling multiple servos on a glider and I am having issues with the servo on each wing as there is a slight delay between them. I am using 2 NRF24L01 for communication between 2 Arduino Nanos.

In my code Servo 1 and 2 are the issues as they do not sync properly.

Any ideas?

Glider.ino (711 Bytes)

OP's Code

#include <Servo.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
  
Servo servo1;
Servo servo2;
Servo servo3;
int joyX = 0;
int joyY = 1;

int Array [2];

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

void setup() {
  servo1.attach(9);
  servo2.attach(5);
  servo3.attach(2);

  radio.begin();
  radio.openReadingPipe(1, addresses[1]);
  radio.setPALevel(RF24_PA_MIN);
}
  
void loop() {
  radio.startListening();
  while (!radio.available());
  radio.read(&Array, sizeof(Array));
  
  servo1.write (map(Array[0], 0, 1023, 0, 180));
  servo2.write (map(Array[0], 0, 1023, 180, 0));
  servo3.write (map(Array[1], 0, 1023, 0 ,180));
}

Caldercurtis, have a read through this page to learn how to use and get the most out of this forum.

caldercurtis:
Hello I am controlling multiple servos on a glider and I am having issues with the servo on each wing as there is a slight delay between them. I am using 2 NRF24L01 for communication between 2 Arduino Nanos.

In my code Servo 1 and 2 are the issues as they do not sync properly.

How long (in millisecs) is the slight delay?
What do you mean by "do not sync propelrly"?

Add some code to print the values that the wireless receives. If they are correct then you need to look elsewhere for the problem.

If this was my project I would write the code like this

void loop() {
  if (radio.available()) {
     radio.read(&Array, sizeof(Array));
  }
  
  servo1.write (map(Array[0], 0, 1023, 0, 180));
  servo2.write (map(Array[0], 0, 1023, 180, 0));
  servo3.write (map(Array[1], 0, 1023, 0 ,180));
}

and I would put radio.startListening() in setup()

I would also convert the values in the TX program so that there is no need to use map() in the RX program.

...R