A punto de tirar NRF24L01 a la basura

Hola Chicos/as...

Tras tres días de pruebas y enfados, antes de tirar estos módulos a al basura, he decidido preguntar aquí.

Se trata de dos modulos NRF24L01 con antena en PCB y dos UNOS.
He seguido una docena de tutoriales con diferentes codigos y conexiones...No hay manera de que comuniquen entre ellos...He leido creo que todo sobre ellos en este foro, pero sigo sin conseguirlo...
Le he puesto los dos condensadores electroliticos de 10uF entre VCC y GND en el propio modulo...

Estos son los dos ultimos codigos utilizados...despues de descartar varios:

// SimpleTx - the master or the transmitter

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


#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

Y como receptor:

// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

//===========

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    }
}

No se entienden entre ellos.

Esta info la he sacado de este enlace del foro:
Codigos y conexiones sacadas de aqui:

En ese hilo, sugieren un codigo de prueba ente arduino y NRF24....Lo he subido pero como novato, no entiendo el resultado:

Este es el código de pruebas:

// 18 Mar 2018 - simple program to verify connection between Arduino
//      and nRF24L01+
//  This program does NOT attempt any communication with another nRF24

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

#include <printf.h>

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;


void setup() {
    Serial.begin(9600);
    printf_begin();

    Serial.println("CheckConnection Starting");
    Serial.println();
    Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
    Serial.println("  Note that RF24 does NOT reset when Arduino resets - only when power is removed");
    Serial.println("  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
    Serial.println("     communicating with the nRF24");
    Serial.println();
    radio.begin();
    radio.printDetails();
    Serial.println();
    Serial.println();
    Serial.println("AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1");
    Serial.println(" and 250KBPS data rate");
    Serial.println();
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.setDataRate( RF24_250KBPS );
    radio.printDetails();
    Serial.println();
    Serial.println();
}


void loop() {

}

Tras ejecutar ese test en ambos arduinos con sus respectivos NRF24, las respuestas de cada uno han sido estas pero ni idea si ellas indican que tengo bien las coxexiones y si los modulos están funcionando bien:

CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24

STATUS.. = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1.. = 0xe7e7e7e7e7 0x0000000106
RX_ADDR_P2-5.. = 0xc3 0xc4 0xc5 0xc6
TX_ADDR.. = 0xe7e7e7e7e7
RX_PW_P0-6.. = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA.. = 0x3f
EN_RXADDR.. = 0x03
RF_CH.. = 0x4c
RF_SETUP.. = 0x07
CONFIG.. = 0x0c
DYNPD/FEATURE.. = 0x00 0x00
Data Rate. = 1MBPS
Model.. = nRF24L01+
CRC Length. = 16 bits
PA Power. = PA_HIGH


AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate

STATUS.. = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1.. = 0xe7e7e7e7e7 0x0000000106
RX_ADDR_P2-5.. = 0xc3 0xc4 0xc5 0xc6
TX_ADDR.. = 0xe7e7e7e7e7
RX_PW_P0-6.. = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA.. = 0x3f
EN_RXADDR.. = 0x03

RF_CH.. = 0x4c
RF_SETUP.. = 0x27
CONFIG.. = 0x0c
DYNPD/FEATURE.. = 0x00 0x00
Data Rate. = 250KBPS
Model.. = nRF24L01+
CRC Length. = 16 bits
PA Power. = PA_HIGH
CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed

  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24


STATUS.. = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1.. = 0xe7e7e7e7e7 0x0000000106
RX_ADDR_P2-5.. = 0xc3 0xc4 0xc5 0xc6

TX_ADDR.. = 0xe7e7e7e7e7
RX_PW_P0-6.. = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA.. = 0x3f
EN_RXADDR.. = 0x03
RF_CH.. = 0x4c
RF_SETUP.. = 0x07
CONFIG.. = 0x0c
DYNPD/FEATURE.. = 0x00 0x00

Data Rate. = 1MBPS
Model.. = nRF24L01+
CRC Length. = 16 bits
PA Power. = PA_HIGH


AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate


STATUS.. = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1.. = 0xe7e7e7e7e7 0x0000000106

RX_ADDR_P2-5.. = 0xc3 0xc4 0xc5 0xc6
TX_ADDR.. = 0xe7e7e7e7e7
RX_PW_P0-6.. = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA.. = 0x3f

EN_RXADDR.. = 0x03

RF_CH.. = 0x4c

RF_SETUP.. = 0x27
CONFIG.. = 0x0c
DYNPD/FEATURE.. = 0x00 0x00
Data Rate. = 250KBPS

Model.. = nRF24L01+
CRC Length. = 16 bits
PA Power. = PA_HIGH

Obviamente, la alimentación la hago a 3.3V con un regulador de tensión entre Arduino UNO(5V) y módulo.

Alguien me podría sugerir por donde buscar el problema ??? Solo pretendo que un módulo de ordenes al otro y conteste y viceversa.

Gracias de antemano

HI,
Adjjunto un link que yo use cuando estaba experimentado con los NRF24L01. En el explica los dos tipo de NRF2401 el de antena y sin aantena y tiene un sketch bien sencillo para probar la comunicacion. Dale un victazo par ver si te ayuda a resolver tu problema.

Link: https://lastminuteengineers.com/nrf24l01-arduino-wireless-communication/

Te estan funcionando correctamente. Solo que no interpretas lo que lees.
Si no funcionaran las respestas serian casi todas 0s.

Acá te lo dice con claridad, un poco de Google Translate te hubiera servido para entender pero tranquilo y lee esto

Dice:

FIRST WITH THE DEFAULT ADDRESSES after power on
Note that RF24 does NOT reset when Arduino resets - only when power is removed
If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
communicating with the nRF24

Lo paso por Google Translate como si yo fuera vos (tu)

PRIMERO CON LAS DIRECCIONES PREDETERMINADAS después del encendido
Tenga en cuenta que RF24 NO se reinicia cuando Arduino se reinicia, solo cuando se corta la alimentación
Si los números son en su mayoría 0x00 o 0xff, significa que el Arduino no es
comunicarse con el nRF24

Explico: Con las direcciones por defecto. Mas allá del tema reinicio que solo cuando apagas/prendes el arduino o mejor dicho cuando el nRF24 lo recepciona es cuando hay cambios en el.

Lo de los 0s o 0xff es mas que obvio creo yo Si los recibes en su mayoría es porque NO FUNCIONA pero en tu caso SI FUNCIONA.
Solo que te has quedado esperando no se que? Es un código de TESTEO y te dice que todo esta OK.

Cambia de 2MB A 1MB a 250KB que son las 3 velocidad posibles. Las 3 funcionaron perfectamente.

Ahora 2do paso
Prueba GettingStarted.ino

/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/
#include <SPI.h>
#include "RF24.h"
/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 0;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving
bool role = 0;
void setup() {
  Serial.begin(115200);
  Serial.println(F("RF24/examples/GettingStarted"));
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
  
  radio.begin();
  // Set the PA Level low to prevent power supply related issues since this is a
 // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  radio.setPALevel(RF24_PA_LOW);
  
  // Open a writing and reading pipe on each radio, with opposite addresses
  if(radioNumber){
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1,addresses[0]);
  }else{
    radio.openWritingPipe(addresses[0]);
    radio.openReadingPipe(1,addresses[1]);
  }
  
  // Start the radio listening for data
  radio.startListening();
}
void loop() {
  
  
/****************** Ping Out Role ***************************/  
if (role == 1)  {
    
    radio.stopListening();                                    // First, stop listening so we can talk.
    
    
    Serial.println(F("Now sending"));
    unsigned long start_time = micros();                             // Take the time, and send it.  This will block until complete
     if (!radio.write( &start_time, sizeof(unsigned long) )){
       Serial.println(F("failed"));
     }
        
    radio.startListening();                                    // Now, continue listening
    
    unsigned long started_waiting_at = micros();               // Set up a timeout period, get the current microseconds
    boolean timeout = false;                                   // Set up a variable to indicate if a response was received or not
    
    while ( ! radio.available() ){                             // While nothing is received
      if (micros() - started_waiting_at > 200000 ){            // If waited longer than 200ms, indicate timeout and exit while loop
          timeout = true;
          break;
      }      
    }
        
    if ( timeout ){                                             // Describe the results
        Serial.println(F("Failed, response timed out."));
    }else{
        unsigned long got_time;                                 // Grab the response, compare, and send to debugging spew
        radio.read( &got_time, sizeof(unsigned long) );
        unsigned long end_time = micros();
        
        // Spew it
        Serial.print(F("Sent "));
        Serial.print(start_time);
        Serial.print(F(", Got response "));
        Serial.print(got_time);
        Serial.print(F(", Round-trip delay "));
        Serial.print(end_time-start_time);
        Serial.println(F(" microseconds"));
    }
    // Try again 1s later
    delay(1000);
  }
/****************** Pong Back Role ***************************/
  if ( role == 0 )
  {
    unsigned long got_time;
    
    if( radio.available()){
                                                                    // Variable for the received timestamp
      while (radio.available()) {                                   // While there is data ready
        radio.read( &got_time, sizeof(unsigned long) );             // Get the payload
      }
     
      radio.stopListening();                                        // First, stop listening so we can talk   
      radio.write( &got_time, sizeof(unsigned long) );              // Send the final one back.      
      radio.startListening();                                       // Now, resume listening so we catch the next packets.     
      Serial.print(F("Sent response "));
      Serial.println(got_time);  
   }
 }
/****************** Change Roles via Serial Commands ***************************/
  if ( Serial.available() )
  {
    char c = toupper(Serial.read());
    if ( c == 'T' && role == 0 ){      
      Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
      role = 1;                  // Become the primary transmitter (ping out)
    
   }else
    if ( c == 'R' && role == 1 ){
      Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));      
       role = 0;                // Become the primary receiver (pong back)
       radio.startListening();
       
    }
  }
} // Loop

