-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trouble reading 2 Wiegand Instances in one Code #20
Comments
Hey @mxf14 I've also encountered something similar to this. I've plugged two HID readers (an iClass and a Prox) into an Arduino Uno and set it to use polling. For example, this is it reading the same 35 bit card with two readers attached:
However the prox reader seems to always return the right value, even when both readers are attached.
This is the sketch.
Changing which pins are for which reader (and running I'm going to do a test of setting on up via interrupt, and one polling, to see if that works differently. |
This worked, I reliably got both readers working when I put 1 (the iClass) into interrupt mode and the other into polling. I don't know enough about Arduino hardware, but a theory I have is that it's something to do with the speed of Possibly even the iClass reader I have is slightly slower at transmitting data? |
Hi Guys,
I implemented 2 wiegand card readers on 1 arduino. I use polling for both.
The issue I face is that if both wiegand instances are polling, then I get message length errors on both and I am not able to read the card IDs.
If I comment out one or the other polling functions it works for 1 of the readers.
Any ideas?
Here is the code (with wiegand1 instance polling disabled, so wiegand0 instance works):
``
#include <Wiegand.h>
#define PIN_WIEG0_D0 2
#define PIN_WIEG0_D1 3
#define PIN_WIEG1_D0 10
#define PIN_WIEG1_D1 11
Wiegand wiegand0;
Wiegand wiegand1;
void setup() {
Serial.begin(115200);
//Install listeners and initialize Wiegand reader
wiegand0.onReceive(receivedData, "Card 0 read: ");
wiegand0.onReceiveError(receivedDataError, "Card 0 read error: ");
wiegand0.onStateChange(stateChanged, "Card 0 State changed: ");
wiegand0.begin(26, true);
wiegand1.onReceive(receivedData, "Card 1 read: ");
wiegand1.onReceiveError(receivedDataError, "Card 1 read error: ");
wiegand1.onStateChange(stateChanged, "Card 1 State changed: ");
wiegand1.begin(26, true);
//initialize pins as INPUT
pinMode(PIN_WIEG0_D0, INPUT);
pinMode(PIN_WIEG0_D1, INPUT);
pinMode(PIN_WIEG1_D0, INPUT);
pinMode(PIN_WIEG1_D1, INPUT);
}
void loop() {
pollRfidReaders();
}
/************** Wiegand Handlers ****************/
void pollRfidReaders(){
// Checks for pending messages
wiegand0.flush();
wiegand1.flush();
// Check for changes on the the wiegand input pins
wiegand0.setPin0State(digitalRead(PIN_WIEG0_D0));
wiegand0.setPin1State(digitalRead(PIN_WIEG0_D1));
//wiegand1.setPin0State(digitalRead(PIN_WIEG1_D0));
//wiegand1.setPin1State(digitalRead(PIN_WIEG1_D1));
}
void stateChanged(bool plugged, const char* message) {
Serial.print(message);
Serial.println(plugged ? "CONNECTED" : "DISCONNECTED");
}
void receivedData(uint8_t* data, uint8_t bits, const char* message) {
Serial.print(message);
Serial.print(bits);
Serial.print("bits / ");
//Print value in HEX
uint8_t bytes = (bits+7)/8;
for (int i=0; i<bytes; i++) {
Serial.print(data[i] >> 4, 16);
Serial.print(data[i] & 0xF, 16);
}
Serial.println();
for (int i=0; i<3; i++) lastRxData[i] = data[i];
newRxRfid = true;
}
void receivedDataError(Wiegand::DataError error, uint8_t* rawData, uint8_t rawBits, const char* message) {
Serial.print(message);
Serial.print(Wiegand::DataErrorStr(error));
Serial.print(" - Raw data: ");
Serial.print(rawBits);
Serial.print("bits / ");
}
``
Thanks
The text was updated successfully, but these errors were encountered: