I am working with RFID reader. I want to read values when card pass over the reader. But only one reader works at one time. Because other serial port is not initialized. For that I use port.listen() function but it didn't help me because some time it read data and some time not. My code is given below suggest me what I have to do. My board is UNO.
#include <SoftwareSerial.h>
SoftwareSerial RFID(8, 9); // RX and TX
SoftwareSerial RFIDD(2, 3); // RX and TX
int data1;
int data2;
int data3;
int ok = -1;
int in = 13;
int out = 12;
int i;
byte byteRead;
void setup()
{
Serial.begin(2400); // start serial to PC
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
RFID.begin(2400);
RFIDD.begin(2400);
// start serial to RFID reader
pinMode(in, OUTPUT); // for status LEDs
pinMode(out, OUTPUT);
}
void readvalues() {
RFID.listen();
if (RFID.available()>0)
{
delay(400);
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
data2 = RFID.read();
Serial.print(data2);
}
RFID.flush(); // stops multiple reads
//Serial.print(" ");
}
RFIDD.listen();
if (RFIDD.available()>0) {
delay(400);
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
data1 = RFIDD.read();
Serial.print(data1);
}
RFIDD.flush(); // stops multiple reads
//Serial.print(" ");
}
}
void loop()
{
readvalues();
if (Serial.available()) {
byteRead = Serial.read();
//listen for numbers between 0-9
if(byteRead == 49){
//number found
digitalWrite(in, HIGH);
delay(1000);
digitalWrite(in, LOW);
}else if(byteRead == 48){
//number found
digitalWrite(out, HIGH);
delay(1000);
digitalWrite(out, LOW);
}
}
}