No puedes copiar este código igual en ambos dispositivos.
Uno debe llamarse 0 y el otro 1 por ejemplo

/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 0;

Lo subes a uno UNO y a otro UNO como dije. El primero con radioNumber = 0 y el segundo con radioNumber = 1.

Lo pones en marcha y con el Monitor serie en uno de los dos cambias el role o bien lo haces por código y ya arranca con rol enviar (sending) y el otro en recibir (receiving)

Resumo si quieres arranca con todo OK

un sketch Envia y sera Nodo1

bool radioNumber = 0;
bool role = 0;

otro sketch recibe y será Nodo2

bool radioNumber = 1;
bool role = 1;

o los dejas y lo haces por monitor Serie. Espero se entienda y no sea confuso.

Moderador:
Ahora DOMPA son preguntas de software no de Hardware. No se porqué lo publicas en esta sección.
Movido.

Gracias a los dos...

El enlace de Tauro0221 tiene muy buena pinta....Lo probaré..
Lo de surbyte tambien...Voy a probar todo..

Muchas gracias

Tauro0221...Con las indicaciones del enlace va de fabula...Gracias
No sé donde estaba el problema, porque ni sugiere que se alimente con 3.3v desde desde fuente externa o con regulador de voltage desde los 5V de arduino. Tampoco sugiere lo de los electroliticos de 10uF...El caso es que por lo menos TX y RX basicos, funcionan.

