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”
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.
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.
This is my code that i typed it before and hoped it works
But it doesn’t
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
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.