Git Product home page Git Product logo

Comments (3)

PauMAVA avatar PauMAVA commented on May 25, 2024

@mattjlewis Any idea why is this happening?

from diozero.

PauMAVA avatar PauMAVA commented on May 25, 2024

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);
}

from diozero.

mattjlewis avatar mattjlewis commented on May 25, 2024

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.

from diozero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.