RC522 RFID SPI on TTGO TDISPLAY

617 views Asked by At

This is going to be pretty specific to this one ESP32 board, TTGO TDISPLAY. I am able to get the RC522 working with other ESP32's.

For reference of SPI pins on this board: https://github.com/Xinyuan-LilyGO/TTGO-T-Display/issues/32

Right now, the RC522 is being recognized and returns the firmware number successfully, but it will not read cards. I have verified it works on other devices.

MISO - 27
MOSI - 26
CLK - 25
CS - 33
RST - 17

I am setting RST to HIGH, as on other ESP32 devices it reads HIGH and works.

I do not know if I'm missing a step (something maybe to disable SPI on the onboard display) or if there's something different about SPI on this board.I'm checking SS for both devices, the OLED is 1 as is the RC522... However, the RC522 is still 1 on the other ESP32 that works...

Not sure if this is different on the TTGO because there are two SPI's going, OLED and RC522. I believe they are both using different SPI busses, HSPI and VSPI. The OLED pinouts are not accessible, so I'm using the other set.

Code below

#include <SPI.h>
#include <MFRC522.h>
#include <TFT_eSPI.h> // Hardware-specific library

#define RST_PIN 17 // Configurable, see typical pin layout above
#define SS_PIN 33 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library

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)

pinMode(RST_PIN, OUTPUT);
digitalWrite(RST_PIN, HIGH);
Serial.println("HELLO");
Serial.println(digitalRead(RST_PIN));
tft.init();

tft.fillScreen(TFT_WHITE);

SPI.begin(25,27,26);            // Init SPI bus CLK, MISO, MOSI
mfrc522.PCD_Init();     // Init MFRC522
delay(4);               // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
}

// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
1

There are 1 answers

1
Pat K. On

Disregard. Turns out I had a bad ground pin. Once I changed to a different ground, it worked fine.

Code above should work for anyone trying to get RC522 working on TTGO TDISPLAY. Just check your connections.