nRF24l01 I can't deal with it anymore :((((

Hi , I wanna make communication with 10 of nrf24l01 modules so i wanna one module as a “BASE” and others just transmitters “Nodes”
to overcome the conflict of packet data i think about broadcasting
as “Base” send radio to all “Nodes” , and Only one node transmit it’s data back
ex. base transmit “1” to all >> so only node #1 transmit it’s data while others silent

I tried modified those codes , but arduino refused to put those lines in “Void loop”

radio.startListening();
radio.stopListening();

https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

*Note : Only this lines make serial monitor print >>> no radio available

any solutions ?!

base.ino (2.18 KB)

node1.ino (1.74 KB)

I do not know which RF24 library you are using.
However I ran into a similar issue.
What happened was in the older RF24 library radio.read() used to return a boolean value. But later modified RF24 libraries changed it so it didn't return anything.

So code like
done = radio.read( joystick, sizeof(joystick) ); no longer works because the needed bool value is not returned anymore.
That may not be the issue for you, but it is something to look into.

Thanks for your reply
i’m using this library >> maniacbug RF24

unfortunately I tried what you said but my problem is in these lines “Only”

 void loop{
radio.stopListening();
radio.startListening();}

in void loop

if these lines typed in void setup , It’s no problem and my code runs normally
once i type it in void loop >>> the madness begin :slight_smile:

you can try it yourself … comment these lines and code runs normally (Y)

Why do you want to continuously turn off and on the radios?

The code you posted does not match what you are claiming you are wanting to do.
The base code never broadcasts anything. You claim you want base to broadcast "1" to all nodes. This means you need to put something in the payload packet from the base that the nodes will parse so the node can determine if it is the node that should respond.

The node1 code never listens for anything from base to know when to send any data. Node1 has no code to do any type of data parsing even if it was listening.

Neither code has just

 void loop{
radio.stopListening();
radio.startListening();}

and as pointed out that code would just toggle listening mode on and off.

This is my code that i typed it before and hoped it works

But it doesn’t :confused:

so I traced it line by line and discovered that switching ON / OFF radio isn’t normal

Base code

/* YourDuinoStarter Example: nRF24L01 Receive Joystick values

 - WHAT IT DOES: Receives data from another transceiver with
   2 Analog values from a Joystick or 2 Potentiometers
   Displays received values on Serial Monitor
 - SEE the comments after "//" on each line below
 - CONNECTIONS: nRF24L01 Modules See:
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED
   
 - V1.00 11/26/13
   Based on examples at http://www.bajdi.com/
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
//const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int Tx[2];  // 2 element array holding Joystick readings
int Rx[2];

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);
  //radio.startListening();
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  
  Tx[0] = 1; // Braodcasting 1 for all nodes
  Tx[1] = 1; // meaningless 
  radio.write( Tx, sizeof(Tx) );
  
  radio.startListening();
  
  delay(10); // sending and recieving time 
 
  if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( Rx, sizeof(Rx) );
      Serial.print("Sensor num = ");
      Serial.print(Rx[0]);
      Serial.print(" Reading = ");      
      Serial.println(Rx[1]);
    }
  }
  else
  {    
      Serial.println("No radio available");
  }
  
  radio.stopListening();
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//NONE
//*********( THE END )***********

Node1 code

/* YourDuinoStarter Example: nRF24L01 Transmit Joystick values
 - WHAT IT DOES: Reads Analog values on A0, A1 and transmits
   them over a nRF24L01 Radio Link to another transceiver.
 - SEE the comments after "//" on each line below
 - CONNECTIONS: nRF24L01 Modules See:
 http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
   1 - GND
   2 - VCC 3.3V !!! NOT 5V
   3 - CE to Arduino pin 9
   4 - CSN to Arduino pin 10
   5 - SCK to Arduino pin 13
   6 - MOSI to Arduino pin 11
   7 - MISO to Arduino pin 12
   8 - UNUSED
   - 
   Analog Joystick or two 10K potentiometers:
   GND to Arduino GND
   VCC to Arduino +5V
   X Pot to Arduino A0
   Y Pot to Arduino A1
   
 - V1.00 11/26/13
   Based on examples at http://www.bajdi.com/
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
//const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int Rx[2];  // 2 element array holding Joystick readings
int Tx[2];

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  //radio.startListening();
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  
  radio.startListening();
  
  if ( radio.available() )
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // Fetch the data payload
      done = radio.read( Rx, sizeof(Rx) );
      
      Serial.print(Rx[0]);
      if(Rx[0] == 1)
      {
        Serial.println("Welcome");
        radio.stopListening();
        Tx[0] = 1;
        Tx[1] = analogRead(A0);
        radio.write( Tx, sizeof(Tx) );
      }
    }
  }
  else
  {    
      Serial.println("No radio available");
  }
  
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//NONE
//*********( THE END )***********

this is the whole idea i wanna do
what’s wrong in this code???!!!

another question >>> Is there any “reliable” codes makes the same idea of broadcasting ?? multi-nodes

Thanks in advance :slight_smile:

what's wrong in this code???!!!

The code you posted does something.
You expect the code that you posted to do something.

What the code actually does and what you expect it to do are mysteries. Clear them up and then there is a possibility that we can help. Until then, not a chance.

What the code actually does

printing in serial monitor >> No radio available

what you expect it to do

I expect "Base" to print AnalogRead(A0) that sent by node number #1

In other words :

i want code make this sequence >>

"Base" send "1" to all nodes

"Node 1" receive "1" so it will send back it's analogRead(A0) Value

"Base" receive this value and print it on serial monitor

then ...

"Base" send "2" to all nodes

"Node 2" receive "2" so it will send back it's analogRead(A0) Value

"Base" receive this value and print it on serial monitor

then ...

"Base" send "3" to all nodes

"Node 3" receive "3" so it will send back it's analogRead(A0) Value

"Base" receive this value and print it on serial monitor

etc ...

Just want a code make this function >> can you help PaulS