Control 2 servos wireless

Hello!
I've been looking for some help with my problem on older topics but I cant find any, so here it goes.
I'm also not a english native speaker so sorry in advance for any errors.

I'm working on a RC car powered with a gas engine completely homemade, and the car itself is almost done, so I started on the actual remote control itself. The car has 2 servos (throttle and steering) and I want to control them using 2 arduinos (transmiter and reciever).

I already have a code for each arduino but I cant get the servos to work properly. If I make the code for only 1 servo, this same servo will work perfect but as soon as I try to use 2 at the same time they just kinda shake and dont turn at full speed, so I gess my code as something wrong.

Transmiter code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

void setup() {
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00001
  radio.openReadingPipe(1, addresses[0]); // 00002
  radio.setPALevel(RF24_PA_MIN);
}
void loop() {
  int potValue = analogRead(A0);
  int pot2Value = analogRead(A1);
  int angleValue = map(potValue, 0, 1023, 0, 180);
  int angle2Value = map(pot2Value, 0, 1023, 0, 180);
  radio.stopListening();
  radio.write(&angleValue, sizeof(angleValue));
  radio.write(&angle2Value, sizeof(angle2Value));
  delay(5);
  radio.startListening();
 }

Reciever code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
Servo myServo;
Servo myServo2;

void setup() {
  myServo.attach(5);
  myServo2.attach(6);
  radio.begin();
  radio.openWritingPipe(addresses[0]); // 00002
  radio.openReadingPipe(1, addresses[1]); // 00001
  radio.setPALevel(RF24_PA_MIN);
}
void loop() {
  delay(5);
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {
      int angleValue = 0;
      int angle2Value = 0;
      radio.read(&angleValue, sizeof(angleValue));
      radio.read(&angle2Value, sizeof(angle2Value));
      myServo.write(angleValue);
      myServo2.write(angle2Value);
    }
  }}

I'm not very good at programming, this is just altered version of a code I found online.
I'm using 10k potenciometers for now just to make the code work, I'll probably use a joystick pot later on.

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

If you just want one-way communication then just use the first example.

You will make things much easier if you put the two values into an array and send the array as a single message. Something like this

  int potValue = analogRead(A0);
  int pot2Value = analogRead(A1);
  int angleValue[2]
  angleValue[0] = map(potValue, 0, 1023, 0, 180);
  angleValue[1] = map(pot2Value, 0, 1023, 0, 180);

  radio.write(&angleValue, sizeof(angleValue));

You should have an identical array in the receiver code

But, as I said, get the simple wireless communication working first

...R

It works!! :slight_smile:

I put two values into a single array and sent the array as a single message, like you suggested and both servos works really nicely now, fluent and fast.

Thank you.