Hello everyone,
I work on a new project using Arduino Uno and Chafon RFID reader CF-RU5106 connected over RS232 with TTL converter. I need your help in coding, because the received data from reader is not same with the code from the tag.
Here is my code:
void loop() {
if (startup == 1 && millis() >= 30000) {
LastTag = "000A000B000C000D000E000F";
startup = 0;
}
if (digitalRead(IR) == "LOW") { //NOT IN USE
index = 2;
lastIR = millis();
}
if ((millis() - LedTimer) >= 2000) {
digitalWrite(flashLed, LOW);
LedTimer = millis();
delay(10);
}
if (index == 0 and (digitalRead(btn1) == 0 || digitalRead(btn2) == 0)) {//if request to resend again with diferent index
index = 1;
Serial.print("Re-send requested: ");
Serial.println(SentTag);
storeTag(SentTag, index);
//LastTag = SentTag;
for (int i = 0; i < 6; i++) {
digitalWrite(flashLed, HIGH);
Serial.println("Back LED is ON");
delay(350);
digitalWrite(flashLed, LOW);
Serial.println("Back LED is OFF");
delay(350);
}
} else {
if ((millis() - lastReq) > timeBtwRqst ) {
digitalWrite(RL, LOW);
delay(500);
digitalWrite(RL, HIGH);
lastReq = millis();
delay(500);
}
if (storedTags == 15) {//if stored tags buffer is full
digitalWrite(flashLed, HIGH);
Serial.println("Back LED is ON");
delay(1000);
digitalWrite(flashLed, LOW);
Serial.println("Back LED is OFF");
} else {//If stored tags buffer is under 15
while (Reader.available() > 0) {
digitalWrite(flashLed, HIGH);
rxdata = Reader.read();
Serial.print(String(rxdata));
switch (rxstate)
{
case 0: //get head
if (String(rxdata) == ("0x02"), HEX) {
rxstate = 1;
strTagID = "";
bReadLength = 0;
}
break;
case 1: //Get TagID
if (String(rxdata, HEX) != ("0x03"), HEX) //Not End
{
if (CheckIsHexChar(rxdata) == 1) { //check legal char
strTagID = strTagID + char (rxdata);
Serial.println(strTagID);
bReadLength++;
if (bReadLength == 24) {
if (storedTags >= 0 || storedTags < 15) {
}
if (LastTag != strTagID) {
if (SentTag == strTagID && (millis() - lastScan) >= timeBtwScans) {
LastTag = strTagID;
storeTag(strTagID, index);//, time());
} else if (SentTag != strTagID) {
LastTag = strTagID;
storeTag(strTagID, index); //, time());
}
//Serial.println(strTagID);
index = 0;
} else {
Serial.print("Current: ");
Serial.println(strTagID);
index = 0;
}
}
//Serial.println(strTagID);
} else {
strTagID = "";
rxstate = 0;
}
} else {
Serial.println("else");
if ((bReadLength) % 2 == 0) //TagLength(HEX data) is odd
{
if (strTagID != "")
{
Serial.print("TagID: ");
Serial.println(String (strTagID));
}
}
else
{
Serial.print("Unlegal Data\r\n");
}
strTagID = ""; rxstate = 0; bReadLength = 0;
}
break;
}
delay(10);
LedTimer = millis();
}
}
}
//digitalWrite(flashLed, LOW);
}
this code work perfect with CHAFON CF-RU5300
Thanks in advance!
