Go Down

Topic: How to use multi transmitter with 1 receiver ? (Read 282 times) previous topic - next topic

jamali973

Dec 06, 2017, 12:47 pm Last Edit: Dec 07, 2017, 10:32 am by jamali973
I would like to give a signal to the receiver, but only if each push button on each transmitter are on HIGH.

This is my code for


TX1

Code: [Select]

#include  <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;
void setup(void){
 Serial.begin(9600);
 pinMode(SW1, INPUT);
 radio.begin();
 radio.openWritingPipe(pipe);}void loop(void){
 radio.setPALevel(RF24_PA_MIN);
if (digitalRead(SW1) == HIGH)
{
 msg[0] = 111;
 radio.write(msg, 1);}
 }


TX2

Code: [Select]

#include  <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg2[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E2LL;
int SW1 = 7;
void setup(void){
 Serial.begin(9600);
 pinMode(SW1, INPUT);
 radio.begin();
 radio.openWritingPipe(pipe);}void loop(void){
 radio.setPALevel(RF24_PA_MIN);
if (digitalRead(SW1) == HIGH)
{
 msg2[0] = 111;
 radio.write(msg2, 1);}
 }



RX


Code: [Select]

#include <SPI.h>

#include "nRF24L01.h"

#include "RF24.h"

int msg[1];

RF24 radio(9,10);

const uint64_t pipe[] = {0xE8E8F0F0E1LL, 0xE8E8F0F0E2LL};
/*const uint64_t pipe = 0xE8E8F0F0E1LL;*/
int LED1 = 3;

void setup(void){

Serial.begin(9600);

radio.begin();

radio.openReadingPipe(1,pipe[0]);
radio.openReadingPipe(2,pipe[1]);
/*radio.openReadingPipe(1, pipe);*/
radio.startListening();

pinMode(LED1, OUTPUT);}

void loop(void){

if (radio.available()){

bool done = false;

while (radio.available()){

radio.read(msg, 1);
Serial.println(msg[0]);

if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}

else {digitalWrite(LED1, LOW);}

delay(10);

msg[0] == 9;}}

else; {Serial.println("No radio available");

digitalWrite(LED1, LOW);}

}



I know I need to edit some things on the receiver code, but I dont know what to do. Can you please help me fix this, thanks in advance.

Robin2

#1
Dec 06, 2017, 06:53 pm Last Edit: Dec 06, 2017, 06:53 pm by Robin2
Have a look at this Simple nRF24L01+ Tutorial

It includes an example with one master and multiple slaves.

...R

PS ... To make it easier for people to help you please modify your post and use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum
Two or three hours spent thinking and reading documentation solves most programming problems.

jamali973

Ok I fixed the post, and thanks I will take a look!

Go Up