MKR 1500 - GPS and RFID don't work together

Hi all,

I am apparently having some kind of conflict with I2C and SPI ports.

I have Arduino MKR 1500 and MKR GPS connected in I2C port, and RFID Reader connected in SPI bus. Everything seems to be correct, but when I initialize SPI (RFID), GPS stops working or vice versa. It seems that one interrupts the other.

Is this something to do with interrupts? I don't quite understand how interrupts work.

The GPS model is MKR GPS and RFID model is MFRC522

Could anyone please give me any idea on what could be the reason I am facing this problem?

Thank you.

Code:

#include <Arduino_MKRGPS.h>
#include <SPI.h>
#include <MFRC522.h>
//Pins for RFID
const int pinRST = 15;
const int pinSDA = 11;

MFRC522 mfrc522(pinSDA, pinRST); // Set up mfrc522 on the Arduino

void setup() {
  // initialize serial communications and wait for port to open:
  
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  if (!GPS.begin(GPS_MODE_I2C)) {
    Serial.println("Failed to initialize GPS!");
    while (1);
  }

 
  SPI.begin(); 
  //Innitialize RFID Reader// Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card

   
}

void loop() {
  
  // check if there is new GPS data available
  if (GPS.available()) {
    // read GPS values
    float latitude   = GPS.latitude();
    float longitude  = GPS.longitude();
    float altitude   = GPS.altitude();
    float speed      = GPS.speed();
    int   satellites = GPS.satellites();

    // print GPS values
    Serial.print("Location: ");
    Serial.print(latitude, 7);
    Serial.print(", ");
    Serial.println(longitude, 7);

    Serial.print("Altitude: ");
    Serial.print(altitude);
    Serial.println("m");

    Serial.print("Ground speed: ");
    Serial.print(speed);
    Serial.println(" km/h");

    Serial.print("Number of satellites: ");
    Serial.println(satellites);

    Serial.println();
  }else{
      //Serial.println("==================");
  }
}

You forgot the link to your MFRC522 breakout. They are very different although they often have exactly the same name.

MFRC522 mfrc522(pinSDA, pinRST); // Set up mfrc522 on the Arduino

Not very clever, using the SDA pin as the chip select for the MFRC522. You even call it SDA...

Sorry my ignorance but I didn't understand. Shouldn't I use SDA pin on arduino? Which one should I use?

What link are you referring to?

This is the MFRC522 that I am using:

I am doing the following wiring:

RFID VCC --> Arduino VCC
RFID RST --> Arduino RST
RFID GND --> Arduino GND
RFID MISO --> Arduino MISO (10)
RFID MOSI --> Arduino MOSI ( 8 )
RFID SCK --> Arduino SCK (9)
RFID NSS --> Arduino SDA (11)

MKR GPS --> Arduino I2C port

Please note that both modules work fine when they run individually.

Thank you so much for your help.

Sorry my ignorance but I didn't understand. Shouldn't I use SDA pin on arduino? Which one should I use?

You can use it but not twice for different tasks. The SDA pin is part of the I2C interface so if you use the I2C interface to connect to the GPS you must not use it again for the RFID reader.

What link are you referring to?

This is the MFRC522 that I am using:
https://www.jaycar.com.au/arduino-compatible-rfid-read-and-write-module/p/XC4506

That link I've asked for. I never buy hardware without the necessary documentation. breakout boards must have their schematics as part of the documentation in my opinion.

Hi Pylon,

Thanks for sending this. You caught my attention for the SDA PIN so I went to research further.

So I decided to use the RX PIN (in a desperate moment because I had to present the prototype to my boss! lol) and both modules (GPS and RFID) worked just fine. This was Friday, I didn't use the device until today Monday, and for my surprise, the problem has returned. GPS works but the RFID doesn't.

So I decided to use TX PIN today and now both modules are working fine again.

Do you have any clue what is happening?

Thank you.

Do you have any clue what is happening?

Which part of my explanation didn't you understand? You cannot use the same signal (even if it's available on multiple locations on that board) for two different tasks.

Sorry, if I didn't understand wasn't because I didn't pay attention or ignored your explanation, but maybe because of lack of experience at my end.

