Go Down

Topic: Arduino mega, pn5180-nfc and NRF24L01 (rf24network)- rf24 wont work (Read 148 times) previous topic - next topic

henderman

Hi Everyone. First post. I am new to Arduino ( 3 months), basic coding knowledge, love learning this stuff though.

I have been creating a nfc puzzle using an Arduino mega, a nrf24l01 and  4 pn5180 nfc readers. its a combination of public tutorials and code. I have done a lot of troubleshooting and I suspect the problem is due to some kind of signal interference from the circuit I have. or could it be a power problem, not sure.

The problem:

There are 4 pn5180 nfc readers each attached to my Arduino mega through 3.3v --> 5v logic converters.
So there are 9 pins to use on each reader. RST, NSS, Busy, miso, mosi, sck, 3v, 5v and ground.

3v and 5v go to their respective sides of the logic level converters and also both go to the nfc readers as well. ground is set up from nfc reader to logic converter to Arduino. RST, BUSY and NSS have their own unique path to Arduino through the logic level converters and the 3 spi wires are merged through the logic lever converters -> mosi with mosi, sck with sck etc. These spi pins are then connected to pins 50-52. The nfc readers work as planned all the time.

The rf24 module is connected to the iscp pins for miso, mosi and sck and pins 8,9 for csn and cn. The rf24 does not work (as transceiver or receiver). pin 53 is output.

So here is what I know.

When the 3 spi pins from the pn5180 readers are disconnected, as in unplugged from the mega --> the rf24 can send and receive. At no point when they are plugged in at the same time have I managed to get them working together.

- I have tried merging the spi connections from rf24 and pn5180 on the normal mega pins and also then on the iscp pins.
- I have tried turning off the nss pins of the 4 pn5180 readers by setting them output and high before trying to use the rf24.
- I have tried using nfc.end(), (if I fully understand its use)
- checked all other connections to be correct.
- tried with one reader instead of 4 etc
- using idc to transfer the data from nfc to logic level converters.
- logic level converters soldered onto protoboard and high one side low the other
- have tried csn for rf24 on pin 53


Code: [Select]


#include <PN5180.h>
#include <PN5180ISO15693.h>
#include <SPI.h>
#include <RF24Network.h>
#include <RF24.h>
#include <nRF24L01.h>

RF24 radio(9, 8);               // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 04;   // (04 is for rfid puzzle )
const uint16_t master00 = 00;    // (master)-- Address of the other node in Octal format

void   puzzlecheck();
void   radiocheck();
void   solvedtransmit();
void   puzzleprocess();
bool firsttimesolved = false;

// The number of PN5180 readers connected
const byte numReaders = 4;

// What is the "correct" UID that should be detected by each reader
uint8_t correctUid[][8] = {

  {0xB, 0xD7, 0x24, 0x80, 0x0, 0x1, 0x4, 0xE0},
  {0x7F, 0xBD, 0x24, 0x80, 0x0, 0x1, 0x4, 0xE0},
  {0x66, 0x9, 0xC7, 0x6A, 0x0, 0x1, 0x4, 0xE0},
  {0x74, 0xDF, 0x24, 0x80, 0x0, 0x1, 0x4, 0xE0}

};

// Each PN5180 reader requires unique NSS, BUSY, and RESET pins,
PN5180ISO15693 nfc[] = {
  PN5180ISO15693(26, 28, 24), // rst line 3 on protoboard
  PN5180ISO15693(32, 34, 30), // rst line 14 on protoboard
  PN5180ISO15693(40, 42, 38), // rst line 24 on protoboard
  PN5180ISO15693(47, 44, 45), // rst line 29 on protoboard
};

// Array to record the value of the last UID read by each reader
uint8_t lastUid[numReaders][8];

void setup() {
  Serial.begin(115200);
  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_MAX); // can be min, low, high, max
  radio.setDataRate(RF24_1MBPS); // can be 256KBS, 1MBPS, 2MBPS
  network.begin(110, this_node);  //(channel, node address)
  Serial.println("setup in progress");
  pinMode(53, OUTPUT);

  for (int i = 0; i < numReaders; i++) {
    nfc[i].begin();
    nfc[i].reset();
    nfc[i].setupRF();
  }
}

/*******************************************/
void loop() {

  if (firsttimesolved == true) {
    radiocheck();
  }

  if (firsttimesolved == false) {
    puzzleprocess();
  }

}


/********************************************/
void puzzleprocess() {

  for (int i = 0; i < numReaders; i++) {                    /
    uint8_t thisUid[8];
    ISO15693ErrorCode rc = nfc[i].getInventory(thisUid);   
    if (rc == ISO15693_EC_OK) {                             
      if (memcmp(thisUid, lastUid[i], 8) == 0) {           
        continue;
      }
      else {
        Serial.println(F("New Card Detected on Reader "));
        for (int j = 0; j < sizeof(thisUid); j++) {
          Serial.print(thisUid[j], HEX);
          Serial.print(" ");
        }
        Serial.println();
        memcpy(lastUid[i], thisUid, sizeof(lastUid[i][0]) * 8);
        puzzlecheck();
      }
    }
    // If a card cannot be read
    else {                                                 
      if (lastUid[i][7] == 0xE0) {                     
        Serial.print("Card ");
        for (int j = 0; j < sizeof(lastUid[i]); j++) {
          Serial.print(lastUid[i][j], HEX);
        }
        Serial.print(" removed from Reader ");
        Serial.println(i);
        memset(lastUid[i], 0, sizeof(lastUid[i][0]) * 8);   
      }
    }
    delay(100);
  }

}

void puzzlecheck() {
  // Test each reader in turn
  for (int i = 0; i < numReaders; i++) {
    if (memcmp(lastUid[i], correctUid[i], 8) != 0) {        // If this reader hasn't detected the correct tag
      return false;
    }
  }
  Serial.println("puzzle solved");
  firsttimesolved = true;
  solvedtransmit();
}

/*****************************************************/

void radiocheck() {
  network.update();
  //===== recieving =====//

  while ( network.available() ) {    // Is there any incoming data?
    RF24NetworkHeader header;
    unsigned long incomingData;
    network.read(header, &incomingData, sizeof(incomingData)); // Read the incoming data
    Serial.print("reading inoming data");
    if (incomingData == 1) {  //reset firsttimesolved variable to false.
      firsttimesolved = false;
      Serial.println(incomingData);
    }
  }
}

/*******************************************************/

void solvedtransmit() { // function to send the puzzle solved code to master when puzzle complete
  bool sending;
  unsigned long puzzlesolved = 5;
  RF24NetworkHeader header(00);   // (Address where the data is going)
  sending = network.write(header, &puzzlesolved, sizeof(puzzlesolved)); // Send the data
  if (sending) {
    Serial.print("success");
  }
}
/*******************************************************/

Go Up