Muchas gracias

Lo que no entiendo porque no seguiste con los ejemplos de Tmrh20, que son extremadamente completos?

Te agradezco tu ayuda, como siempre muy valiosa.
Después de tantos días peleando con esa librería dandome problemas, por fin he probado la que me sugiere Tauro0221 y funciona, voy a profundizar en ella y luego explicaré lo que no me funcionaba...Ahora necesito unos días de buen funcionamiento para olvidar los fracasos....

Pretendo hacer una especie de RFID pero a 2.4GHz aprovechando el alcance corto que permite(creo).
Asignarles a cada esclavo un numero de ID....
El maestro(base), estará transmitiendo una clave cada 5 segundos con un alcance estimado de 2, 3 o 5 metros máximo.
Cuando un esclavo entra en ese campo, recibe la clave, la reconoce y contesta: -Soy el esclavo ID # XXXXXXX...Entonces si es un esclavo autorizado en la base, esta activa un dispositivo...por ejemplo una cerradura electrica....
Quería hacerlo con RFID puro, pero la distancia es muy escasa...Solo unos 3 o 5 centimetros. por eso opté por esta opción que creo permite acortar la distancia de recepción/transmisión.

Supongo que más adelante exploraré de nuevo Tmrh20...Primero lo basico que me funciona e iré probando otros codigos y librerías de las muchas que hay ...
Gracias

No había visto el enlace de tauro0221.
Toda la explicación es muy buena pero resulta que la librerías que usas es la que te indiqué. La de Tmrh20.
Basicamente fuiste a ejemplos y te encontraste con lo mismo.
Asi que no entiendo qué cambió?

Tal vez necesitabas saber cual elegir de entre todos los ejemplos.
Lo haz resuelto y como ves, hay que ser mas paciente.
Yo tengo cosas que hace meses no funcionan y no las tiro a la basura. De hecho me vendría bien tirar algo de tanto que tengo, jajaja.
La electrónica y mas ESTO es así, mucho de frustración pero es por nuestro propio desconocimiento de lo que estamos haciendo.

Tienes toda la razón...La paciencia no es mi fuerte... Me he ilusionado con este proyecto y ya estaba a punto de volver a los 433 o 868 para llevarlo a cabo...Ahora solo falta leer, leer y leer para avanzarlo.
Me gusta este nuevo campo (nuevo para mi)..A ver que le saco.

Muchas gracias, nunca decepcionáis.