Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Issue while interfacing NRF24L01 and RFID on same arduino

Issue while interfacing NRF24L01 and RFID on same arduino

Scheduled Pinned Locked Moved Troubleshooting
15 Posts 5 Posters 2.8k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gohanG gohan

    I had the same problem when I tried it: if you connect the rfid reader you loose the nrf24 communication. It is like they don't like sharing the SPI :D

    mfalkviddM Offline
    mfalkviddM Offline
    mfalkvidd
    Mod
    wrote on last edited by
    #5

    @gohan that's probably why the examples has this:

    // Enable soft spi as radio has a hard time sharing spi 
    
    1 Reply Last reply
    0
    • 1 Offline
      1 Offline
      123cheatn
      wrote on last edited by 123cheatn
      #6

      thanks to all of you for the reply.
      I found the solution.
      after looking at the code and some debugging.
      my code is working fine now.
      This is the code

      /**
       * --------------------------------------------------------------------------------------------------------------------
       * Example sketch/program showing how to read data from more than one PICC to serial.
       * --------------------------------------------------------------------------------------------------------------------
       * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
       *
       * Example sketch/program showing how to read data from more than one PICC (that is: a RFID Tag or Card) using a
       * MFRC522 based RFID Reader on the Arduino SPI interface.
       *
       * Warning: This may not work! Multiple devices at one SPI are difficult and cause many trouble!! Engineering skill
       *          and knowledge are required!
       *
       * @license Released into the public domain.
       *
       * Typical pin layout used:
       * -----------------------------------------------------------------------------------------
       *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
       *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
       * Signal      Pin          Pin           Pin       Pin        Pin              Pin
       * -----------------------------------------------------------------------------------------
       * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
       * SPI SS 1    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
       * SPI SS 2    SDA(SS)      ** custom, take a unused pin, only HIGH/LOW required **
       * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
       * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
       * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
       *
       */
      
      #include <SPI.h>
      #include <MFRC522.h>
      #include <nRF24L01.h>
      #include <RF24.h>
      RF24 radio(7, 8); // CE, CSN
      const byte add[6] = "00001";
      #define RST_PIN         9          // Configurable, see typical pin layout above
      #define SS_PIN        10         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
      //#define SS_2_PIN        8          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
      
      #define NR_OF_READERS   1
      
      byte ssPins[] = {SS_PIN};
      
      MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.
      
      /**
       * Initialize.
       */
      void setup() {
      
        Serial.begin(9600); // Initialize serial communications with the PC
        while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
      
        SPI.begin();        // Init SPI bus
      
        for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
          mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
          Serial.print(F("Reader "));
          Serial.print(reader);
          Serial.print(F(": "));
          mfrc522[reader].PCD_DumpVersionToSerial();
        }
        radio.begin();
        radio.openWritingPipe(add);
        radio.setPALevel(RF24_PA_MAX);
        radio.stopListening();
      }
      /**
       * Main loop.
       */
      void loop() {
        for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
          // Look for new cards
      
          if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
            Serial.print(F("Reader "));
            Serial.print(reader);
            // Show some details of the PICC (that is: the tag/card)
            Serial.print(F(": Card UID:"));
            dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
            Serial.println();
            mfrc522[reader].PCD_StopCrypto1();
          }
        }
      }
      
      /**
       * Helper routine to dump a byte array as hex values to Serial.
       */
      void dump_byte_array(byte *buffer, byte bufferSize) {
        int c[]={176,240,158,94};
        int count=0;
        delay(10);
        for (byte i = 0; i < bufferSize; i++) {
          delay(10);
          Serial.print(buffer[i] < 0x10 ? " 0" : " ");
          Serial.print(buffer[i], HEX);
        }
        Serial.println();
        for (byte i = 0; i < bufferSize; i++) {
          if(buffer[i]==c[i]){
            count++;
          }
        }
        int flag=0;
        if(count==4){
          const char text[] = "17624015894";
          radio.write(&text, sizeof(text));
        }else{
          const char text[] = "No";
          radio.write(&text, sizeof(text));
        }
      }
      
      void before() {
      // Make sure MFRC is disabled from the SPI bus
      pinMode(RST_PIN, INPUT);
      digitalWrite(RST_PIN, HIGH);
      pinMode(SS_PIN, OUTPUT);
      digitalWrite(SS_PIN, LOW);
      }
      
      1 Reply Last reply
      1
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #7

        But you still haven't used any mysensors code :thinking_face:

        YveauxY 1 2 Replies Last reply
        0
        • gohanG gohan

          But you still haven't used any mysensors code :thinking_face:

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #8

          @gohan and we still don't know what the issue was :rolling_on_the_floor_laughing:

          http://yveaux.blogspot.nl

          1 1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #9

            he wrote me a PM, so the problem is the one I described

            1 Reply Last reply
            0
            • YveauxY Yveaux

              @gohan and we still don't know what the issue was :rolling_on_the_floor_laughing:

              1 Offline
              1 Offline
              123cheatn
              wrote on last edited by
              #10

              @yveaux the problem was in the code and in the circuit, actually both the modules were not working together.
              Previously I had to disconnect either one of the module.

              YveauxY 1 Reply Last reply
              0
              • gohanG gohan

                But you still haven't used any mysensors code :thinking_face:

                1 Offline
                1 Offline
                123cheatn
                wrote on last edited by
                #11

                hey, @gohan it was working fine without mysensors library.

                gohanG 1 Reply Last reply
                0
                • 1 123cheatn

                  @yveaux the problem was in the code and in the circuit, actually both the modules were not working together.
                  Previously I had to disconnect either one of the module.

                  YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by
                  #12

                  @123cheatn Ok, clear. Thanks for reporting back! :+1:

                  http://yveaux.blogspot.nl

                  1 Reply Last reply
                  0
                  • 1 123cheatn

                    hey, @gohan it was working fine without mysensors library.

                    gohanG Offline
                    gohanG Offline
                    gohan
                    Mod
                    wrote on last edited by
                    #13

                    @123cheatn if you make it to work with mysensors, pls report back

                    1 1 Reply Last reply
                    0
                    • gohanG gohan

                      @123cheatn if you make it to work with mysensors, pls report back

                      1 Offline
                      1 Offline
                      123cheatn
                      wrote on last edited by
                      #14

                      @gohan sure I will try.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        Gokhan Tuncel
                        wrote on last edited by
                        #15

                        @123cheatn I'm trying very similar project but could not achieve it :(
                        On master Arduino, RFID UID ID will be read and send to 4 other Arduinos; they will react regarding to UID ID (activate a relay, led etc.). Also those 4 Arduinos have MFRC522 but won't be sending RF UID ID's, just reacting depending on which UID ID read by their reader.
                        I think I could not solve multiple SPI module code :/ Here is my code;

                        #include <SPI.h>
                        #include <MFRC522.h>
                        #include <RF24.h>
                        #include <NRF24.h>
                        #include <nRF24L01.h>
                        NRF24 radio;
                        
                        unsigned long time_now = 0;
                        int blinkled = 300;
                        int value;
                        int displace = 1000;
                        unsigned long CountDownStarted = 0;
                        
                        int CountdownState = 0;
                        
                        int Set60State = 0;
                        int Set90State = 0;
                        int EngineState = 0;
                        
                        #define EnginePin 6
                        #define StartPin 7
                        #define Set90Pin 8
                        #define Set60Pin 9
                        #define TestLed 13
                        
                        String cardUID ;
                        #define SS_RF 10
                        #define RST 5
                        #define SS_NRF 53
                        MFRC522 mfrc522(SS_RF, RST);   // Create MFRC522 instance.
                        
                        
                        void setup()
                        { pinMode(EnginePin, OUTPUT);
                          pinMode(StartPin, OUTPUT);
                          pinMode(Set90Pin, OUTPUT);
                          pinMode(Set60Pin, OUTPUT);
                          Serial.begin(115200);   // Initiate a serial communication
                          SPI.begin();      // Initiate  SPI bus
                        
                          radio.setAddress(0xD2);
                          radio.begin(40, 53);
                          radio.setChannel(124);
                          radio.setRetries(0, 15);
                          radio.setActive(true);
                          pinMode(SS_RF, OUTPUT);
                          pinMode(SS_NRF, OUTPUT);
                          pinMode(TestLed, OUTPUT);
                          digitalWrite(EnginePin, LOW);
                          digitalWrite(StartPin, LOW);
                          digitalWrite(Set90Pin, LOW);
                          digitalWrite(Set60Pin, LOW);
                          digitalWrite(TestLed, LOW);
                        }
                        void loop()
                        {
                          radio.startListening();
                        
                          if (CountdownState == 1) {
                            CountDown();
                          }
                        
                        
                          // Look for new cards
                          if ( ! mfrc522.PICC_IsNewCardPresent())
                          {
                            return;
                          }
                          // Select one of the cards
                          if ( ! mfrc522.PICC_ReadCardSerial())
                          {
                            return;
                          }
                        
                          //Show UID on serial monitor
                          Serial.print("UID tag :");
                          String content = "";
                          byte letter;
                          for (byte i = 0; i < mfrc522.uid.size; i++)
                          {
                            Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
                            Serial.print(mfrc522.uid.uidByte[i], HEX);
                            content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
                            content.concat(String(mfrc522.uid.uidByte[i], HEX));
                          }
                          Serial.println();
                          Serial.print("Message : ");
                          content.toUpperCase();
                        
                        
                          if (content.substring(1) == "E0 0A DD A4" || content.substring(1) == "C0 57 FE A7" || content.substring(1) == "B0 AB 9F A5" || content.substring(1) == "50 51 1B A4" )
                          {
                            if (EngineState == 0) {
                              
                              digitalWrite(EnginePin, HIGH);
                              Serial.print(F("Sending Engine Code... "));
                              bool sent = radio.send(0xD3, "E0 0A DD A4");
                              bool sent2 = radio.send(0xD4, "E0 0A DD A4");
                              bool sent3 = radio.send(0xD5, "E0 0A DD A4");
                              bool sent4 = radio.send(0xD6, "E0 0A DD A4");
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              EngineState = 1;
                              delay(50);
                            }
                        
                            if (EngineState == 1) {
                              bool sent = radio.send(0xD3, "E0 0A DD A4");
                              bool sent2 = radio.send(0xD4, "E0 0A DD A4");
                              bool sent3 = radio.send(0xD5, "E0 0A DD A4");
                              bool sent4 = radio.send(0xD6, "E0 0A DD A4");
                        
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              delay(100);
                            }
                          }
                        
                          if ((EngineState != 0) && (content.substring(1) == "CD 9E 08 75" || content.substring(1) == "7D A6 4F 75" || content.substring(1) == "8D 2B 55 75" || content.substring(1) == "DD D1 6C 3E" ))
                          {
                            if (CountdownState == 0) {
                              Serial.println("Countdown Started");
                              digitalWrite(StartPin, HIGH);
                              delay(50);
                              digitalWrite(StartPin, LOW);
                              Serial.print(F("Sending Start Code... "));
                              bool sent = radio.send(0xD3, "CD 9E 08 75");
                              bool sent2 = radio.send(0xD4, "CD 9E 08 75");
                              bool sent3 = radio.send(0xD5, "CD 9E 08 75");
                              bool sent4 = radio.send(0xD6, "CD 9E 08 75");
                        
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              CountdownState = 1;
                            }
                        
                            if (CountdownState == 1) {
                              Serial.print(F("Sending Start Code... "));
                              bool sent = radio.send(0xD3, "CD 9E 08 75");
                              bool sent2 = radio.send(0xD4, "CD 9E 08 75");
                              bool sent3 = radio.send(0xD5, "CD 9E 08 75");
                              bool sent4 = radio.send(0xD6, "CD 9E 08 75");
                        
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              delay(100);
                            }
                        
                          }
                        
                         
                        
                          if ((EngineState != 0) && (content.substring(1) == "7D 1C 65 5C" || content.substring(1) == "AD C2 5C 74"))
                          {
                            if (Set90State == 0) {
                              
                              digitalWrite(Set90Pin, HIGH);
                              delay(50);
                              digitalWrite(Set90Pin, LOW);
                              Serial.print(F("Sending 90' Code... "));
                              bool sent = radio.send(0xD3, "7D 1C 65 5C");
                              bool sent2 = radio.send(0xD4, "7D 1C 65 5C");
                              bool sent3 = radio.send(0xD5, "7D 1C 65 5C");
                              bool sent4 = radio.send(0xD6, "7D 1C 65 5C");
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              Set90State = 1;
                              delay(50);
                        
                            }
                            else
                            {
                              
                              bool sent = radio.send(0xD3, "7D 1C 65 5C");
                              bool sent2 = radio.send(0xD4, "7D 1C 65 5C");
                              bool sent3 = radio.send(0xD5, "7D 1C 65 5C");
                              bool sent4 = radio.send(0xD6, "7D 1C 65 5C");
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              delay(100);
                            }
                          }
                        
                        
                        
                          if ((EngineState != 0) && (content.substring(1) == "20 C4 18 A4" || content.substring(1) == "1D AE 2C 75"))
                          {
                            if (Set60State == 0) {
                              
                              digitalWrite(Set60Pin, HIGH);
                              delay(50);
                              digitalWrite(Set60Pin, LOW);
                             
                              bool sent = radio.send(0xD3, "20 C4 18 A4");
                              bool sent2 = radio.send(0xD4, "20 C4 18 A4");
                              bool sent3 = radio.send(0xD5, "20 C4 18 A4");
                              bool sent4 = radio.send(0xD6, "20 C4 18 A4");
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              Set60State = 1;
                              delay(50);
                        
                            }
                            else
                            {
                              
                              bool sent = radio.send(0xD3, "20 C4 18 A4");
                              bool sent2 = radio.send(0xD4, "20 C4 18 A4");
                              bool sent3 = radio.send(0xD5, "20 C4 18 A4");
                              bool sent4 = radio.send(0xD6, "20 C4 18 A4");
                              Serial.println(sent ? "OK" : "failed");
                              Serial.println(sent2 ? "OK" : "failed");
                              Serial.println(sent3 ? "OK" : "failed");
                              Serial.println(sent4 ? "OK" : "failed");
                              delay(100);
                            }
                          }
                        
                        
                          if (radio.available()) {
                            char buf[32];
                            uint8_t numBytes = radio.read(buf, sizeof(buf));
                            Serial.print(F("Received: "));
                            Serial.println(buf);
                          }
                        
                        
                        }
                        
                        
                        void CountDown() {
                          time_now = millis();
                          value = 128 + 127 * cos(2 * PI / blinkled * time_now);
                          analogWrite(TestLed, value);
                          //Serial.println(value);
                        }
                        

                        Do you have any idea to solve this?

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        26

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.1k

                        Posts


                        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • MySensors
                        • OpenHardware.io
                        • Categories
                        • Recent
                        • Tags
                        • Popular