OS: Linux Mint
Hello !
For the past week, I have been trying to send this binary number: 01100000101111001011111000 through two wires, emulating the Wiegand Protocol, to a Card Reader.
Wiegand Protocol starts with both pins HIGH. When I send a 0, W0 pin is pulled LOW for usually 20-100us and W1 stays HIGH. When a 1 is being sent W1 is pulled LOW for usually 20-100us and W0 stays HIGH.
I have been able to send that number by doing this:
Code: Select all
void setup() {
Serial.begin(115200);
pinMode(W0, OUTPUT);
pinMode(W1, OUTPUT);
digitalWrite(W0, HIGH);
digitalWrite(W1, HIGH);
// ...
}
void loop() {
delay(100);
if(change) {
Serial.println("Sending ID...");
pulse = pulseWidth.toInt();
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
portENTER_CRITICAL(&mux);
for(int i = 0; i<26; i++) {
if(wiegandArray[i] == 0) {
digitalWrite(W0, LOW);
delayMicroseconds(pulse);
digitalWrite(W0, HIGH);
} else {
digitalWrite(W1, LOW);
delayMicroseconds(pulse);
digitalWrite(W1, HIGH);
}
delayMicroseconds(pulse);
}
portEXIT_CRITICAL(&mux);
}
if(change) {
change = false;
for(int i = 0; i<26; i++) {
Serial.print(wiegandArray[i]);
}
Serial.println();
}
}
I've then tried implementing it in a task:
Code: Select all
void taskOne(void * parameter ) {
for( ; ; ) {
if(change) {
int pulse = pulseWidth.toInt();
vTaskSuspendAll();
for(int i = 0; i<26; i++) {
if(wiegandArray[i] == 0) {
digitalWrite(W0, LOW);
delayMicroseconds(pulse);
digitalWrite(W0, HIGH);
} else {
digitalWrite(W1, LOW);
delayMicroseconds(pulse);
digitalWrite(W1, HIGH);
}
delayMicroseconds(pulse);
}
xTaskResumeAll();
if(change) {
change = false;
for(int i = 0; i<26; i++) {
Serial.print(wiegandArray[i]);
}
Serial.println();
}
uxTaskGetStackHighWaterMark(NULL);
} // if(change)
} // for( ; ; )
}
void setup() {
xTaskCreate(
taskOne, /* Task function. */
"TaskOne", /* String with name of task. */
10000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL); /* Task handle. */
}
void loop() {
delay(100);
}
Now, I am being told to try the RMT driver, that can only send one signal through one pin at a time, but I need one signal through two pins, which can apparently be done by doing this:
But, I have no idea how to use transistors. Will I have to split the signal by 0 and 1 in code or from hardware ? How is the split happening ?If you need to split the signal on the output you can do that via NPN/PNP transistors to create an inverse signal or direct the output to two outputs based on the high/low state of the single output.
I want to send 01100000101111001011111000. Do I send it all at once with a little pause between each one of the bits and the transistor will split the signal and send the zeros (0) to a pin, the ones (1) to the other pin and hope that they will be synchronized ? Because I can't have 0 and 1 sent at the same time.
Can I get some help in understanding how this works and how can I implement it ?
Thank you.