USB Host Shield and RFID-Scanner

Hello together

I have used the following hardware in my setup:

  • Arduino UNO R4 Wifi
  • USB Host Shield
  • RFID - RC522 (Scanner)

The following problem has arisen. If I connect the RFID scanner directly to the Arduino as shown in the picture below, I can read the transponder. If I mount the USB host shield on the Arduino and then the RFID scanner on it, it no longer works.
(Side fact: If I do not connect the 6 pins (CSP connector) to the Arduino board, the scanner works)

My question now is, why does the RFID scanner not work with the USB host shield?

Setup:

USB Host Shield (with the marked CSP Connector I mentioned in the text before):

here you find my Code:

//////////////////////////////////////////////////////////////////////////
// Bibliotheken
#include <MFRC522.h>  // MFRC522 RFID module library.
#include <SPI.h>      // SPI device communication library.

//////////////////////////////////////////////////////////////////////////
// I/O-Mapping
#define RST_PIN 4      // Defines pins for RST, SS conncetions respectively.
#define CS_PIN 3

//#define OLED_SDA_PIN 19
//#define OLED_SCL_PIN 18

byte readCard[4];     // Array that will hold UID of the RFID card.

byte SusuID[4] = {0xB0, 0x5E, 0xDF, 0xAD};
byte CaroID[4] = {0xA0, 0xEF, 0xDF, 0xAD};
byte KPID[4] = {0xE0, 0x59, 0xD7, 0xAD};

int successRead;
int new_User = 0;
int old_User = 0;

const int dayPin = 7;
const int weekPin = 6;
const int monthPin = 5;
bool ready;

MFRC522 mfrc522(CS_PIN, RST_PIN);   // Creates MFRC522 instance.
MFRC522::MIFARE_Key key;          // Creates MIFARE key instance.

void setup() {
  pinMode(dayPin, INPUT_PULLUP);
  pinMode(weekPin, INPUT_PULLUP);
  pinMode(monthPin, INPUT_PULLUP);
  Serial.begin(9600); // Starts the serial connection at 9600 baud rate.
  SPI.begin();        // Initiates SPI connection between RFID module and Arduino.
  mfrc522.PCD_Init(); // Initiates MFRC522 RFID module.

  Serial.println("RFID reading process initiated.");    // Prints user commands.
  Serial.println("Please scan your RFID card to the reader.");
}

void loop()
{
  new_User = getID(); 
  char time = getTime();
  Serial.println(new_User);
  if ((new_User != old_User) && (new_User != -1)) {
    Serial.print("Benutzer");
    Serial.println(new_User);
    old_User = new_User;
    if (time == 'd' || time == 'w' || time == 'm') {
      ready = true;
    }
  }
  if (ready == true) {
    Serial.print("Benutzer: ");
    Serial.print(new_User);
    Serial.print(", Dauer: ");
    Serial.println(time);
  }
}


int getID() // Function that will read and print the RFID cards UID.
{
  // Look for new cards or Nothing to read
  if ( !mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {

    return -1;  // kein return Wert komische Zahl, da Funktion auf Variable geht
  }

  Serial.print("UID: ");    
  for (int i = 0; i < mfrc522.uid.size; i++) {  
    readCard[i] = mfrc522.uid.uidByte[i];   // Reads RFID cards UID.
    Serial.print(readCard[i], HEX);         // Prints RFID cards UID to the serial monitor.
  }
  mfrc522.PICC_HaltA();     // Stops the reading process.
  int benutzer = User();
  Serial.println(benutzer);
  return benutzer;
}

// Auswertung User
int User() {
  if(mfrc522.uid.uidByte[0] == SusuID[0] && mfrc522.uid.uidByte[1] == SusuID[1] && mfrc522.uid.uidByte[2] == SusuID[2] && mfrc522.uid.uidByte[3] == SusuID[3]) {
    return 1;
  }
  if(mfrc522.uid.uidByte[0] == CaroID[0] && mfrc522.uid.uidByte[1] == CaroID[1] && mfrc522.uid.uidByte[2] == CaroID[2] && mfrc522.uid.uidByte[3] == CaroID[3]) {
    return 2;
  }
  if(mfrc522.uid.uidByte[0] == KPID[0] && mfrc522.uid.uidByte[1] == KPID[1] && mfrc522.uid.uidByte[2] == KPID[2] && mfrc522.uid.uidByte[3] == KPID[3]) {
    return 3;
  }
  return 0;     // kein bekannter Nutzer 
}

// Dauer
char getTime() {
  bool day;
  bool week;
  bool month;
  if (day == LOW && week == HIGH && month == HIGH) {
    return 0x64;
  } 
  if (day == HIGH && week == LOW && month == HIGH) {
    return 0x77;
  } 
  if (day == HIGH && week == HIGH && month == LOW) {
    return 0x6D;
  } 
  return 0;
}
`

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