Spi Bad connect

Hello.
I'm trying to run this project on my own hardware. My project consists of 6 RFID tags and a relay.
I've assembled it and it works.

Here's a prototype without a lock; I wrote the RC522 simulation module for wokwi myself to test my work.

However, I encountered the following problems on real hardware:

  1. Soldering the SPI channel reliably turned out to be difficult. There are 6 wires in a bundle; they often break. Furthermore, I discovered that only 3-4 sensors work reliably each time I turn it on. Even at the VersionReg stage, I see unknown symbols from time to time. I think this is interference due to a poor connection. Any ideas on how to connect the wires reliably and without interference? 2. I've read many articles, and some of them recommend changing the logic of the extraneous signals to 3V, supposedly to avoid interference. I didn't find any point in this.

  2. I followed the advice of placing a 1000 uf capacitor between 3V and GND to smooth out the spikes, but it didn't help.

  3. Some people recommend installing an additional power supply, but I've measured the turn-on current with an ammeter, and it doesn't even exceed 50 mA (30-35 mA). I ​​also discovered that if the 3V line is interrupted, the sensors continue to work, but not all of them (parasitic power supply).

Sometimes everything works like clockwork, but that's 1 time out of 10.

No action, simple on/off. 3 different result.



My 4-digit display decoding:
1st digit: RC522 chip successfully reads VersionReq. This is done once in setup() . Later, I moved it to the loop and discovered some instability.
2nd digit: card inserted
3rd digit: card inserted and UID tag in place
4th digit: relay status
Each segment has its own RFID sensor

The first thing to do is to read the pinned post re 'How to get the most from the forum'. There you will learn that photos.videos aren't always a good choice, especially from what appears to be a phone screen.
Remember, we can't see what you see.

1 Like

Post your annotated schematic, showing all connections, power sources and links to technical information on the hardware items. Also post your code using code tags. If you follow @sonofcy recommendation that explains what we need and how to post. Remember without the needed information we can only guess, and I do not like that game, somebody always unhappy.

Hello everyone from Tashkent.
Yes, I apologize, the problem is critical, and I was a bit hasty with my question on the forum.

  1. I provide the full source code arduino-box-unlocker/src at main · anton21m/arduino-box-unlocker · GitHub

  2. I also created a prototype in wokwi https://wokwi.com/projects/437202456035501057 (always choose 1 card to solve the puzzle)

  3. Demonstration of work
    https://youtube.com/shorts/f8VYgHAoIOI
    https://youtube.com/shorts/8vSvEa8msG8
    https://youtu.be/tpcwLTZFWBQ

  4. And I just pulled out the debug logs here. Code messages, as you can see, they are different, but nevertheless, the cards work, but not all of them, although 6 cards are installed.

MFRC522 Access Control Initialize.
Puzzle state reset (card data cleared).
Reader 0: Code 134 WARNING: Communication failure, is the MFRC522 properly connected?
Reader 1: Code 130 WARNING: Communication failure, is the MFRC522 properly connected?
Reader 2: Code 142 WARNING: Communication failure, is the MFRC522 properly connected?
Reader 3: Code 130 WARNING: Communication failure, is the MFRC522 properly connected?
Reader 4: Code 128 WARNING: Communication failure, is the MFRC522 properly connected?
Reader 5: Code 132 WARNING: Communication failure, is the MFRC522 properly connected Initialized 0 / 6 readers.
Puzzle state reset (card data cleared).
Card on Reader 0: UID: 77 18 40 05
Unknown Tag on Reader 0
Card on Reader 1: UID: AD 25 3B 05
Unknown Tag on Reader 1
Card on Reader 2: UID: 04 2D 3E 05
Card on Reader 3: UID: 89 C2 48 05 
Unknown Tag on Reader 3
:ERR Version: on id: 5-> 132
System needs 5 more correct cards. Door is LOCKED.
Cards Present: 4 Cards Correct: 1
Puzzle state reset (card data cleared).
Card on Reader 0: UID: 77 18 40 05
Unknown Tag on Reader
Card on Reader 1: UID: AD 25 3B 05 
Unknown Tag on Reader 1
Card on Reader 2: UID: 04 2D 3E 05
Card on Reader 3: UID: 89 C2 48 05 
Unknown Tag on Reader 3
:ERR Version: on id: 5-> 132
System needs 5 more correct cards. Door is LOCKED.

4.I modified the program a little (Other files are the same)

