Skip to content
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

Connect two readers to one controller #51

Open
AuspeXeu opened this issue Nov 18, 2020 · 14 comments
Open

Connect two readers to one controller #51

AuspeXeu opened this issue Nov 18, 2020 · 14 comments

Comments

@AuspeXeu
Copy link

AuspeXeu commented Nov 18, 2020

Was just wondering whether it would be possible to monitor two readers with the same controller. I tried the following code but it only logs reads from Wiegand1.

#include <Wiegand.h>

WIEGAND wg1;
WIEGAND wg2;

const int pinD01 = 2;
const int pinD11 = 3;
const int pinD02 = 18;
const int pinD12 = 19;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  wg1.begin(pinD01, pinD11);
  wg2.begin(pinD02, pinD12);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(wg1.available()) {
    Serial.print("Wiegand1 HEX = ");
    Serial.print(wg1.getCode(),HEX);
    Serial.print(", DECIMAL = ");
    Serial.print(wg1.getCode());
    Serial.print(", Type W");
    Serial.println(wg1.getWiegandType());    
  }
  if(wg2.available()) {
    Serial.print("Wiegand2 HEX = ");
    Serial.print(wg2.getCode(),HEX);
    Serial.print(", DECIMAL = ");
    Serial.print(wg2.getCode());
    Serial.print(", Type W");
    Serial.println(wg2.getWiegandType());    
  }
}
@jpliew
Copy link
Collaborator

jpliew commented Nov 18, 2020

This will not work as the library was not written to cater for multiple wiegand. I will put this in a feature request and work on it when free.

@AuspeXeu
Copy link
Author

C++ is not my daily driver so I am not super aware of how it works but what changes would be necessary for this to work? It's not like in OOP and another Wiegand object is instantiated and that's it?

@jpliew
Copy link
Collaborator

jpliew commented Nov 19, 2020

There are two things that needed to be done.

  1. Move all the variables into proper C++ class

  2. When I first wrote this, it was meant for UNO, and UNO has only two interrupts. In order to support multiple interrupts, we need to use pin change interrupts.

@AuspeXeu
Copy link
Author

I just looked into the code it appears to me that it's already a C++ class, no?

@AuspeXeu
Copy link
Author

I can confirm my code from the first post in this issue works with two readers connected to an Arduino Mega.

@jpliew
Copy link
Collaborator

jpliew commented Nov 21, 2020

Because the variables were designed for only 1 reader in the global, it will not completely work for 2 readers. In your case it worked because you swiped the cards one by one.

I am going to leave this issue open so that others can see and also I try to allocate time to work on this.

@jpliew jpliew reopened this Nov 21, 2020
@jpliew
Copy link
Collaborator

jpliew commented Nov 21, 2020

The other thing, I am not sure how it worked on your test when you were using pin10 and pin11 for the second reader. Pin10 & 11 are not interrupt supported.

@AuspeXeu
Copy link
Author

Fixed the code. I actually used different pins.

@jpliew
Copy link
Collaborator

jpliew commented Nov 23, 2020

Try scan two readers at the same time, you will get wrong values.

@AuspeXeu
Copy link
Author

I can confirm that yes.

@AuspeXeu
Copy link
Author

AuspeXeu commented Feb 3, 2021

@jpliew did you have a chance to look into this? :)

@jpliew
Copy link
Collaborator

jpliew commented Feb 15, 2021

@AuspeXeu sorry for the slow reply. I was stuck with work commitments. Please take a look at this and see if you can get it working

https://github.com/jpliew/Multi-Reader-Wiegand-Protocol-Library-for-Arduino

@AuspeXeu
Copy link
Author

I'll give it a shot an report back :)

@AuspeXeu
Copy link
Author

Works like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants