Xinyuan-LilyGO / TTGO-T-Display

MIT License
1.02k stars 335 forks source link

Connecting External SPI Device RC522 #91

Closed khumprp closed 2 years ago

khumprp commented 2 years ago

Hello

I'm trying to get the RC522 RFID reader to work with TDISPLAY. I have it working with other ESP32 devices.

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.

Code below

`

include

include

include // 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));

} `

khumprp commented 2 years ago

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