Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino icon indicating copy to clipboard operation
Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino copied to clipboard

Support for multiple instances of WiegandNG?

Open NamoDev opened this issue 4 years ago • 7 comments

Hello,

I recently tried this library out and would say it's perhaps one of the nicest I've seen. Works perfectly with most types of readers, including HID iCLASS SE readers :)

Right now I could handle one Wiegand device on a single Arduino just fine. However, I would like to be able to handle two independent readers on the same Arduino (in this case, an Arduino Nano Every with interrupt support on all pins) and it seems that I have ran into a little snag.

If I modify the example code to be:

WiegandNG wg;
WiegandNG wg2;

// PrintBinary() function removed from this snippet to simplify things (no changes have been made to it)

void setup() {
    Serial.begin(115200);

    unsigned int wiegandbits = 48;
    unsigned int packetGap = 15; // 25 ms between packet

    if (!wg.begin(14, 15, wiegandbits, packetGap)) {
        Serial.println("WG Out of memory!");
    }

    if (!wg2.begin(17, 18, wiegandbits, packetGap)) {
        Serial.println("WG2 Out of memory!");
    }

    Serial.println("Ready...");
}

void loop() {
    if (wg.available()) {
        wg.pause();
        Serial.print("WG Bits=");
        Serial.println(wg.getBitCounted());
        Serial.print("RAW Binary=");
        PrintBinary(wg);
        wg.clear();
    }

    if (wg2.available()) {
        wg2.pause();
        Serial.print("WG2 Bits=");
        Serial.println(wg2.getBitCounted());
        Serial.print("RAW Binary=");
        PrintBinary(wg2);
        wg2.clear();
    }
}

It seems that the Arduino would not be able to correctly indicate from which instance a read has occured (with a read from the same keypad, sometimes it'd say it's from wg, sometimes it'd say it's from wg2). Is this a problem with the library, or am I instantiating it incorrectly in this case?

Thank you!

NamoDev avatar Oct 16 '20 03:10 NamoDev

Can you please try the following tests one by one

Test 1

wg ---> reader 1 connect to 14, 15

Test 2

wg2 ---> reader 2 connect to 17,18

Test 3

wg ---> reader 1 connect to 14, 15 wg2 ---> reader 2 connect to 17,18 Only scan at reader 1 all the time

Test 4

wg ---> reader 1 connect to 14, 15 wg2 ---> reader 2 connect to 17,18 Only scan at reader 2 all the time

jpliew avatar Oct 16 '20 05:10 jpliew

let me know the result, I might need rewrite the code.

jpliew avatar Oct 16 '20 05:10 jpliew

@jpliew Here are the results:

Test 1

Only reader 1 connected to pins 14/15 Reader 1 is a cheap 26-bit reader bought off Amazon

Ready...
WG2 Bits=26
RAW Binary=10111000100011111101100101

WG Bits=26
RAW Binary=10111000100011111101100101

WG2 Bits=26
RAW Binary=10111000100011111101100101

WG Bits=26
RAW Binary=10111000100011111101100101

Test 2

Only reader 2 connected to pins 17/18 Reader 2 is a HID iCLASS SE RK40 reader (Wiegand with keypad)

WG2 Bits=32
RAW Binary=01111010000110100100011100000100

WG Bits=32
RAW Binary=01111010000110100100011100000100

WG2 Bits=4
RAW Binary=0101

WG2 Bits=4
RAW Binary=1000

Test 3

Both readers connected, only reader 1 is scanned all the time

WG2 Bits=26
RAW Binary=01000111011100000010011010

WG Bits=26
RAW Binary=01000111011100000010011010

WG Bits=26
RAW Binary=01000111011100000010011010

WG Bits=26
RAW Binary=01000111011100000010011010

Test 4

Both readers connected, only reader 2 is scanned all the time

WG2 Bits=32
RAW Binary=01111010000110100100011100000100

WG Bits=32
RAW Binary=01111010000110100100011100000100

WG2 Bits=32
RAW Binary=01111010000110100100011100000100

WG2 Bits=32
RAW Binary=01111010000110100100011100000100

NamoDev avatar Oct 16 '20 06:10 NamoDev

Ok, I will work on a fix. I think this is a bug.

jpliew avatar Oct 16 '20 09:10 jpliew

hi, thx for your great work, is it possible to use 3 readers in Arduino uno now?

rassaifred avatar Dec 12 '20 11:12 rassaifred

@rassaifred not yet. Arduino attachInterrupt is preventing the whole the ISR in the object. There are many discussion about this for other library. I need to workout a better way to handle this.

https://www.google.com/search?client=firefox-b-d&q=arduino+attachinterrupt+in+class

jpliew avatar Dec 12 '20 21:12 jpliew

@NamoDev @rassaifred multiple instances support https://github.com/jpliew/Multi-Reader-Wiegand-Protocol-Library-for-Arduino

jpliew avatar Mar 07 '21 03:03 jpliew