2 transmitters with different channel numbers to one RX and to Excel columns

Hello Dear forum gurus
Have a little challenge for myself and I am pretty stuck- just need your help.
I have 2 Transmitters (each one of them is Arduino+NRF24 with button-counter_2 and TX_button_6. Only after TX_butto_6n is pressed the data will be transmitted out) and one Receiver ( arduino+ NRF24).
The data from Transmitters should be uploaded at the Receiver side to Excel columns.
Lets call First TX_P that counts the number of button presses of A.
Lets call Second TX_C that counts the number of button presses of B.

Now the RX should:
Get the number of A and put it in column A
Get the number of B and put it in column B

And here comes the tricky part-
the First_TX_P needs to transmit at channel 60 for A column
the Second TX_C needs to transmit at channel 58 for B column
the RX should get the Channel 60 with A value and place it in column A, Channel 58 with B value and place it in column B

My problem is to write code of RX. I am really new to programming. I belie the TXs codes are is correct, but how do I do it in RX to separate column vs channel

What I have enabled so far is:

  1. Upload the data from ONE TX to ONE RX and the ONE column of Excel according to example here:
    http://www.instructables.com/id/Sending-data-from-Arduino-to-Excel-and-plotting-it/

  2. Enable 2 TX and one RX according to this:
    https://www.elec-cafe.com/multiple-nodes-nrf24l01-wireless-temperature-ds18b20-with-arduino-uno-2-transmitter-1-receiver/

The Code as I see it should be :
First TX_P

#include <Wire.h>
#include "rgb_lcd.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 255;
const int colorB = 0;

int button1PushCounter = 0;
int button1State = 0;
int lastButton1State = 0;

int button_tx = 6; // If button TX will be pressed - the data will be transmitted out
int button1Pin = 2; // A

int digitValue ;  //  value from the digit input pin
int i=0;
RF24 radio(5,10);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL };
int msg1[1];
//--------------------------- Setup ---------------------------------

void setup() {

pinMode (button1Pin, INPUT);
pinMode (button_tx, INPUT);
  
  Serial.begin (9600);
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipes[1]);
 radio.setChannel(0x60);  //channel 60 for A column
 radio.setPayloadSize(32);     //size of packet
radio.powerUp();
radio.stopListening(); // we are TX
}

void loop(){
 button1State = digitalRead(button1Pin);
delay(100);

   if (button1State == HIGH) {
     // if button1 state is HIGH then the button1 went from off to on
      delay(100);
     button1PushCounter++;
      delay(200);
      
   Serial.print("M1 Number of button1 pushes: A ");
    Serial.println(button1PushCounter, DEC);
  }

   
 
    if (digitalRead(button_tx) == HIGH)
     {
      delay(100);
      send_msg("  A=  ");
      send_msg("  "+String(button1PushCounter));
      delay(100);
Serial.print(" M2 Total string: A ");
Serial.println(button1PushCounter, DEC);
      
      }
  

lastButton1State = button1State;   
}



void send_msg(String msg)
{
  String theMessage = msg;
  int messageSize = theMessage.length();
  for (int i = 0; i < messageSize; i++) {
    int charToSend[1];
    charToSend[0] = theMessage.charAt(i);
    radio.write(charToSend,1);
  }  
  msg1[0] = 2; 
  radio.write(msg1,1);
  radio.powerDown(); 
  delay(1000);
  radio.powerUp();
}

//---------------------------------
Second TX_C

#include <Wire.h>
#include "rgb_lcd.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 255;
const int colorB = 0;

int button1PushCounter = 0;
int button1State = 0;
int lastButton1State = 0;

int button_tx = 6; // If button TX will be pressed - the data will be transmitted out
int button1Pin = 2; // B button

int digitValue ;  //  value from the digit input pin
int i=0;
RF24 radio(5,10);
const uint64_t pipes[3] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL };
int msg1[1];
//--------------------------- Setup ---------------------------------

void setup() {

pinMode (button1Pin, INPUT);
pinMode (button_tx, INPUT);
  
  Serial.begin (9600);
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  radio.begin();
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipes[1]);
 radio.setChannel(0x58);  //channel 58 for B column 
 radio.setPayloadSize(32);     //size of packet
radio.powerUp();
radio.stopListening(); // we are TX
}

void loop(){
 button1State = digitalRead(button1Pin);
delay(100);

   if (button1State == HIGH) {
     // if button1 state is HIGH then the button1 went from off to on
      delay(100);
     button1PushCounter++;
      delay(200);
      
   Serial.print("M1 Number of button1 pushes: B ");
    Serial.println(button1PushCounter, DEC);
  }

   
 
    if (digitalRead(button_tx) == HIGH)
     {
      delay(100);
      send_msg("  B=  ");
      send_msg("  "+String(button1PushCounter));
      delay(100);
Serial.print(" M2 Total string: B ");
Serial.println(button1PushCounter, DEC);
      
      }
  

lastButton1State = button1State;   
}



void send_msg(String msg)
{
  String theMessage = msg;
  int messageSize = theMessage.length();
  for (int i = 0; i < messageSize; i++) {
    int charToSend[1];
    charToSend[0] = theMessage.charAt(i);
    radio.write(charToSend,1);
  }  
  msg1[0] = 2; 
  radio.write(msg1,1);
  radio.powerDown(); 
  delay(1000);
  radio.powerUp();
}

