Hi everybody,
I'm working in last week to connect my ardunio to RFID reader of UHF (for about 1-2 meter). My reader is of skyetec ?.link?.
I have connect the reader to the arduino using the software serial , so I could use the serial.print for debugging (but at the end I might remove it )
The reader is getting command in ascii or binary and then response in the same way.
After some reading I manage to send data ok using mySerial.print(0xAA,BYTE)
(although I notice it send wrong the first one or two, so I send some 00 in the beginning)
but I have some problem with displaying the response.
By using some serial monitor software I know I get back " 02000401C1AD3C"
But when I try to print it out it print different stuff " 2 , 0 , 4 , 81 , E0 , D6 , 9E " and I don't know why. It even not consist and I get different print out .
// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
#define ledPin 13
#define len 7
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
byte val = 0;
byte code[len];
int bytesread = 0,i=0;
boolean start = true;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(ledPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
bytesread = 0;
for (i=0;i<len;i++){
code[i] = 0;
}
if (start){ // call initLoop only in the first loop
initLoopCheck();
start = false;
}
// listen for new serial coming in:
while(bytesread<len) {
// read len digit code
val = mySerial.read();
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
// print out the character:
Serial.print("recive : ");
for (i=0;i<bytesread;i++ ){
Serial.print(code[i],HEX);
Serial.print(" , ");
}
Serial.println();
}
void initLoopCheck() {
Serial.println("in Init");
for (i=0;i<2;i++) {
sendZero();
}
startLoop();
}
void sendZero(){
mySerial.print(0x00,BYTE);
}
void startLoop() {
Serial.println(" in start loop ");
//send 020008002101010000F35E - command for select tag in loop
mySerial.print(0x02,BYTE);
mySerial.print(0x00,BYTE);
mySerial.print(0x08,BYTE);
mySerial.print(0x00,BYTE);
mySerial.print(0x21,BYTE);
mySerial.print(0x01,BYTE);
mySerial.print(0x01,BYTE);
mySerial.print(0x00,BYTE);
mySerial.print(0x00,BYTE);
mySerial.print(0xF3,BYTE);
mySerial.print(0x5E,BYTE);
}
kind regards
Adi