Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I am facing some problems with an arduino nrf24l01 code, kindly give suggestions please

Status
Not open for further replies.

Vraj

Advanced Member level 4
Joined
Jul 15, 2016
Messages
119
Helped
2
Reputation
4
Reaction score
2
Trophy points
18
Activity points
1,038
i am facing some problems with coding .kindly suggest me.

hello,
i am facing some coding problem with this arduino nrf24l01 code.
here is the receiver code
Code:
#include<SPI.h>
#include"RF24.h"
RF24 radio(7, 8);
byte addresses[][6] = {"0"};
struct package
{ float  vraj = 1;
};
typedef struct package;
package data;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setDataRate(RF24_1MBPS);
  radio.setChannel(115);
  radio.openReadingPipe(1, addresses[0]);
  radio.startListening();
  delay(100);
}

void loop() {
  Serial.println("i m top");
  delay(1000);
  radio.startListening();
  if (radio.available())
  { while (radio.available())
    {
      radio.write(&data, sizeof(data));
      Serial.println("i m here");   
     
    }
    radio.stopListening();
   analogWrite(3, data.vraj);
    Serial.println(data.vraj);

  }
  else
  { Serial.println("no");
  } delay(1000);
}



and here is transmitter code
Code:
#include<SPI.h>
#include"RF24.h"
RF24 radio(7,8);
byte addresses[][6]={"0"};
struct package
{ float vraj=1;
};
typedef struct package;
package data;
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_1MBPS);
radio.setChannel(115);
radio.openWritingPipe(addresses[0]);
delay(100);
radio.startListening();
}

void loop() {
  // put your main code here, to run repeatedly:
radio.write(&data,sizeof(data));
Serial.println(data.vraj);
data.vraj=map(analogRead(3),0,1023,0,255);
delay(1000);

}



i think there is problem with receiver side
because i can see the values of analog read on serial monitor.
 

Re: i am facing some problems with coding .kindly suggest me.

Why you have radio.stopListening(); in receiver? So you one receive data and no more.
 
  • Like
Reactions: Vraj

    Vraj

    Points: 2
    Helpful Answer Positive Rating
Re: i am facing some problems with coding .kindly suggest me.

without it, it is also not receiving data.
 

Re: i am facing some problems with coding .kindly suggest me.

Maybe try: **broken link removed**

Your adress pipes is other.
 
  • Like
Reactions: Vraj

    Vraj

    Points: 2
    Helpful Answer Positive Rating
Re: i am facing some problems with coding .kindly suggest me.

this code is working perfectly but my edited is not working
 

Re: i am facing some problems with coding .kindly suggest me.

1) Do you have good connect? Check it.
2) In transmitter you have Delay(100), try Delay(1000). Maybe NRF need delay(1000) on start (it's stupid but... you can try).
3) Try set transmit and receive on 250KBPS, maybe Arduino have problem with 1MBPS.
4) In transmitter you have PA_MIN. In receiver you have PA_MAX. Select one in both code.
!!!!!! 5) !!!!!! In receive you have radio.write(&data, sizeof(data)); under while. Why write? You receive, no transmit. Replace on radio.Read(&data, sizeof(data));
6) In receive delete radio.stopListening();
 
  • Like
Reactions: Vraj

    Vraj

    Points: 2
    Helpful Answer Positive Rating
Re: i am facing some problems with coding .kindly suggest me.

hmm,
the problem was the radio.startListening(); at transmitter side and that 6 that you mentioned. thanks matti,i am proud of you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top