UHF RFID, nRF24L01+ communication

Hi, i’m working on a project involving the UHF RFID, arduino nano and a nRF24L01+ transceiver.

This project works by scanning an RFID tag, and getting the the tag number and sending it via the transceiver to the receiving station, which contains an nRF24L01+ and the Arduino nano only.

My problem is this, as i scan the tag number for the first time it gets the tag number as it should and i receive the tag number that it should be. If i scan the next tag that i have(which has a different tag number than the first), I still receive the tag number for the first tag that i have scanned, if i scan the second tag again, then it would only show its right tag number.

How do i fix this?? I’ll post the code below.

Code for the Transmitting station(the one with the UHF RFID):

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


//TEST
//#include <Time.h>
#include <Wiegand.h>

WIEGAND wg;
int msgSize;
long character;
int msg[1];  //Holding your sent message

#define CE_PIN 9
#define CSN_PIN 10
RF24 radio(CE_PIN, CSN_PIN);
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;

String theMessage = ""; //Received Message
String inputString = ""; //Hold incoming Message from Serial

void setup(void) {
Serial.begin(9600);
wg.begin();
while (!Serial) {} //Needed for Leonardo
radio.begin(); //Start the radio
radio.setRetries(15, 15); // optionally, increase the delay between retries & # of retries
radio.setPayloadSize(8);// optionally, reduce the payload size.
radio.openWritingPipe(pipe);
radio.openReadingPipe(1, pipe);
radio.startListening();
}

void loop(void) {
  
  if(wg.available()){
  Serial.print("RFID Code:");
  Serial.println(wg.getCode());
  delay(3);
  character = wg.getCode();
  
  identifytag();
  
  sentText();
  

    
  }
  
  
if (radio.available()) { //Wait for incoming message from radio
receiveText(); //Call funtion to receive message
}
}

void identifytag(){
  if(character == 16777205){
    Serial.println("OK");
    delay(3);
  }
   else{
      Serial.println("Fail!!!");
      delay(3);
   }
  
}


void receiveText() {
radio.read(msg, 1); //Read radio 1 char at a time
char theChar = msg[0]; //Stor it in theChar
if (msg[0] != 2) { //If you get \n char then
theMessage.concat(theChar); //link all together
}
else { //If done then
Serial.println(theMessage); //Print to serial
theMessage = ""; //Clear Message
}
}
//This is same as EXAMPLE CODE it just works this better. NO ERRORS
void serialEvent() { //if something happens in serial do this
while (Serial.available()) { //Do till you get all from serial
char inChar = (char)Serial.read(); // get the new byte:
delay(3); //*****I add this else you get broken messages******
inputString += inChar;// add it to the inputString:
}
sentText(); //Call function to sent message to other radio
}

void sentText() {
radio.stopListening(); // First, stop listening so we can talk.
int messageSize = inputString.length(); //Calculate String length
for (int i = 0; i < messageSize; i++) { //Sending 1 char at a time to other radio
int charToSend[1]; //Hold the char to be send
//charToSend[0] = sec;
charToSend[0] = inputString.charAt(i); //First char stored
bool ok = radio.write(charToSend, 1); //Sent char
/*if (ok) //This is not needed but will make you feel better
Serial.println("");
else
Serial.println("ERROR...");
}*/}
msg[0] = 2; //send the 'terminate string' value...
radio.write(msg, 1);
//IMPORTANT CODE//
inputString = wg.getCode();
radio.startListening(); // Now, continue listening
}

Code for the Receiving station:

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

String Time;
String sec;
String minu;
String hawr;
String theMessage;
int msg[1];

#define CE_PIN 9
#define CSN_PIN 10
RF24 radio(CE_PIN, CSN_PIN);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void){
  Serial.begin(9600);
  while (!Serial) {} //Needed for Leonardo
radio.begin(); //Start the radio
radio.setRetries(15, 15); // optionally, increase the delay between retries & # of retries
radio.setPayloadSize(8);// optionally, reduce the payload size.
radio.openWritingPipe(pipe);
radio.openReadingPipe(1, pipe);
radio.startListening();
  
}

void loop(void){
  ClockDisplay();   // start of the Race Timing
 // theMessage="";
  if(radio.available()){
      receiveText();
      
    
  }
}

void receiveText(){
  radio.read(msg,1);
  char theChar = msg[0];
  if(msg[0] != 2){
    theMessage.concat(theChar);

  }
  else{
    Serial.println(theMessage + "," + Time);
  
 delay(1000);
  theMessage = "";
  }
}

void serialEvent(){
  while (Serial.available()){
    char inChar = (char)Serial.read();
    delay(3);
    
  }
}

void ClockDisplay(){
  sec = second();
  minu = minute();
  hawr = hour();
  Time = hawr + ":" + minu + ":" + sec;
}
char theChar = msg[0]; //Stor it in theChar

Why?

  Serial.println(wg.getCode());
  delay(3);
  character = wg.getCode();

What does wg.getCode() do? Why do you need to call it twice? Call it once, and store the value.

Calling a long variable character looks pretty stupid to me. It's like having this:

  float integer;
//IMPORTANT CODE//
inputString = wg.getCode();

Why do you set inputString to the RFID tag value AFTER sending inputString?

as active tag you used ?

Pls am working on an audio transmission project, I need help with the RFID and nrf24 because have not still been able to get dem work as expected, I want the RFID to scan a card and if the card is valid the nrf24lo1 starts transmitting the audio, but the RFID doesn't work at all. Am using the AddicoreRFID library and TMRH's RfAudio library