-
Notifications
You must be signed in to change notification settings - Fork 31
Description
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 / ");
//Print value in HEX
uint8_t bytes = (rawBits+7)/8;
for (int i=0; i<bytes; i++) {
Serial.print(rawData[i] >> 4, 16);
Serial.print(rawData[i] & 0xF, 16);
}
Serial.println();
}
``
Thanks