Just meanwhile I was writing this post I found the solution. Actually there was nothing to find the code was giving me the serial card number backwards.
This is a bit like saying "I have my Arduino connected to a servo via Spanish." It doesn't make sense, and tells us nothing about the reader, the wiring, the software, or the cards.
Obviously I don't express myself properly. Sorry about that. I have this reader (http://www.aliexpress.com/snapshot/214317754.html) connected to an arduino Mega. Wiring: DATA0 Pin 2, DATA1 Pin 3.
This is the code (GitHub - johannrichard/SeeedRFIDLib: Arduino RFID Tool for SeedStudio's (and possibly other) RFID Readers with both an UART and Wiegand Interface implementation.):
#include <Wiegand.h>
WIEGAND wg;
void setup() {
Serial.begin(9600);
wg.begin();
}
void loop() {
if(wg.available())
{
Serial.print("Wiegand BIN = ");
Serial.print(wg.getCode(),BIN);
Serial.print(", Wiegand HEX = ");
Serial.print(wg.getCode(),HEX);
Serial.print(", DECIMAL = ");
Serial.print(wg.getCode());
Serial.print(", Type W");
Serial.println(wg.getWiegandType());
}
}
Response:
Wiegand BIN = 10010011101110000111010100001010, Wiegand HEX = 93B8750A, DECIMAL = 2478339338, Type W34
And this reader (http://www.ebay.co.uk/itm/200868439895?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649) connected to an arduino Uno.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //pin2 Rx, pin3 Tx
int CMD[64];
int comlen =0;
int out_flag =0;
void setup()
{
Serial.begin(9600);
mySerial.listen();
Serial.println("Serial number will be displayed here if a card is detected by the module:\n");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
delay(10);
mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
}
void loop() // run over and over
{
while (Serial.available())
{
int a = SerialReadHexDigit();
if(a>=0){
CMD[comlen] = a;
comlen++;
}
delay(10);
}
for(int i=0; i<comlen; i+=2){
int c = mySerial.write( CMD[i]*16 + CMD[i+1]);
Serial.print(c);
}
comlen =0;
while (mySerial.available()) {
byte C = mySerial.read();
if (C<16) Serial.print("0");
Serial.print(C ,HEX); //Display the Serial Number in HEX
Serial.print(" ");
out_flag =1;
}
if (out_flag >0) {
Serial.println();
out_flag = 0;
}
}
int SerialReadHexDigit()
{
byte c = (byte) Serial.read();
if (c >= '0' && c <= '9') {
return c - '0';
} else if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
} else if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
} else {
return -1; // getting here is bad: it means the character was invalid
}
}
Response: 0A 75 B8 93
Thanks for your reply. Hope that helps someone.