ESP32 and NRF24 is not working

Hello all,

I want to send 6 values from an arduino nano to a ESP32 devkit v1 via nrf24 but i have some issues.
i have this two codes:
this is for the transmitter:

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

RF24 radio(7, 8); // Inițializarea obiectului NRF24 pentru pinii CE și CSN

const byte adresa[6] = "00001"; // Adresa de transmisie

void setup() {
  radio.begin();
  radio.openWritingPipe(adresa);
}

void loop() {
  int vector[6] = {10, 20, 30, 40, 50, 60}; // Vectorul de 6 variabile (exemplu)

  radio.write(vector, sizeof(vector)); // Trimiterea vectorului de 6 variabile

  delay(1000); // Așteptare pentru a trimite din nou
}

and this for receiver:

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

RF24 radio(4, 5); // Inițializarea obiectului NRF24 pentru pinii CE și CSN

const byte adresa[6] = "00001"; // Adresa de recepție

void setup() {
  radio.begin();
  radio.openReadingPipe(1, adresa);
  radio.startListening();
  Serial.begin(9600);
}

void loop() {
  if (radio.available()) {
    int vectorReceptionat[6]; // Vectorul pentru datele receptionate

    radio.read(&vectorReceptionat, sizeof(vectorReceptionat)); // Recepționarea vectorului de 6 variabile

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

    delay(1000); 
  }
}

'
and the values get so bad at the ESP.... something like "1310730 2621470 3932210 0 0 0"
I have tried this receiver code on with another nano and it works...
I have checked the connections so many times that i can make them with my eyes closed!
Please help me! Thank you.

Welcome to the forum

An int on the ESP32 takes 4 bytes of storage whereas and int on a Nano takes 2 bytes so your two structs do not actually have the same data layout

do you have a solution for this?

Solved by using uint16_t to initialize vectorReceptionat[6]. Thank you for the help!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.