Hey ,
I'm doing a project based on waste segregation using RFID tags(which will be embedded in the garbage) .Eventually,it's supposed to be a game for little kids ,to learn to differentiate waste.
For now,i'm using just two RFID readers and two tags,just to see if i can get this bit working. I need to use multiple software serial ports (as of now, 2 ports to receive data from the two readers).
My problem point is -: Despite using whateverobject.listen() i'm unable to listen in on the available ports.Actually i don't get any data. But when i use just one reader or one port ( i don't need the object.listen() )and comment out the unnecessary parts of the code,it works.
i have posted the code below,which uses two ports and doesn't receive any data.If someone can please help with the receiving of information from two ports ,That'd be awesome!
#include <SoftwareSerial.h>
String item;//variable to store the characters from the available serial port(RFID1)
String userid;//variable to store the characters from the available serial port(user)
int ctr=0;
long int user1=4140716;//tags which are given to the user-Reader 2
long int user2=4140718;
//long int cat[3]={4140720,5118436,4356789};// tags which are embedded in the garbage-Reader 1
SoftwareSerial user(3,4);//Serial object-1
SoftwareSerial RFID1(5,6);//Serial object-2
void setup()
{
Serial.begin(9600);
delay(200);
}
void loop()
{
func_user();
func_RFID1();
}
void func_user()
{
user.begin(9600);//setting the baud rate for the serial object-user
long int un,um;
user.listen();
while(user.available())
{
delay(200);
while(user.available()>0)
{
userid+=char(user.read());
}
}
Serial.println(userid);
char usercarray[15];
userid.toCharArray(usercarray, sizeof(usercarray));//converting string to character array
un = atol(usercarray); //converting char array to long int
um=un%10000000;//using only 7 values in the 8 values of tag
Serial.print("The user integer value is");
Serial.println(um);
delay(2000);
if(um==user1)
Serial.println("Welcome user1");
else if(um==user2)
Serial.println("Welcome user2");
else
Serial.println("invalid user");
delay(2000);
userid="\0";
}
void func_RFID1()
{
RFID1.begin(9600);
long int n,m;
RFID1.listen();
while(RFID1.available())
{
delay(2000);
if(RFID1.available()>0)
{
item+=char(RFID1.read());
}
}
Serial.println(item);
char carray[15];
item.toCharArray(carray, sizeof(carray));
n = atol(carray);
m=n%10000000;
Serial.print("The integer value is");
Serial.println(m);
item="\0";
delay(2000);
}
Thanks in advance!