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