[SOLVED] How to send a signal for a set amount of time ?
Posted: Tue Dec 10, 2019 10:31 am
Hello !
I am trying to emulate a 26-Bit Wiegand Protocol data transfer. I am basically trying to send a card information through the two data wires, W0 and W1, from the ESP32 to a station card reader to emulate a card being read.
I have hooked up a card reader that acts a station to an ESP32-EVB:
Note: I do not know if "station" is the right word for it, but this particular card reader can act as a Standalone Card Reader or as a Central for other card readers. One device will act as a card reader, sending the data about the card that has been read to a second device that acts as a station/central/system and determines if the card has access or not.
Using a Wiegand Calculator and a decimal number from a real access card ( 12679548 ), we obtain the 26-Bit binary number ( 01100000101111001011111000 ) that has to be sent to the W0 and W1 data wires.
Reading from here we find out that between the sent bits there has to be a delay, that's in the vicinity of 100uS (microseconds) and that between card IDs there has to be a pause of 20-100ms (milliseconds).
I have put the card reader device in Station mode and the wires are set as W0 and W1 inputs.
From my point of view the code is good and should be working but it's not. The only piece of code that has me worried is the part that actually puts the pins to LOW then waits then puts them to HIGH again. I am not sure if this is the proper way to send a signal with a set PulseWidth.
What do you think ?
I am trying to emulate a 26-Bit Wiegand Protocol data transfer. I am basically trying to send a card information through the two data wires, W0 and W1, from the ESP32 to a station card reader to emulate a card being read.
I have hooked up a card reader that acts a station to an ESP32-EVB:
- GPIO13 is W0;
- GPIO17 is W1.
Note: I do not know if "station" is the right word for it, but this particular card reader can act as a Standalone Card Reader or as a Central for other card readers. One device will act as a card reader, sending the data about the card that has been read to a second device that acts as a station/central/system and determines if the card has access or not.
Using a Wiegand Calculator and a decimal number from a real access card ( 12679548 ), we obtain the 26-Bit binary number ( 01100000101111001011111000 ) that has to be sent to the W0 and W1 data wires.
Reading from here we find out that between the sent bits there has to be a delay, that's in the vicinity of 100uS (microseconds) and that between card IDs there has to be a pause of 20-100ms (milliseconds).
Code: Select all
#define W0 13
#define W1 17
change = false;
void setup() {
Serial.begin(115200);
pinMode(W0, OUTPUT);
pinMode(W1, OUTPUT);
digitalWrite(W0, HIGH);
digitalWrite(W1, HIGH);
// decimal number 12679548 transforms into Wiegand 26-Bit binary number: 01100000101111001011111000
// store the binary number into 'bool* wiegandArray = new bool[26];'
// if a new card ID has come then change = true;
int pulseWidth = 90;
}
void loop() {
if(change) {
for(int i = 0; i<26; i++) {
if(wiegandArray[i] == 0) {
digitalWrite(W0, LOW);
delayMicroseconds(pulseWidth);
digitalWrite(W0, HIGH);
} else {
digitalWrite(W1, LOW);
delayMicroseconds(pulseWidth);
digitalWrite(W1, HIGH);
}
}
}
}
From my point of view the code is good and should be working but it's not. The only piece of code that has me worried is the part that actually puts the pins to LOW then waits then puts them to HIGH again. I am not sure if this is the proper way to send a signal with a set PulseWidth.
What do you think ?