Arduino Mega2560 wiegand26 rfids send data and wg.available not always is true

Hello all,

I am using an arduino mega2560 with 2 wiegand26 RFIDs and “Wiegand-Protocol-Library-for-Arduino-master”
]
Arduino code:

#include <Wiegand.h>

WIEGAND wg;

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

// default Wiegand Pin 2 and Pin 3 see image on README.md
// for non UNO board, use wg.begin(pinD0, pinD1) where pinD0 and pinD1
// are the pins connected to D0 and D1 of wiegand reader respectively.
//wg.begin();
wg.begin(pinD0, pinD1)
}

void loop() {
if(wg.available())
{
Serial.print(“Wiegand HEX = “);
Serial.print(wg.getCode(),HEX);
Serial.print(”, DECIMAL = “);
Serial.print(wg.getCode());
Serial.print(”, Type W”);
Serial.println(wg.getWiegandType());
}
}

The RFID readers on MEGA board are using for first RFID the pin 2 and 3 and for the second RFID the pin 20 and 21.

After reading several time from the first and second RFID the reading process freezes(when i touch a tag on first rfid nothing is being read, the second rfid sometimes read the tag and then if i try with the first one it works again) this strange behaviour of using the second one to unlock the first one i managed to reproduce it several time yesterday.

Sometimes both RFID readers are freezing.

I have checked the Arduino Code again and in the code i have modified to send a repetitive char “a” to test if the serial is freezing when problem appear.

The result showed that the serial was working fine (no freezing) but in the code the problem is that after a while in the void loop() the wg.available return false even if both rfid are connected and the rfid sends over wiegand26 protocol to the arduino.

So, sometimes the wg.available returns false and the if is not executed even if the rfid sends data

I have used and “or” condition with 1 to force an entrance in the IF and the getCode() stays freeze with the last working reading value and not returning a new value.

Conclusion:

Sometimes wg.available stays in false even if the data is send from the rfid to the arduino.
If i restart the board everything works ok for a while and then problem is back.

Who had the same problem?

// for non UNO board, use wg.begin(pinD0, pinD1) where pinD0 and pinD1
// are the pins connected to D0 and D1 of wiegand reader respectively.

This is not a good idea especially as you have

Serial.begin(9600)

The serial port uses pins 0&1, which means the two systems will probably interfere with each other. Try using other pins for your Wigand reader.

Please read the how to use this forum sticky post to learn how to post code correctly here.

Hello Mike,
Thank you for observations!

Unfortunately i have used the wrong code in the post regarding Arduino Mega problem with wiegand26.

The actual code used is below and the pins are used corectly for both RFID readers.
This library is used “Wiegand-Protocol-Library-for-Arduino-MEGA-2560”.

#include <WiegandMega2560.h>

#define FALSE 0			
#define TRUE  1	


WIEGAND wg;

void setup() {
	Serial.begin(9600);  
	wg.begin(TRUE, TRUE, FALSE);  // wg.begin(GateA , GateB, GateC)
}

void loop() {
	if(wg.available())
	{
		Serial.print("Wiegand HEX = ");
		Serial.print(wg.getCode(),HEX);
		Serial.print(", DECIMAL = ");
		Serial.print(wg.getCode());
                Serial.print(", Gate= ");
                Serial.print(wg.getGateActive());
		Serial.print(", Type W");
		Serial.println(wg.getWiegandType());    
	}
}

I have tested today (after i let the board for 24h working) and again i had this problem, sometimes an RFID stays freeze and for that RFID when i try to read a tag the wg.available returns False and if is not executed.

I can’t see how that code you posted addresses two readers?

Can you post a link to the library you are using, and add a schematic showing how you have wired things up.