#include <SPI.h>
#include "config.h"
// Forward declarations for functions defined in functions.ino
void InitializePuzzleState();
void updateDisplay();
void dump_byte_array(byte * buffer, byte bufferSize);

void setup() {
  delay(1000);

  pinMode(RST_PIN, OUTPUT); 
  digitalWrite(RST_PIN, LOW); 
  delay(5);                   
  digitalWrite(RST_PIN, HIGH); 
  delay(1000); 
  
  Serial.begin(9600);
  SPI.begin();
  
  Serial.println(F("MFRC522 Access Control Initialize."));
  
 
  pinMode(ACCESS_RELAY_PIN, OUTPUT);
  
  digitalWrite(ACCESS_RELAY_PIN, LOW); 
  display.clear();
  display.brightness(3); 

  InitializePuzzleState();
  
  // repeat initialization
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    bool success = false;
    byte version = 0x00;
    int attempt = 0;
    
    
    while (!success && attempt < 5) { 
      mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN);
      version = mfrc522[reader].PCD_ReadRegister(MFRC522::VersionReg);
      
      if (version == 0x92) {
        success = true;
      } else {
        attempt++;
        Serial.print(F("Reader "));
        Serial.print(reader);
        Serial.print(F(": Attempt "));
        Serial.print(attempt);
        Serial.print(F(" failed (Code "));
        Serial.print(version);
        Serial.println(F("). Retrying..."));
        
        delay(200); 
      }
    }
    
    // Result
    if (success) {
      Serial.print(F("Reader "));
      Serial.print(reader);
      Serial.print(F(": "));
      mfrc522[reader].PCD_DumpVersionToSerial();
      initializedReadersCount++;
      readerInitialized[reader] = true;
    } else {
      Serial.print(F("Reader "));
      Serial.print(reader);
      Serial.println(F(": FAILED after 5 attempts."));
      readerInitialized[reader] = false;
    }
    delay(50);
  }
  
  Serial.print(F("Initialized "));
  Serial.print(initializedReadersCount);
  Serial.print(F(" / "));
  Serial.print(NR_OF_READERS);
  Serial.println(F(" readers."));
  
  updateDisplay();

  delay(100);
}

void loop() {
  // Фиксированная задержка между полными циклами сканирования.
  // Обратите внимание: эта задержка замедляет опрос считывателей.
  delay(1000);

  // Сбрасываем состояние головоломки для каждой итерации
  InitializePuzzleState();

  // Сканирование всех считывателей
  for (uint8_t reader_idx = 0; reader_idx < NR_OF_READERS; reader_idx++) {

    // Проверка связи со считывателем в каждом цикле
    byte version = mfrc522[reader_idx].PCD_ReadRegister(MFRC522::VersionReg);
    if (version != 0x92) {
      Serial.print(":ERR Version: on id: ");
      Serial.print(reader_idx);
      Serial.print("-> ");
      Serial.println(version);
      readerInitialized[reader_idx] = false;
    } else {
      readerInitialized[reader_idx] = true;
    }

    // Включаем антенну только для текущего считывателя
    mfrc522[reader_idx].PCD_AntennaOn();
    delay(30); // Короткая пауза для стабилизации поля

    // Сразу проверяем наличие карты и читаем её UID
    if (mfrc522[reader_idx].PICC_IsNewCardPresent() && mfrc522[reader_idx].PICC_ReadCardSerial()) {
      readerHasCard[reader_idx] = true;
      Serial.print("Card on Reader ");
      Serial.print(reader_idx);
      Serial.print(F(": UID:"));
      dump_byte_array(mfrc522[reader_idx].uid.uidByte, mfrc522[reader_idx].uid.size);
      Serial.println();

      bool uidMatch = true;
      for (int i = 0; i < mfrc522[reader_idx].uid.size; i++) {
        if (mfrc522[reader_idx].uid.uidByte[i] != tagarray[reader_idx][i]) {
            uidMatch = false;
            break;
          }
      }

      if (uidMatch) {
        readerHasCorrectCard[reader_idx] = true;
      } else {
        Serial.println("Unknown Tag on Reader " + String(reader_idx));
      }

      mfrc522[reader_idx].PICC_HaltA();
      mfrc522[reader_idx].PCD_StopCrypto1();
    }

    // Выключаем антенну, чтобы она не мешала другим считывателям
    mfrc522[reader_idx].PCD_AntennaOff();
    }

  // Агрегация данных после сканирования всех считывателей
  for (uint8_t i = 0; i < NR_OF_READERS; i++) {
    if (readerHasCard[i]) {
      currentTotalCardsPresent++;
    }
    if (readerHasCorrectCard[i]) {
      currentTotalCorrectCards++;
    }
  }

  // Обновляем флаг puzzleSolved
  puzzleSolved = (currentTotalCorrectCards == NR_OF_READERS);

  // Логика управления единственным реле (ACCESS_RELAY_PIN)
  // Согласно схеме и желаемой логике:
  // ACCESS_RELAY_PIN HIGH (реле ВКЛ) -> COM на NO -> led-open (зеленый) горит (ДВЕРЬ РАЗБЛОКИРОВАНА)
  // ACCESS_RELAY_PIN LOW (реле ВЫКЛ) -> COM на NC -> lock-magnet (красный) горит (ДВЕРЬ ЗАБЛОКИРОВАНА)
  if (puzzleSolved) {
    // Если головоломка решена, ДВЕРЬ РАЗБЛОКИРОВАНА (зеленый LED ON)
    digitalWrite(ACCESS_RELAY_PIN, HIGH); // Реле ВКЛ -> РАЗБЛОКИРОВАНО
    Serial.println("Welcome! All tags correct. Door is now UNLOCKED.");
  } else {
    // Если головоломка НЕ решена, ДВЕРЬ ЗАБЛОКИРОВАНА (красный LED ON)
    digitalWrite(ACCESS_RELAY_PIN, LOW); // Реле ВЫКЛ -> ЗАБЛОКИРОВАНО
    Serial.println("System needs " + String(NR_OF_READERS - currentTotalCorrectCards) + " more correct cards. Door is LOCKED.");
  }

  Serial.print("Cards Present: ");
  Serial.print(currentTotalCardsPresent);
  Serial.print(" Cards Correct: ");
  Serial.println(currentTotalCorrectCards);

  updateDisplay(); // Обновление дисплея
}

