Go Down

Topic: NRF24L01 2.4ghz wireless on arduino (Read 10773 times) previous topic - next topic

rlogiacco

Solution one: packet payload identifier.

Each transmitter use a different id (an integer number from 1 to 5) and that is what you send to the central station: when the central station receives a packet it opens it and use the integer number to light up the correct LED.
All the transmitters use the same sender address, the receiver sets up one single pipe for that address.

Solution two: packet address identifier.

Each transmitter use a different sender address, the receiver sets up 5 pipes, each one associated to one of the transmitter address.
The transmitters send an empty packet (or a dummy one just to avoid spurious and unwanted false positives) to the receiver: the receiver determines which led to light up based on the sender address.

Solution one might be slightly simpler to implement as you will not have to deal with multiple pipes, but it is less reliable as you cannot rely on auto acknowledgements of transmission.
Both solutions are prone to collisions: the RF channel will be the same for all the nodes (transmitters and receivers).

In all cases you are NOT limited to 6 nodes: the pipes are an hardware buffer, not a limitation of any sort!
Please, do not send me personal messages containing forum related questions: I will not answer.

I share my discoveries and thoughts at http://rlogiacco.wordpress.com

fungus


In all cases you are NOT limited to 6 nodes: the pipes are an hardware buffer, not a limitation of any sort!


Yep. The receiver can changes addresses at any time. eg. You could switch between two sets of addresses every couple of seconds if you have 10 transmitters and don't need instant response times.

It all depends on how much data you need to send, how frequent it is, what response time you need, etc.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

josephchrzempiec

problem is I'm not sure how to code that i try to look for sketch for multiple transmitters to a single  receiver  and came up with nothing i can do a single transmitting and single receiver but that's all

tack

Try RF24Network library  by maniacbug.  It operates as a tree network so you can have lots of node a all communicating with any other node.

rlogiacco


problem is I'm not sure how to code that i try to look for sketch for multiple transmitters to a single  receiver  and came up with nothing i can do a single transmitting and single receiver but that's all


Are you able to send a number from your sender and your receiver?
Please, do not send me personal messages containing forum related questions: I will not answer.

I share my discoveries and thoughts at http://rlogiacco.wordpress.com

josephchrzempiec

hello. well i found some sample code online that lets me send a signal from a push button from one module with a uno on it  to another module on a different arduino uno  that haves a led on it and that led lights up when i push the button.

rlogiacco


hello. well i found some sample code online that lets me send a signal from a push button from one module with a uno on it  to another module on a different arduino uno  that haves a led on it and that led lights up when i push the button.


In your sample code you are probably sending the current time millis as payload. Is that right?

Every "message" can be decomposed into two parts: an envelope and a content. The envelope (also known as "header") is there for the messaging system to know what to do with the message; the content (also know as "payload") is the data you are going to send. This is valid for snail mail as much as for email and other internet protocols.

In nRF24 the envelope contains the sender address, the destination address and a verification code (used to check the transmission correctness). The content can be anything up to 32 bytes.

With your example you are using 8 of those 32 bytes to send an unsigned long. You can use the same data type and size, but instead of transmitting the millis() you send an identifier: each transmitter will use a different identifier and the receiver can determine which transmitter is communicating by reading that number.

If you still have troubles I suggest you post your sketch as a Gist and we can tap in the changes.
Please, do not send me personal messages containing forum related questions: I will not answer.

I share my discoveries and thoughts at http://rlogiacco.wordpress.com

josephchrzempiec

hello i did post the example sketch before i do it again

this is for the transmitting side

Code: [Select]

#include <SPI.h>

#include "nRF24L01.h"

#include "RF24.h"

int msg[1];

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10

//Contacts from the radio to connect NRF24L01 pinamnam -> Arduino

//SCK -> 13

//MISO -> 12

//MOSI -> 11

//CSN -> 10

//CE -> 9

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL; // fax transmission channel

//button connected to these pins

int buttonPin1 = 2;

int buttonPin2 = 3;

void setup(void){

radio.begin();

radio.openWritingPipe(pipe); // Open channel

}

void loop(void){

//until the button (buttonPin1) pressed send the package (111) Arduino ?2

if (digitalRead(buttonPin1) == HIGH){

msg[0] = 111;

radio.write(msg, 1);

}

if (digitalRead(buttonPin2) == HIGH){

msg[0] = 112;

radio.write(msg, 1);

}

}




