Closed PauMAVA closed 4 years ago
@mattjlewis Any idea why is this happening?
It seems that a bad cable was causing the issue.
The code I ended up using is:
private void listen() {
log("Started listening for RFID cards...");
try (MFRC522 mfrc522 = new MFRC522(0, 0, 22)) {
while (listen) {
rfidLoop(mfrc522);
SleepUtil.sleepSeconds(1);
}
}
}
private void rfidLoop(MFRC522 rfid) {
if (!rfid.isNewCardPresent()) {
log("No card found.");
return;
}
log("Card found!");
UID uid = rfid.readCardSerial();
if (uid == null) {
log("Failed to read UID");
return;
} else {
log("Read UID: " + ConversionTools.bytesToHex(uid.getUidBytes()) + "of type " + uid.getType().getName());
}
rfid.haltA();
rfid.stopCrypto1();
}
static void log(String message) {
MainClass.log(MainClass.ANSI_YELLOW + "RFID Sensor >> " + MainClass.ANSI_RESET + message);
}
Excellent, good to know. The MFRC522 code is pretty complex - I ported Arduino code to Java and TBH I've not tested it that much. I've also experienced a bad cable - I was pulling my hair out tying to work out why something wasn't working that had been working.
Hello!
I am trying to use an RFID MFRC522 module on a Raspberry PI 3B+. Once having enabled the SPI interface on the board, I am trying to use the following code in order to read the UID of a card (it is almost as the example one):
The thing is that a UID is never read and the only output I get is:
Timed out waiting for interrupt
. Here you have an extract of the console:I have already checked the following:
The SPI interface is enabled on
/boot/config.txt
Have checked the wiring: (https://es.pinout.xyz/#):
Tried using chip select 0 instead of 1.
Tried passing 25 instead of 22 for the reset pin parameter. (Tried this for both chip selects).
Here you also have the output of some related commands for reference:
The version I am using for diozero is: 0.11 and for Pi4J is: 1.1. I can't find where is the problem. Is even my program being able to communicate with the sensor?
Any help is really appreciated.