RX code: how to set 2 channels 60 and 58 to different columns?

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

/*
This sketch receives strings from sending unit via nrf24 
and prints them out via serial.  The sketch waits until
it receives a specific value , then it 
prints the complete message and clears the message buffer.
*/

int msg[1];
RF24 radio(5,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; // choosing pipe
int lastmsg = 1;
String theMessage = "";
void setup(void){
  Serial.begin(9600);
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,Acolumn"); //always write LABEL, so excel knows the next things will be the names of the columns (instead of Acolumn you could write Time for instance)

  
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.setPALevel (RF24_PA_MAX); //Power Amplifier setup we can choose among  RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX 
  radio.setDataRate (RF24_250KBPS); //bit rate, we can choose among RF24_2MBPS, RF24_1MBPS, RF24_250KBPS

//trying the chanel and the payload size:
 radio.setChannel(0x60);  //channel 60
 radio.setPayloadSize(32);     //packet size 

  radio.setAutoAck(1);         //Ack mode on "1" on and the "0 " is off
  radio.setRetries(0,15);     //(time between retries, amount of retries)
  radio.enableAckPayload();    // enable the TX send after the RX recieves


  radio.powerUp(); //begin the work
  radio.startListening(); // we are RX
}
void loop(void){
  if (radio.available()){
    bool done = false;  
      done = radio.read(msg, 1); 
      char theChar = msg[0];
      if (msg[0] != 2){
        theMessage.concat(theChar);
        }
      else {
       Serial.println(theMessage);
       Serial.print("DATA,theMessage");
       theMessage= ""; 
      }
   }
}

Thank you
Regards

Thus if I summarize it:
First TX_P
<>
radio.openWritingPipe(pipes[1]); // first pipe
radio.setChannel(0x60); //channel 60 for A column
</>

Second TX_C
<>
radio.openWritingPipe(pipes[1]); // first pipe
radio.setChannel(0x58); //channel 58 for B column
</>

How do I separate the columns A and B at RX? and how do I write it?
Thanks

simonbiton: And here comes the tricky part- the First_TX_P needs to transmit at channel 60 for A column the Second TX_C needs to transmit at channel 58 for B column

Why are you using two different channels? Life will be much simpler if all your nRF24s use the same channel.

Have a look at this Simple nRF24L01+ Tutorial. There is an example of a master communicating with 2 slaves. It could probably be used for your project. By putting the master in charge there can be no confusion about where the data comes from.

...R

I went over the link you provided thank you. At this link it is stating : " Messages will also be garbled if (say) a nearby Wifi system transmits at the same time on the exact same frequency. " And that is why I need different channels.

I have to use different channels because eventually I will have to do the following:

Living room: 2 transmitters send to one receiver A pushes and B pushes . Channels 60 and 58 Hallway: 2 transmitters send to one receiver C pushes and D pushes. Channels 56 and 54 Basement: 2 transmitters send to one receiver E pushes and F pushes. 52 and 50 Child bedroom_1: 2 transmitters send to one receiver G pushes and H pushes. 48 and 46 Child bedroom_2: 2 transmitters send to one receiver I pushes and J pushes. 44 and 42 And so on..

RX: will accept Living room, Hallway, Basement, Child bedroom_1, Child bedroom_2 and so on.. And will present in excell columns with A,B,C,D,E.... from channels 60, 58, 56, 54.. Thank you

IMHO using different channels is all wrong. If anything you just increase the possibility of some other device causing interference. Four people walking in the road in single file might not get hit by a car. Four people walking side by side evenly spaced across the road cannot avoid one of them being hit.

Don’t try to solve a problem you don’t have, and are not likely to have.

Choose a channel that works and use it for all your devices. And include in your code the ability to deal with occasional missed messages.

Working with different channels will be very complex. The listener must be listening on the correct channel before the sender transmits on that channel. Arranging that for so many different channels will just be a nightmare.

And (as a separate comment) this way of using an nRF24 is very wasteful

  for (int i = 0; i < messageSize; i++) {
    int charToSend[1];
    charToSend[0] = theMessage.charAt(i);
    radio.write(charToSend,1);
  }

A single nRF24 message can contain up to 32 bytes so you should not be sending single bytes. Sending the message as one item also means there is no need to reassemble it at the receiving side.

As another separate comment it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0. And it seems especially silly to use Strings if you have to convert them to cstrings to transmit them.

…R

Hello Robin Lets say I accept your advise and drop the channels. Lets assume that there are 8 transmitters and one receiver. Your advice- place them all in one Pipe. The TX_1 sends data A=8 The TX_2 sends data B=6 The TX_3 sends data C=4 The TX_4 sends data D=2

This at the receiving end the data would look like ( in single column) A=8 B=6 C=4 D=2

If the A and D are pressed simultaneously the data will be corrupted AC=48 B=6 C=4

Isn't it?

simonbiton: If the A and D are pressed simultaneously the data will be corrupted

When I say "corrupted" I mean that nothing will be received because the error checking will fail. The nRF24 has a lot of error checking. If it receives a message you can be 99.999% certain it is what was transmitted.

As an nRF24 has only a single wireless that problem will not be eased by using more pipes or more channels. Pipes only enter the picture after a message is correctly received.

By putting the master in charge and polling each of the slaves in turn the risk of collisions is entirely eliminated.

...R