Sending multiple values with a nrf24l01

Hi,
I've been trying to use two nrf24l01s to send readings from two different pots to another nrf24l01 and display it on a lcd. I've been able to use code from the forum to send one pot value just fine, but so far I haven't had any luck being able to send a second pot value.

This is the transmitter code that I've been trying to make work,

#include <Mirf.h>
#include <nRF24L01.h>
#include <Spi (2).h>

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
int potpin2 = 1;
int val2;

void setup(){
  
  Mirf.init();
  Mirf.setRADDR((byte *)"clie1");
  Mirf.payload = sizeof(long);
  
  Mirf.config();
  
}
void loop(){
  
  val = analogRead(potpin);    // reads the value of the potentiometer (value between 0 and 1023) 
  val2 = analogRead(potpin2);
   val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
 val2 = map(val2, 0, 1023, 0, 179);
  
  byte joyStick[2];
       joyStick[0] = val;
       joyStick[1] = val2; 
  
  unsigned long time = millis();
  long time_long = long(time);
  Mirf.setTADDR((byte *)"serv1");
  Mirf.send((byte *)&joyStick);
  
  while(Mirf.isSending()){
  }
  
  delay(10);
  while(!Mirf.dataReady()){
    if ( (millis() - time) > 100){
      
      break;
  }}
  Mirf.getData((byte *) &time);
  
  delay(100);
}

And this is the code for the reciever,

#include <Mirf.h>
#include <nRF24L01.h>
#include <Spi (2).h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(0,1,5,4,3,2);
byte joyStick[2];


void setup(){
  
  lcd.begin(16,2);
  
  Mirf.csnPin = 8;
  Mirf.cePin = 7;
  Mirf.init();
  Mirf.setRADDR((byte *)"serv1");
  Mirf.payload = sizeof(long);
  Mirf.config();
  
  }
void loop(){
  byte data[Mirf.payload];
  if(Mirf.dataReady()){
    do{
      
      Mirf.getData(&joyStick[2]); 
      long time_long = long(data);
     
      lcd.clear();
      lcd.setCursor(5,0);
      lcd.print(joyStick[0], DEC);  // print as an ASCII-encoded decimal
      lcd.setCursor(5,1);
      lcd.print(joyStick[1], DEC);
      
    }while(!Mirf.rxFifoEmpty());
  }
}

Some of the code is changed from the working code I had to try and make it work for sending two values.
Any help would be appreciated,
Brian

  Mirf.payload = sizeof(long);

A long is 4 bytes.

  byte joyStick[2];
       joyStick[0] = val;
       joyStick[1] = val2; 
  
  unsigned long time = millis();
  long time_long = long(time);
  Mirf.setTADDR((byte *)"serv1");
  Mirf.send((byte *)&joyStick);

If you want the time as a long, why are you saving it is an unsigned long?

If you are setting the payload size to 4 bytes, why are you only sending 2?

byte joyStick[2];
Mirf.getData(&joyStick[2]);

You have allocated space for 2 bytes, but you are asking Mirf to store the data staring in the 3rd byte. How well is that working for you?

Since you stored the data in bytes 0 and 1 of your long, you want to read from positions 0 and 1 as well. You're currently reading a long into the second half of a long, which will write to parts of memory it shouldn't. Then you're reading the first half of the long, which is going to get you some garbage.

Change the array to have 4 bytes, and then change the getData(&joystick[2]) to getData(&joystick).

I finally got around working on the code some more. If my array needs to have 4 bytes does that mean it should look like this

 byte joyStick[2];
       joyStick[0] = val;    //values from the pots
       joyStick[1] = val2;
       joyStick[2] = 0;
       joyStick[3] = 0;

Is there a better way to store and send multiple values other than using an array, and if there isn't where is the best place to learn how to use arrays?

Thanks,

Brian

If my array needs to have 4 bytes does that mean it should look like this

See comments

 byte joyStick[2]; // Declare the array to hold 2 values
       joyStick[0] = val;    //values from the pots
       joyStick[1] = val2;
       joyStick[2] = 0; // Oops, no room
       joyStick[3] = 0; // Oops, no room

Declare your data as you want it, here I'm guessing

byte joyStick [2];

Make the payload the actual size of your data

  Mirf.payload = sizeof (joyStick) ;

Read into the array starting at the start:

      Mirf.getData (joyStick) ;

simple!