this is for the receiving side



Code: [Select]

#include <SPI.h>

#include "nRF24L01.h"

#include "RF24.h"

int msg[1];

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10

//Contacts from the radio to connect NRF24L01 pinamnam -> Arduino

//SCK -> 13

//MISO -> 12

//MOSI -> 11

//CSN -> 10

//CE -> 9

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL; // channel address

//LEDs connected to these pins

int LEDpin1 = 2;

int LEDpin2 = 3;

void setup(void){
  Serial.begin(9600);   
 
radio.begin();

radio.openReadingPipe(1,pipe); // Open one of the 6-channel reception

radio.startListening(); //Begin to listen

pinMode(LEDpin1, OUTPUT);

pinMode(LEDpin2, OUTPUT);

}

void loop(void){

if (radio.available()){

bool done = false;

while (!done){

done = radio.read(msg, 1);

//if the packet came from Arduino ?1 (111), the LED (lights) LEDpin1, HIGH

if (msg[0] == 111){

delay(10);

digitalWrite(LEDpin1, HIGH);
Serial.println("Led 1 On");
}

else {

digitalWrite(LEDpin1, LOW);
Serial.println("Led 1 Off");
}

delay(10);

if (msg[0] == 112){

delay(10);

digitalWrite(LEDpin2, HIGH);
Serial.println("Led 2 On");
}

else {

digitalWrite(LEDpin2, LOW);
Serial.println("Led 2 Off");
}

delay(10);

}

}

}







rlogiacco

Here you go https://gist.github.com/rlogiacco/b50b2a4398029bd4eb3c: I did ask a Gist because it's easier to read and easier to highlight changes, I hope you still get the differences.

I didn't test it myself as my breadboards are all busy with other projects, so it still needs to be field tested.
Please, do not send me personal messages containing forum related questions: I will not answer.

I share my discoveries and thoughts at http://rlogiacco.wordpress.com

josephchrzempiec

hello i looked at the receiver sketch and it only shows one address with 5 leds on it but my question is how does the receiver know what transmitter the push button comes from if all transmitters have the same address?

josephchrzempiec

what I'm trying to do is have 5 modules that transmit each one with a push button on each one. and the receiver to have 5 leds one for each transmitter so if transmitter 2 button was pushed led 2 on receiver will light up. same with the other ones.

rlogiacco

Have you read my comments? In particular those in all UPPERCASE letters? More specifically to the one on line 29 of transmitter.ino?

Would you please do it before posting after the time I've spent to edit your sketches?

Thanks
Please, do not send me personal messages containing forum related questions: I will not answer.

I share my discoveries and thoughts at http://rlogiacco.wordpress.com

josephchrzempiec

I looked over  some of the comments i did i totally didn't understand how can receiver can use only one  address  from the transmit and i looked over your comments as well rlogiacco and I'm sorry i really didn't get what you was saying i really had to look at it more at i wrap my brain around all this rf transmitting and receiving stuff never did before but from what i understand now is that only need one address on each transmitter to go to the receiver and i guess again a number to each transmitter so that the receiver knows what led to light up from each receiver so if number 2 is a sign to receiver 2 then it lights up number 2 led from the transmitter  node number 2 when that button is pushed  if I'm wrong at reading this let me know. and so forth with transmitter 3, 4, 5 and 1 I'm looking over that sketch from that link you gave me in more detail thank you.

rlogiacco

Yes, you got it right: the number you transmit (the payload) is the way for the receiver to identify the transmitter.

There are alternative ways to achieve this same goal, but the one described into the example should be the simplest to implement and it can scale up easily.

Having all the transmitters use the same RF address means packet auto acknowledgement (another nice feature of the NRF24L01P chip) can get confused when transmitters send messages at the approximate same time: a transmitter will believe the packet has been received even in cases it wasn't.

For a simple test this is not a problem, but it might be an issue with a real system.

Please note that in the receiver code I didn't handle the case where multiple buttons are pressed: if you push the button on T1 then LED1 will light up, but keeping T1 pressed and pushing button on T2 will turn LED1 off and light up LED2. Visually this should end up in both LEDs blinking in turn.
Please, do not send me personal messages containing forum related questions: I will not answer.

I share my discoveries and thoughts at http://rlogiacco.wordpress.com

josephchrzempiec

thanks rlogiacco i have to try that sketch from that site with the  transmitter and receiver when i get home.

Go Up