Sending an array via Nrf24l01

Hi,

I am sending an array via the NRF24L01, but I'm having a problem where the receiving side is not getting the correct values. Specifically, when I send an array with 8 values, the receiver gets 0 0 1 0 2 0 3 0 instead of 0 1 2 3 4 5 6 7. Even if I increase the size of the array, I get the same thing with zeros in between ( 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0). This isn't a big problem for me, but I would like to know why this is happening or what I might be doing wrong.

Thank you.

Transmitter code:

#include <Arduino.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


RF24 radio(4, 5); // CE, CSN

const byte address[6] = "00001";

int values[8] = {0,1,2,3,4,5,6,7};

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();

  Serial.begin(9600);


}

void loop() {

      radio.write(values, sizeof(values));

}

Receiver code:

#include <Arduino.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(A4, A5); // CE, CSN

const byte address[6] = "00001";
int values[8];


void setup() {
  Serial.begin(9600);
  radio.begin(A4, A5);
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();

}

void loop() {
  if (radio.available()) {
    radio.read(values, sizeof(values));

    for(int i = 0; i <8; i++){
      Serial.print(values[i]);
      Serial.print(" ");
    }
    
    Serial.println("");

  }
  


}

Which Arduino boards are you using at each end of the radio link ?

The transmitter is an ESP32 and on the receiving end an Arduino Mega.

Check the size of an int on each of those boards. They are not the same. Hence the problem

Use

uint8_t values[8] = {0,1,2,3,4,5,6,7};

In the declaration of the array in both sketches or if each value will never exceed 255 declare both as type byte

Thanks, it works. Just one more thing, what if I want to send negative values?

Declare the array as type int16_t

Actually, if the values are to be greater than 255 they should be declared as uint16_t in your original sketch. My mistake