I want to build several boards that will communicate over the NRF24L01 radio and to have on them the same sketch. Say 10 of them. But, only two should work together, so this makes 5 pairs. To make the data doesn't mess with them, I can use a different channel, or a different address. On my setup, I have a 4 switches. My guess is, by setting the correct combination of switches, I can make 5 pairs to work correctly.
Now, the software part.
How to implement those logic states from switches to channels and/or address?
It should be something this way:
To check in setup the switch states, and to set a parameter. As long as the switches are in position, after booting up two boards should work together without interference.
This is my basic sender sketch:
//sender
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(PA4, PA3); // CE, CSN
int sw1 = PA1;
int sw2 = PA2;
int sw3 = PA13;
int sw4 = PA14;
const byte address[6] = "00001";
int ldr = PA0;
int ldrRead;
void setup(){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address[0]);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop(){
ldrRead = analogRead(ldr);
Serial.println(ldrRead);
radio.write(&ldrRead, sizeof(ldrRead));
delay(1000);
}
Should be radio.openWritingPipe(address);
or radio.openWritingPipe(&address[0]);
Your code will probably use different addresses in receiver and transmitter,
because the address will be the content of processor registers (from address 0 to 4).
The receiver has the same error.
On Linux the program will probably crash when you access memory at address zero.
is not very sensible.
I don't understand your strange pairing strategy,
I would let all nodes talk to any node, by just giving them a personal address.
I use addresses that only differ in the lowest byte, so I can use all pipes freely,
and use one EEPROM byte for the personal address.
If you insist in pairing them, you could put the destination byte to EEPROM also.
The goal is to have maybe even 50 pairs, but to have only ONE sketch on them. It could be 5 pairs in the same place, or only one pair. If I pair them through a sketch, then I will have to mark them somehow which one is paired to which one.
My idea is to have those switches, and just pair the board with switches, while the sketch remains the same. Maybe I will not be the one who will install them. This way anyone can install them. Just pull the same switches and the boards are paired.
Say, there are 4 switches in pull down. This means I have 0000. If I pull first switch, I will get 1000. So according to these logic states, I can use the specific address.
0000 = address 1
1000 = address 2
0100 = address 3
...
I tried something, but get nothing. LOL.