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

Unable to use 2 readers on Arduino Zero #13

Open
zackjd opened this issue Jan 10, 2024 · 0 comments
Open

Unable to use 2 readers on Arduino Zero #13

zackjd opened this issue Jan 10, 2024 · 0 comments

Comments

@zackjd
Copy link

zackjd commented Jan 10, 2024

Can't use 2 readers with example code.

One reader works fine, but when trying to use 2 readers only one of them will print any output.

Attempted with modified advanced example because pin 4 can't be used as an interrupt.

`/*
Advanced HidProxWiegand usage example.
*/

#include <Arduino.h>
#include "HidProxWiegand.h"

#define PIN_RDR1_DATA0 2 // The pin to use for reader 1, DATA 0.
#define PIN_RDR1_DATA1 3 // The pin to use for reader 1, DATA 1.
#define PIN_RDR2_DATA0 5 // The pin to use for reader 2, DATA 0.
#define PIN_RDR2_DATA1 6 // The pin to use for reader 2, DATA 1.

// Reader 1 outputs.
//#define PIN_RDR1_BUZZER 6
//#define PIN_RDR1_GREEN_LED 7
//#define PIN_RDR1_RED_LED 8

//Reader 2 outputs.
//#define PIN_RDR2_BUZZER 9
//#define PIN_RDR2_GREEN_LED 10
//#define PIN_RDR2_RED_LED 11

ProxReaderInfo* reader1; // Card reader 1.
ProxReaderInfo* reader2; // Card reader 2.

// Callback for handling card reads from reader 1.
void cardRead1Handler(ProxReaderInfo* reader) {
Serial.print(F("Card read: "));
Serial.print(reader->facilityCode);
Serial.print(F(":"));
Serial.println(reader->cardCode);

 // Here you can add logic to see if the card that was read was actually
 // valid or whatever. For example: reading stored card numbers from EEPROM
 // and looking for a match. Ideal for access control applications.
 //
 // This would also be where you would want to change state of the buzzer
 // and LEDs on the reader.
 //digitalWrite(PIN_RDR1_BUZZER, HIGH);
 //digitalWrite(PIN_RDR1_RED_LED, LOW);
 //digitalWrite(PIN_RDR1_GREEN_LED, HIGH);
 //delay(500);
 //digitalWrite(PIN_RDR1_BUZZER, LOW);
 //digitalWrite(PIN_RDR1_GREEN_LED, LOW);
 //digitalWrite(PIN_RDR1_RED_LED, HIGH);

}

void cardRead2Handler(ProxReaderInfo* reader) {
Serial.print(F("Card read: "));
Serial.print(reader->facilityCode);
Serial.print(F(":"));
Serial.println(reader->cardCode);

 //digitalWrite(PIN_RDR2_BUZZER, HIGH);
 //digitalWrite(PIN_RDR2_RED_LED, LOW);
 //digitalWrite(PIN_RDR2_GREEN_LED, HIGH);
 //delay(500);
 //digitalWrite(PIN_RDR2_BUZZER, LOW);
 //digitalWrite(PIN_RDR2_GREEN_LED, LOW);
 //digitalWrite(PIN_RDR2_RED_LED, HIGH);

}

// Handle interrupt for reader 1, DATA 0.
void handleInterrupt0() {
if (reader1 != NULL) {
reader1->ISR_Data0();
}
}

// Handle interrupt for reader 1, DATA 1.
void handleInterrupt1() {
if (reader1 != NULL) {
reader1->ISR_Data1();
}
}

// Handle interrupt for reader 2, DATA 0.
void handleInterrupt2() {
if (reader2 != NULL) {
reader2->ISR_Data0();
}
}

// Handle interrupt for reader 2, DATA 1.
void handleInterrupt3() {
if (reader2 != NULL) {
reader2->ISR_Data1();
}
}

void setup() {
Serial.begin(9600);
while (!Serial) {
delay(10);
}

 // Create the readers and attach them to the system.
 reader1 = HidProxWiegand.addReader(PIN_RDR1_DATA0, PIN_RDR1_DATA1, cardRead1Handler);
 reader2 = HidProxWiegand.addReader(PIN_RDR2_DATA0, PIN_RDR2_DATA1, cardRead2Handler);

 // Attach interrupt handlers for readers 1 and 2.
 HidProxWiegand_AttachReaderInterrupts(PIN_RDR1_DATA0, PIN_RDR1_DATA1, handleInterrupt0, handleInterrupt1);
 HidProxWiegand_AttachReaderInterrupts(PIN_RDR2_DATA0, PIN_RDR2_DATA1, handleInterrupt2, handleInterrupt3);

 // Init reader 1 outputs.
 //pinMode(PIN_RDR1_BUZZER, OUTPUT);
 //digitalWrite(PIN_RDR1_BUZZER, LOW);
 //pinMode(PIN_RDR1_GREEN_LED, OUTPUT);
 //digitalWrite(PIN_RDR1_GREEN_LED, LOW);
 //pinMode(PIN_RDR1_RED_LED, OUTPUT);
 //digitalWrite(PIN_RDR1_RED_LED, HIGH);

 // Init reader 2 outputs.
 //pinMode(PIN_RDR2_BUZZER, OUTPUT);
 //digitalWrite(PIN_RDR2_BUZZER, LOW);
 //pinMode(PIN_RDR2_GREEN_LED, OUTPUT);
 //digitalWrite(PIN_RDR2_GREEN_LED, LOW);
 //pinMode(PIN_RDR2_RED_LED, OUTPUT);
 //digitalWrite(PIN_RDR2_RED_LED, HIGH);

}

void loop() {
// Process any cards that have been read.
HidProxWiegand.loop();
}`

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

No branches or pull requests

1 participant