and now I received the following, different codes but 1 and the same request

MFRC522 Access Control Initialize.
Puzzle state reset (card data cleared).
Reader 0: Attempt 1 failed (Code 234). Retrying... 
Reader 0: Attempt 2 failed (Code 162). Retrying... 
Reader 0: Attempt 3 failed (Code 226). Retrying... 
Reader 0: Attempt 4 failed (Code 130). Retrying... 
Reader 0: Attempt 5 failed (Code 130). Retrying... 
Reader : FAILED after 5 attempts.
Reader 1: Attempt 1 failed (Code 238). Retrying... 
Reader 1: Attempt 2 failed (Code 130). Retrying... 
Reader 1: Attempt 3 failed (Code 130). Retrying... 
Reader 1: Attempt 4 failed (Code 128). Retrying... 
Reader 1: Attempt 5 failed (Code 130). Retrying... 
Reader 1: FAILED after 5 attempts.
Reader 2: Attempt 1 failed (Code 128). Retrying... 
Reader 2: Attempt 2 failed (Code 138). Retrying... 
Reader 2: Attempt 3 failed (Code 128). Retrying... 
Reader 2: Attempt 4 failed (Code 138). Retrying... 
Reader 2: Attempt 5 failed (Code 238). Retrying...

Are you actually using an Arduino Uno and RC522 readers exactly as you show in the diagram?

Yes, schema true

@antik9421

Contrary to popular belief the I/Os of the RC522 are not 5V tolerant, so you will need voltage shifters/translators on all the signal lines.

The RC522 can draw a lot of current so you need a separate 3.3V power supply for the RFID readers.

Soldering all connections will provide the most reliable hardware set-up

FYI: The woki simulator does not care about voltages and currents so it will work even if you exceed the actual design values

This was discovered when lead-free solder was first introduced, so many years ago. If you cannot use lead based solder, then the wires must be fixed to the circuit board so they cannot be moved. Use RTV or hot-glue or some other way to eliminate movement of the soldered part of the wires.

1 Like

Sorry I did not understand the language in the link. Without a schematic I do not feel I or many others can help you.

If you using a 6 RFID modules, it will needs a 9 SPI wires rather than 6 - Miso, Mosi, Sck and 6 x CS

@antik9421
To be warned that a generally bad idea to use more than one .ino file in the project because it is difficult to predict how the IDE will process them. If you need to split a code to the pieces - the better way is using a standard C++ approach with .h and .cpp pairs.