Why am I not receiving data on my NRF24L01 with arduino? Hello! I am trying to create communication between a NRF24L01 c
Posted: Tue Jun 07, 2022 12:16 pm
Why am I not receiving data on my NRF24L01 with arduino?
Hello! I am trying to create communication between a NRF24L01
connected to an arduino nano and another connected to an arduino
uno, I used an example to start the communication, and the arduino
nano sends information but the arduino UNO only receives zeros.
This is the code for the receiver connected to the arduino UNO,
any idea why it doesn't work?
This is part if the code for
emisor
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define con 3.9
float acX = 0, u=0, acY = 0;
float v = 0, a=0, acZ = 0;
float pitch =0, roll=0, yaw=0;
byte direccion[5] ={'c','a','n','a','l'};
RF24 radio(CSN_PIN, CE_PIN);
float datos[8];
int ax, ay, az;
int gx, gy, gz;
double pnm=1008;
void setup() {
radio.begin();
radio.openWritingPipe(direccion);
Serial.begin(9600);
Wire.begin();
}
void loop() {
char status;
double T,P,A;
int s=0;
float m=0;
float ok=
radio.write(datos, sizeof(unsigned long));
if(ok)
{
sensor.getAcceleration(&ax, &ay,
&az);
sensor.getRotation(&gx, &gy, &gz);
a=(ax)^2+(ay)^2+(az)^2;
v=sqrt(abs(a))*0.001;
u=v;
acX=ax*con;
acY=ay*con;
acZ=az*con;
pitch = 180 * atan (acX/sqrt(acY*acY +
acZ*acZ))/M_PI;
roll = 180*atan(acY/acZ)/M_PI;
yaw=1;
sensor.getTemperature(T);
sensor.getPressure(P,T);
datos[0]=yaw;
datos[1]=T;
datos[2]=
sensor.altitude(P,pnm);
Serial.print(datos[0]);
Serial.print(",");
Serial.print(datos[1]);
Serial.print(",");
Serial.print(datos[2]);
Serial.print(",");
}
}
}
}
datos[3]=gx;
datos[4]=gy;
datos[5]=gz;
datos[6]=pitch;
datos[7]=roll;
datos[8]=v*1.94384;
Serial.print(datos[3]); Serial.print(",");
Serial.print(datos[4]); Serial.print(",");
Serial.print(datos[5]); Serial.print(",");
Serial.print(datos[6]); Serial.print(",");
Serial.print(datos[7]); Serial.print(",");
Serial.println(datos[8]);
delay(500);
}
else
{
}
}
This is the code for
receptor
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
byte direccion[5] ={'c','a','n','a','l'};
RF24 radio(CSN_PIN, CE_PIN);
float datos[8];
void setup()
{
radio.begin();
Serial.begin(9600);
radio.openReadingPipe(1, direccion);
radio.startListening();
}
void loop() {
uint8_t numero_canal;
if ( radio.available(&numero_canal) )
{
radio.read(datos,sizeof(unsigned
long));
//reportamos por el puerto serial los datos
recibidos
Serial.print(datos[0]); Serial.print(",");
Serial.print(datos[1]); Serial.print(",");
Serial.print(datos[2]); Serial.print(",");
Serial.print(datos[3]); Serial.print(",");
Serial.print(datos[4]); Serial.print(",");
Serial.print(datos[5]); Serial.print(",");
Serial.print(datos[6]); Serial.print(",");
Serial.print(datos[7]); Serial.print(",");
Serial.println(datos[8]);
}
else
{
}
delay(1000);
}
Hello! I am trying to create communication between a NRF24L01
connected to an arduino nano and another connected to an arduino
uno, I used an example to start the communication, and the arduino
nano sends information but the arduino UNO only receives zeros.
This is the code for the receiver connected to the arduino UNO,
any idea why it doesn't work?
This is part if the code for
emisor
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define con 3.9
float acX = 0, u=0, acY = 0;
float v = 0, a=0, acZ = 0;
float pitch =0, roll=0, yaw=0;
byte direccion[5] ={'c','a','n','a','l'};
RF24 radio(CSN_PIN, CE_PIN);
float datos[8];
int ax, ay, az;
int gx, gy, gz;
double pnm=1008;
void setup() {
radio.begin();
radio.openWritingPipe(direccion);
Serial.begin(9600);
Wire.begin();
}
void loop() {
char status;
double T,P,A;
int s=0;
float m=0;
float ok=
radio.write(datos, sizeof(unsigned long));
if(ok)
{
sensor.getAcceleration(&ax, &ay,
&az);
sensor.getRotation(&gx, &gy, &gz);
a=(ax)^2+(ay)^2+(az)^2;
v=sqrt(abs(a))*0.001;
u=v;
acX=ax*con;
acY=ay*con;
acZ=az*con;
pitch = 180 * atan (acX/sqrt(acY*acY +
acZ*acZ))/M_PI;
roll = 180*atan(acY/acZ)/M_PI;
yaw=1;
sensor.getTemperature(T);
sensor.getPressure(P,T);
datos[0]=yaw;
datos[1]=T;
datos[2]=
sensor.altitude(P,pnm);
Serial.print(datos[0]);
Serial.print(",");
Serial.print(datos[1]);
Serial.print(",");
Serial.print(datos[2]);
Serial.print(",");
}
}
}
}
datos[3]=gx;
datos[4]=gy;
datos[5]=gz;
datos[6]=pitch;
datos[7]=roll;
datos[8]=v*1.94384;
Serial.print(datos[3]); Serial.print(",");
Serial.print(datos[4]); Serial.print(",");
Serial.print(datos[5]); Serial.print(",");
Serial.print(datos[6]); Serial.print(",");
Serial.print(datos[7]); Serial.print(",");
Serial.println(datos[8]);
delay(500);
}
else
{
}
}
This is the code for
receptor
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
byte direccion[5] ={'c','a','n','a','l'};
RF24 radio(CSN_PIN, CE_PIN);
float datos[8];
void setup()
{
radio.begin();
Serial.begin(9600);
radio.openReadingPipe(1, direccion);
radio.startListening();
}
void loop() {
uint8_t numero_canal;
if ( radio.available(&numero_canal) )
{
radio.read(datos,sizeof(unsigned
long));
//reportamos por el puerto serial los datos
recibidos
Serial.print(datos[0]); Serial.print(",");
Serial.print(datos[1]); Serial.print(",");
Serial.print(datos[2]); Serial.print(",");
Serial.print(datos[3]); Serial.print(",");
Serial.print(datos[4]); Serial.print(",");
Serial.print(datos[5]); Serial.print(",");
Serial.print(datos[6]); Serial.print(",");
Serial.print(datos[7]); Serial.print(",");
Serial.println(datos[8]);
}
else
{
}
delay(1000);
}