You said that wasn't very clever using SDA as chip select because SDA is I2C port, so as I mentioned I changed to RX and both worked fine for a few minutes and then it stopped work, and then I changed to TX port, both worked great and then stopped work. I am just trying to understand the logic here.

So maybe I misunderstood in the sense of that either TX and RX pins are also I2C and cannot be used because they will conflict with the I2C protocol being used by the GPS?

I might be again making more silly questions. Sorry, that's I am here in a forum seeking for assistance.

Thanks for your help.

You said that wasn't very clever using SDA as chip select because SDA is I2C port, so as I mentioned I changed to RX and both worked fine for a few minutes and then it stopped work, and then I changed to TX port, both worked great and then stopped work. I am just trying to understand the logic here.

I did not realize that you stayed at using the RX pin, I got the impression that you changed back to the SDA pin.

So maybe I misunderstood in the sense of that either TX and RX pins are also I2C and cannot be used because they will conflict with the I2C protocol being used by the GPS?

No, these pins should be available for you to use.

I might be again making more silly questions. Sorry, that's I am here in a forum seeking for assistance.

Sure, I apologize, I interpreted your last post incorrectly.

Can you provide more details about the state if you use another pin. How long does it work? What happens if it doesn't work? Post the exact output of the serial monitor (also using code tags)!

Please post a wiring diagram of the changed wiring (may be hand drawn).

Hi,

I am sorry for the long delay in responding. I had to stop working on this project but now I am back.

I am managed to get both modules working together, the problem was something that I had wired wrongly. I have attached the wiring diagram for reference.

But unfortunately, another issue arrived:

This MKR 1500 board has a known issue that makes the board freeze at nbAccess.begin() == NB_READY instruction. People say the problem is related to power-wise. That's why I had ditched the RFID module from my project.

However, now I am required to use the RFID again and the board has hanged ALWAYS at nbAccess.begin() == NB_READY.

Can anyone please give any clue how to resolve this?

However, now I am required to use the RFID again and the board has hanged ALWAYS at nbAccess.begin() == NB_READY.

You haven't posted any code yet that contains this line.

According to the wiring diagram you have also connected an SD card reader. Most cheap Chinese boards have a bug in the level converter which don't tri-state MISO if CS is pulled HIGH. Some of them can be fixed if you're good in hand soldering, otherwise you might have to buy a new board from one of the serious suppliers (Adafruit, Sparkfun).

Hi,

Thanks for the advice, but I believe the SD Card Reader must be good. It is this one: https://www.jaycar.com.au/arduino-compatible-sd-card-interface-module/p/XC4386

The code is attached. It is quite a long code, I am here to clarify any questions. Thanks a lot for the help.

Smart-Nav_v4.0.ino (23 KB)

mirandax:
I believe the SD Card Reader must be good.

Why make that assumption when it's so easy to verify it for yourself? Open File > Examples > SD > CardInfo. Upload the sketch to your MKR NB 1500. Open serial monitor and verify the SD card is recognized.

Sorry but I never said that the SD Card Reader is not recognized. I haven't had any issues with it. The SD Card is not part of the problem.

I only posted the code because Pylon asked for it, which makes sense as I didn't have post so far.

The issue that I have is that the board freezes when reaches if ((nbAccess.begin("2412", APN) == NB_READY)) { --- line 638 by the way.

Maybe my sentence "must be good" caused an eventual slackness of my part, and it should have been "should be good as I haven't had any issues". (English is not my first language).

Thanks for the advice, but I believe the SD Card Reader must be good. It is this one: https://www.jaycar.com.au/arduino-compatible-sd-card-interface-module/p/XC4386

Some of the problematic boards look exactly like the linked one. I would expect problems if more than just that once device is connected to the SPI bus.

Try to change the call to:

if ((nbAccess.begin("2412", APN, true, false) == NB_READY))  {

Does it still freeze? If you tell it to freeze if there's no connection, it does exactly that.

Hi Pylon,

Sorry delay for replying.

Just to update you that I've been having much better results after I added an external Li-Po battery connected to the board. The main point where the code used to freeze was at the modem.begin, but now it rarely freezes. Only sometimes.

Thanks for your suggestion, I will try with those parameters and get back to you. Thanks again.