Arduino uno R4 issues with serial communications rfid and gps module

#include <WiFiS3.h>
#include <SPI.h>
#include <MFRC522.h>
#include <ArduinoJson.h>
#include <TinyGPS.h>

#define RST_PIN 9
#define SS_PIN 10  


MFRC522 mfrc522(SS_PIN, RST_PIN);

//WIFI CREDENTIALS//
char ssid[] = "Home 4G";
char pass[] = "P@ssw0rd123!";
int status = WL_IDLE_STATUS;

const char* host = "www.ssbms2024.online";

TinyGPS gps;

//SETUP//
void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  while (!Serial) {
    ;
  }
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }
  Serial.println("You're connected to the network");
  Serial.println("IP Address: ");
  Serial.println(WiFi.localIP());

  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("RFID ready");

}

// READ DATA FROM SERVER //
void read_response(WiFiClient& client) {
  uint32_t data_num = 0;
  bool jsonDetected = false;
  char data[500];
  while (client.available() && data_num < 500) {
    char c = client.read();
    if ('{' == c) {
      jsonDetected = true;
    }
    if (jsonDetected) {
      data[data_num++] = c;
    }
  }
  data[data_num] = '\0';

  // RAW DATA JSON DATA //
  if (jsonDetected) {
    Serial.println("Raw JSON Response:");
    Serial.println(data);

    DynamicJsonDocument doc(512);
    DeserializationError error = deserializeJson(doc, data);
    
    if (error) {
        Serial.print("deserializeJson() failed: ");
        Serial.println(error.c_str());
    } else {
        Serial.println("Parsed JSON:");
        const char* phoneNumber = doc["contact_number"];
        const char* message = doc["message"];
        const char* status = doc["status"];
        const char* timestamp = doc["timestamp"];
        const char* guardian = doc["guardian"];
        const char* first_name = doc["child_firstname"];
        const char* last_name = doc["child_lastname"];
        const char* year_level = doc["year_level"];
        const char* section = doc["section"];
        
        Serial.print("Phone Number: ");
        Serial.println(phoneNumber);
        Serial.print("Message: ");
        Serial.println(message);
        Serial.print("Timestamp: ");
        Serial.println(timestamp);
        Serial.print("Guardian: ");
        Serial.println(guardian);
        Serial.print("Child's Name: ");
        char childName[50];
        sprintf(childName, "%s %s", first_name, last_name);
        Serial.println(childName);
        Serial.print("Yr & Sec: ");
        char yrAndSec[50];
        sprintf(yrAndSec, "%s %s", year_level, section);
        Serial.println(yrAndSec);
        Serial.print("Status: ");
        Serial.println(status);

    }
  }
}

//READ RFID//
void loop() {
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    String rfidData = "";
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      rfidData += String(mfrc522.uid.uidByte[i], HEX);
    }
 
    Serial.println("RFID Tag: ");
    Serial.println(rfidData);

    //CONNECT TO THE SERVER SSBMS//
    WiFiClient client;
    if (client.connect(host, 80)) {
      Serial.println("Connected to server");
      client.print("GET /validate_rfid?rfid=" + rfidData + " HTTP/1.1\r\n");
      client.print("Host: ");
      client.print(host);
      client.print("\r\n");
      client.print("Connection: close\r\n\r\n");
      
      while (client.connected() && !client.available()) delay(1);

      read_response(client);

      client.stop();
    } else {
      Serial.println("Connection to server failed");
    }

    delay(1000);
  }

  // GPS data reading
  while (Serial1.available() > 0) {
    char c = Serial1.read();
    if (gps.encode(c)) {
      float latitude, longitude;
      gps.f_get_position(&latitude, &longitude);
      Serial.print("Latitude: ");
      Serial.print(latitude, 6);
      Serial.print(", Longitude: ");
      Serial.println(longitude, 6);
    }
    delay(5000);
  }
}

I have a project that involves reading RFID cards to validate them against a server and reading GPS latitude and longitude data every 5 seconds. However, I'm facing two issues:

  1. When I upload the code, only the GPS functionality works, and the RFID scanning does not. I've checked the wiring and connections, and the RFID reader is powered and functional. What could be causing this issue?
  2. I'm also experiencing problems with software serial not working with the GPS module. I've double-checked the software serial pins and settings in my code, but it's still not working. Any suggestions on how to troubleshoot this?

PS: i am using RC522 RFID module, neo6mv2 GPS module, and the Arduino UNO R4 WIFI

Well I don't know why you deleted this same question you just asked?

One thing that is wrong is the way you wire up your RFID reader. This is a 3V3 device and you are blasting it with 5V signals from the Arduino.

I know that is what a lot of crap websites say but they are wrong. At the best the RFID reader will work for a bit and then fail.

This is the proper way of wiring it up.

Check the GPS board to see if it can cope with 5V signals from the R4 board?

I ma not sure that software serial works at all on an R4 board. Check for compatibility here:-

2 Likes

deleted the first post cause of some errors in the format.
the RFID reader was connected to 3.3V, while the GPS module was connected to 5V. Both modules are functional individually, but when used together, only the GPS works.

If you indeed have a GY-GPS6MV2 module, that's a 3.3V board, just like the RC522 board.

Yes, the GPS board has a 3.3V regulator on it. So you can power the board with 5V. But neither board has level shifters on their signal pins. And the signal pins are not 5V tolerant.

Read the RC522 datasheet. Read the NEO-6 datasheet. Look at the maximum allowed Vi/Vih. 5V on inputs exceeds the Absolute Maximum Ratings for both. As @Grumpy_Mike correctly pointed out, you need to reduce the 5V signals from the Uno to 3.3V, or you will sooner or later have modules which no longer function.

1 Like

Ok we will try to connect the rfid module that way also, how about the gps module? How should the signal pins be connected to the arduino. We will get back after connecting it properly

Same sort of idea as the RFID module: GPS Tx to Uno Rx straight through, and a serial resistor on the Uno's Tx line with another resistor from the GPS's Rx line to ground. Though I'd use different values myself; 1.2K in series and 2.2K to ground rather than 300 & 1K. 300 & 1K only reduces 5V to 3.85V, which is right on the edge of what the RC522 can take, and still well above what the GPS can.

Be prepared for it not to make any difference at this point though. Either or both modules may already be damaged by the 5V inputs they've been subjected to.

Thank you for the information, if nothing happens we will try with our back up reserve rfid and gps as we were prepared something might happened to our modules. We will be back and notify what our problem would be, hopefully that was the solution to our problem.

You can always use the edit icon, the pencil at the end of your post to change everything in your post.

I know that will not work on the R4, You should use a delay of about a second instead.

1 Like

I have found this does not work at all.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.