Hi everyone.
Im working with 4 RFID antennas, and im trying to read the ID send by them with SoftwareSerial library (but it's not working).
If i use just 1 Antenna, it works fine with these library, but not with 2 antennas... I try using port.listen(), and the antennas have a separeted transformer 5V 2Amps.
Here's my code if there anyone who could help... i'll appreciated (Hlp pliiiizzz)...
#include <SoftwareSerial.h>
SoftwareSerial SerialUno(10, 11);
SoftwareSerial SerialDos(12, 13);
SoftwareSerial SerialTres(6, 7);
char incomingByte = 0; // for incoming serial data
byte storedCard[6]; // Stores an ID read from EEPROM
byte readCard[6]; // Stores an ID read from the RFID reader
byte checksum = 0; // Stores the checksum to verify the ID
byte bytesread = 0;
byte i = 0;
int val = 0;
byte tempbyte = 0;
char IDstring[13];
//Register your RFID tags here
char tag1[13] = "4300F97F21E4"; //Rodrigo
char tag2[13] = "4300F9C60E72"; //Gabriela
char tag3[13] = "030034E42AF9"; //Borrador
char tag4[13] = "0300346585D7"; //Maestro
//char tag5[13] = "030034DBA448";
int ledRojo = 8;
int ledVerde = 9;
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(10, INPUT);
pinMode(12, INPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
pinMode(ledRojo, OUTPUT); // Initialize LED pin
pinMode(ledVerde, OUTPUT); // Initialize LED pin
}
void loop()
{
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, LOW);
revisarEntrada();
revisarSalida();
//revisarUno();
//revisarDos();
}
void revisarEntrada()
{
SerialUno.begin(9600);
byte val = 0; // Temp variable to hold the current byte
// send data only when you receive data
if (SerialUno.available() > 0)
{
//SerialUno.listen();
if((val = SerialUno.read()) == 2) // First Byte should be 2, STX byte
{
// getID(); Get the ID, sets readCard = to the read ID
// 5 HEX Byte code is actually 10 ASCII Bytes.
while ( bytesread < 12 ) // Read 10 digit code + 2 digit checksum
{
if( SerialUno.available() > 0) // Check to make sure data is coming on the serial line
{
val = SerialUno.read(); // Store the current ASCII byte in val
if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02))
{ // If header or stop bytes before the 10 digit reading
break; // Stop reading
}
IDstring = val;
- i++;*
- if ( (val >= '0' ) && ( val <= '9' ) ) // Do Ascii/Hex conversion*
- {*
- val = val - '0';*
- }*
- else if ( ( val >= 'A' ) && ( val <= 'F' ) )*
- {*
- val = 10 + val - 'A';*
- }*
- Serial.print(val,HEX);*
- Serial.print(" ");*
- if ( bytesread & 1 == 1 ) // Every two ASCII charactors = 1 BYTE in HEX format*
- {*
- // Make some space for this hex-digit by*
- // shifting the previous hex-digit with 4 bits to the left:*
- readCard[bytesread >> 1] = (val | (tempbyte << 4));*
- if ( bytesread >> 1 != 5 ) // If we're at the checksum byte,*
- {*
- checksum ^= readCard[bytesread >> 1]; // Calculate the checksum using XOR*
- }; *
- }*
- else // If it is the first HEX charactor*
- {*
- tempbyte = val; // Store the HEX in a temp variable*
- };*
- bytesread++; // Increment the counter to keep track*
- }*
- }*
- bytesread = 0;*
- i=0;*
- Serial.println();*
- Serial.println(IDstring);*
- checkTag(IDstring); //Check if it is a match*
- }*
- else*
- checksum = 0;*
- } *
}
void revisarSalida()
{ - SerialDos.begin(9600);*
- byte val = 0; // Temp variable to hold the current byte*
- // send data only when you receive data*
- if (SerialDos.available() > 0)*
- {*
- //SerialDos.listen();*
- if((val = SerialDos.read()) == 2) // First Byte should be 2, STX byte*
- {*
- // getID(); Get the ID, sets readCard = to the read ID*
- // 5 HEX Byte code is actually 10 ASCII Bytes.*
- while ( bytesread < 12 ) // Read 10 digit code + 2 digit checksum*
- {*
- if( SerialDos.available() > 0) // Check to make sure data is coming on the serial line*
- {*
- val = SerialDos.read(); // Store the current ASCII byte in val*
- if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02))*
- { // If header or stop bytes before the 10 digit reading*
- break; // Stop reading*
- }*
_ IDstring = val;_
* i++;*
* if ( (val >= '0' ) && ( val <= '9' ) ) // Do Ascii/Hex conversion*
* {*
* val = val - '0';*
* }*
* else if ( ( val >= 'A' ) && ( val <= 'F' ) )*
* {*
* val = 10 + val - 'A';*
* }*
* Serial.print(val,HEX);*
* Serial.print(" ");*
* if ( bytesread & 1 == 1 ) // Every two ASCII charactors = 1 BYTE in HEX format*
* {*
* // Make some space for this hex-digit by*
* // shifting the previous hex-digit with 4 bits to the left:*
* readCard[bytesread >> 1] = (val | (tempbyte << 4));*
* if ( bytesread >> 1 != 5 ) // If we're at the checksum byte,*
* {*
* checksum ^= readCard[bytesread >> 1]; // Calculate the checksum using XOR*
* }; *
* }*
* else // If it is the first HEX charactor*
* {*
* tempbyte = val; // Store the HEX in a temp variable*
* };*
* bytesread++; // Increment the counter to keep track*
* }*
* }*
* bytesread = 0;*
* i=0;*
* Serial.println();*
* Serial.println(IDstring);*
* checkTag(IDstring); //Check if it is a match*
* }*
* else*
* checksum = 0;*
* } *
}
// If the serial port is ready and we received the STX BYTE (2) then this function is called
// to get the 4 BYTE ID + 1 BYTE checksum. The ID+checksum is stored in readCard[6]
// Bytes 0-4 are the 5 ID bytes, byte 5 is the checksum
//void getID()
//{
//}
void checkTag(char tag[])
{
* int actuador;*
* ///////////////////////////////////*
* //Check the read tag against known tags*
* ///////////////////////////////////*
* if(strlen(tag) == 0) return; //empty, no need to contunue*
* if(compareTag(tag, tag1)){ // if matched tag1, do this*
* Serial.println("Usuario: Rodrigo");*
* actuador=1;*
* }else if(compareTag(tag, tag2)){ //if matched tag2, do this*
* Serial.println("Usuario: Gabriela");*
* actuador=1; *
* }else if(compareTag(tag, tag3)){*
* Serial.println("Tarjeta: Borrado");*
* actuador=2; *
* }else if(compareTag(tag, tag4)){*
* Serial.println("Tarjeta: Maestro");*
* actuador=2;*
* }else{*
* Serial.print("Tarjeta Desconocida: ");*
* Serial.println(tag); //read out any unknown tag*
* actuador=3; *
* }*
* if(actuador==1)*
* {*
* digitalWrite(ledVerde, HIGH);*
* }*
* else if (actuador==2)*
* {*
* digitalWrite(ledRojo, HIGH);*
* digitalWrite(ledVerde, HIGH); *
* }*
* else if (actuador==3)*
* {*
* digitalWrite(ledRojo, HIGH);*
* }*
* delay(100);*
}
boolean compareTag(char one[], char two[])
{
///////////////////////////////////
//compare two value to see if same,
//strcmp not working 100% so we do this
///////////////////////////////////
* if(strlen(one) == 0) return false; //empty*
* for(int i = 0; i < 12; i++){*
if(one != two*) return false;*
* }*
* return true; //no mismatches*
}