Hi Group,
Remember in your answers that I only start coding in general and play with Arduino
since this summer so I am new at this but with your help I will get better
Project
I have two NRF2401 acting as transmitter. They both have an ultrasonic sensor and a flow sensor. Each transmitter will monitor the water lever of a water tank and the input flow that fill that tank.
Each NRF2401 is sending is data to the same NRF2401 acting as a receiver, each of them using a different pip.
All this is working for now, the receiver is receiving each pip and print the values on an LCD 16X4.
The first transmitter has the sensors installed but the second transmitter is sending fixed values
until I'm ready with the general concept.
For now and for the test purpose, sending the data from two TX to One RX is ok.
Monitoring The Signal
I need to find a way to monitor if I'm receiving the signal from the first, the second or both transmitters.
So if I loose the signal from on eof them or both, my LCD screen will become blank or print Lost signal.
The way the code is done, I can see the following on the serial monitor of the receiver
Data on pip = 1 Got data size=12 data = folowing by my value
Data on pip = 2 Got data size=12 data = folowing by my value
Data on pip = 1 Got data size=12 data = folowing by my value
Data on pip = 2 Got data size=12 data = folowing by my value
Data on pip = 1 Got data size=12 data = folowing by my value
Data on pip = 2 Got data size=12 data = folowing by my value
and so on..
Maybe
If there is a way to recognize from which TX the signal is coming from tell me how so I can
create an (if) condition with it.
BUT
It it's impossible to monitor the different signal, maybe I can create a condition to see (pip =1) and or (pip=2).
I did that but since I'm receiving (pip =1) then ( pip =2) one after the other, it's making
my LCD flashing all the time and it's not nice.
I told myself that maybe I can create a boolean value to store true in the boolean pip1 when pip = 1 and then store true in pip2 when pip =2. I need to keep that value for 3 secondes so if within that 3 seconds, the pip = 1 and pip =2 are still sending, it will keep the true condition in both boolean pip1 and pip2. So i just have to create a condition to see if pip1 and or pip2 is or are true. it will prevent the conditon to change at each transmission and so keep my LCD to flash all the time.
I really don't know if I'm on the right direction to reach my goal by I wanted to tell you what I tried so you can help me better.
See my code
//the NRF2401 code section is from sew-dude Post on july 2016 on the Arduino forum
//Multiple Pip receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "printf.h"
#include "LCD.h"
#include "LiquidCrystal_I2C.h"
#define lenght 16.0
double percent=100;
unsigned char b;
unsigned int peace;
unsigned long previousMillis = 0;
const long interval = 3000;
boolean pip1 = false;
boolean pip2 = false;
//****************************************Initialize for Receiver
RF24 radio (8, 10);
#define PLOAD_WIDTHÂ 32Â // 32 unsigned chars TX payload
byte pip;
byte pload_width_now;
byte newdata;
unsigned char rx_buf[PLOAD_WIDTH]= {0};
struct dataStruct1{
float p1;
float t1;
float s1;
}transmitter1_data;
struct dataStruct2{
float p1;
float t1;
float s1;
}transmitter2_data;
unsigned char ADDRESS2[1]= {0xb2};Â
unsigned char ADDRESS3[1]= {0xb3};Â
unsigned char ADDRESS4[1]= {0xb4};Â
unsigned char ADDRESS5[1]= {0xb5};Â
unsigned char ADDRESS1[5]Â =
{
 0xb1,0x43,0x88,0x99,0x45
}; // Define a static TX address
unsigned char ADDRESS0[5]Â =
{
 0xb0,0x43,0x88,0x99,0x45
}; // Define a static TX address
//****************************************END Receiver
LiquidCrystal_I2C lcd_3(0x23,2,1,0,4,5,6,7);
void setup(){
//****************************************Setup Receiver
 radio.begin();
 printf_begin();
 Serial.begin(115200);
 radio.setDataRate(RF24_250KBPS);
 radio.enableDynamicPayloads();
 radio.openWritingPipe(ADDRESS0);
 radio.openReadingPipe(0,ADDRESS0);
 radio.openReadingPipe(1,ADDRESS1);
 radio.openReadingPipe(2,ADDRESS2);
 radio.openReadingPipe(3,ADDRESS3);
 radio.openReadingPipe(4,ADDRESS4);
 radio.openReadingPipe(5,ADDRESS5);
 radio.startListening();
 radio.printDetails();
//****************************************END Setup Receiver
 lcd_3.begin (16,4); // 16 x 4 LCD module
 lcd_3.setBacklightPin(3,POSITIVE);
 lcd_3.setBacklight(HIGH);
}
//**************************************** void Receiver
void Receiver_1(){
if ( radio.available(&pip) ){
   // Fetch the payload, and see if this was the last one.
   pload_width_now = radio.getDynamicPayloadSize();
   // If a corrupt dynamic payload is received, it will be flushed
   if(!pload_width_now){Â
   }
   else
   {
  Â
   radio.read( rx_buf, pload_width_now );
   newdata=1;
   Serial.print(F("Data on pip= "));
   Serial.print(pip);
   Serial.print(F(" Got data size="));
   Serial.print(pload_width_now);
   Serial.print(F(" data="));
   for(byte i=0; i<pload_width_now; i++)
   {
   Serial.print(" ");
   Serial.print(rx_buf[i]); // print rx_buf
   }
   Serial.print(" ");
   }
  }
Â
if(newdata==1){
 newdata=0;
if(pip==1&&pload_width_now==sizeof(transmitter1_data)){
Â
  memcpy(&transmitter1_data, rx_buf, sizeof(transmitter1_data));
    Â
  Serial.print(" Distance, Percent, Flow ");
  Serial.print(transmitter1_data.p1);
  Serial.print(" , ");
  Serial.print(transmitter1_data.t1);
  Serial.print(" , ");
  Serial.print(transmitter1_data.s1); Â
     Â
    lcd_3.setCursor(0,0);
    lcd_3.print(transmitter1_data.p1, 0);
    lcd_3.print(F("cm "));
    lcd_3.setCursor(6,0);
    lcd_3.print(percent, 0);
    lcd_3.print(F("% "));
    lcd_3.setCursor(11,0);
    lcd_3.print(transmitter1_data.s1, 0);
    lcd_3.print(F("l/m "));
  Â
 }
Â
if(pip==2&&pload_width_now==sizeof(transmitter2_data)){
Â
  memcpy(&transmitter2_data, rx_buf, sizeof(transmitter2_data));
    Â
  Serial.print(" Distance, Percent, Flow ");
  Serial.print(transmitter2_data.p1);
  Serial.print(" , ");
  Serial.print(transmitter2_data.t1);
  Serial.print(" , ");
  Serial.print(transmitter2_data.s1);
   lcd_3.setCursor(0,2);
   lcd_3.print(transmitter2_data.p1, 0);
   lcd_3.print(F("cm "));
   lcd_3.setCursor(6,2);
   lcd_3.print(transmitter2_data.t1, 0);
   lcd_3.print(F("% "));
   lcd_3.setCursor(11,2);
   lcd_3.print(transmitter2_data.s1, 0);
   lcd_3.print(F("l/m "));
   }
   Serial.println("");
 }
}
//********************************************That's the section I'm talking about
void LostRfSignal(){
unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval){ //interval = 3000 millis
  if (pip == 1){
   pip1 = true; // true for pip1 should stay in memory for 3000 millis
  }else{
   pip1 = false;
  }
  if (pip == 2){
   pip2 = true; // true for pip2 should stay in memory for 3000 millis
  }else {
   pip2 = false; Â
  }
  previousMillis = currentMillis;
  }
 Â
   //during the 3000 Millis, the next two (IF) should have the time to
   //see if pip1 and/or pip2 are true or false
 Â
   if(pip1 == true){ //do nothing
   Â
   }else{ // it will erase the line 0 and 1 on LCD
   Â
    lcd_3.setCursor(0, 0);Â
    lcd_3.print(F("        "));
    lcd_3.setCursor(0, 1);
    lcd_3.print(F("        "));
   }
 Â
   if(pip2 == true){ //do nothing
Â
   }else{ // it will erase the line 2 and 3 on LCD
    lcd_3.setCursor(0, 2);Â
    lcd_3.print(F("        "));
    lcd_3.setCursor(0, 3);
    lcd_3.print(F("        "));
   }
} //********************************************END of the section I'm talking about
void loop(){
Â
 Receiver_1();
 LostRfSignal();
 ProgressBar_1();
 delay(100);
}