I'm trying to read from two sm130 (rfid reader) with an arduino. uno.
I'm using the SoftwareSerial library.
I've successfully seeing my Mifare tags with the code found at
I'm using this kind of tags
http://www.robotshop.com/eu/fr/autocollant-rfid-rond-1356mhz.html
with this antenna
It works from a distance to 4 cm. I'm using an external power for the sm130 module,
If I try with two modules with an alternate listening from one soft serial to an other with the code below the behaviour is very strange. The ranging distance is shorter (I still have only one antenna for each module), and the reading is hazardous (sometimes it reads but not every time).
I've tried to change the switching frequency for the antenna but it doesn't help.
Any ideas ?
/*
RFID Eval 13.56MHz Shield example sketch v10
Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW
works with 13.56MHz MiFare 1k tags
Note: RFID Reset attached to D13 (aka status LED)
Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/
Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the 'Found' LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.
*/
#include <SoftwareSerial.h>
SoftwareSerial rfid(2, 3);
SoftwareSerial rfid2(7, 8);
//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);
void check_for_notag2(void);
void halt2(void);
void parse2(void);
void print_serial2(void);
void read_serial2(void);
void seek2(void);
void set_flag2(void);
//Global var
int flag = 0;
int Str1[11];
boolean reading1 = false;
boolean reading2 = false;
int flag2 = 0;
int Str2[11];
//INIT
void setup()
{
Serial.begin(19200);
Serial.println("Start");
// set the data rate for the SoftwareSerial ports
rfid.begin(19200);
delay(10);
halt();
delay(100);
rfid2.begin(19200);
delay(10);
halt2();
rfid.listen();
}
//MAIN
void loop()
{
unsigned long start = millis();
reading1 = true;
while (reading1){
read_serial();
if (start + 1000 < millis()) reading1 = false;
}
rfid2.listen();
reading2 = true;
unsigned long start2 = millis();
while (reading2){
read_serial2();
if (start2 + 1000 < millis()) reading2 = false;
}
rfid.listen();
}
//--------------------------------------
void read_serial()
{
seek();
delay(10);
parse();
set_flag();
print_serial();
delay(100);
}
//--------------------------------------
void check_for_notag()
{
seek();
delay(10);
parse();
set_flag();
if(flag == 1){
seek();
delay(10);
parse();
}
}
void halt()
{
//Halt tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)147);
rfid.write((uint8_t)148);
}
void parse()
{
while(rfid.available()){
if(rfid.read() == 255){
for(int i=1;i<11;i++){
Str1[i]= rfid.read();
}
}
}
}
void print_serial()
{
if(flag == 1){
if(Str1[7]== 253 && Str1[6]==247 && Str1[5]==157) Serial.print("1");
else if(Str1[7]== 248 && Str1[6]==213 && Str1[5]==141) Serial.print("2");
else if(Str1[7]== 248 && Str1[6]==69 && Str1[5]==141) Serial.print("3");
else if(Str1[7]== 252 && Str1[6]==135 && Str1[5]==173) Serial.print("4");
else if(Str1[7]== 253 && Str1[6]==14 && Str1[5]==189) Serial.print("5");
else if(Str1[7]== 253 && Str1[6]==98 && Str1[5]==13) Serial.print("6");
else {
Serial.print(Str1[7]);
Serial.print(Str1[6]);
Serial.print(Str1[5]);
}
Serial.println();
delay(100);
reading1 = false;
check_for_notag();
}
}
void seek()
{
//search for RFID tag
rfid.write((uint8_t)255);
rfid.write((uint8_t)0);
rfid.write((uint8_t)1);
rfid.write((uint8_t)130);
rfid.write((uint8_t)131);
delay(10);
}
void set_flag()
{
if(Str1[2] == 6){
flag++;
}
if(Str1[2] == 2){
flag = 0;
}
}
//-------------------------------------
//--------------------------------------
void read_serial2()
{
seek2();
delay(10);
parse2();
set_flag2();
print_serial2();
delay(100);
}
//--------------------------------------
void check_for_notag2()
{
seek2();
delay(10);
parse2();
set_flag2();
if(flag2 == 1){
seek2();
delay(10);
parse2();
}
}
void halt2()
{
//Halt tag
rfid2.write((uint8_t)255);
rfid2.write((uint8_t)0);
rfid2.write((uint8_t)1);
rfid2.write((uint8_t)147);
rfid2.write((uint8_t)148);
}
void parse2()
{
while(rfid2.available()){
if(rfid2.read() == 255){
for(int i=1;i<11;i++){
Str2[i]= rfid2.read();
}
}
}
}
void print_serial2()
{
if(flag2 == 1){
if(Str2[7]== 253 && Str2[6]==247 && Str2[5]==157) Serial.print("1");
else if(Str2[7]== 248 && Str2[6]==213 && Str2[5]==141) Serial.print("2");
else if(Str2[7]== 248 && Str2[6]==69 && Str2[5]==141) Serial.print("3");
else if(Str2[7]== 252 && Str2[6]==135 && Str2[5]==173) Serial.print("4");
else if(Str2[7]== 253 && Str2[6]==14 && Str2[5]==189) Serial.print("5");
else if(Str2[7]== 253 && Str2[6]==98 && Str2[5]==13) Serial.print("6");
else {
Serial.print(Str2[7]);
Serial.print(Str2[6]);
Serial.print(Str2[5]);
}
Serial.println();
delay(100);
reading2 = false;
check_for_notag2();
}
}
void seek2()
{
//search for RFID tag
rfid2.write((uint8_t)255);
rfid2.write((uint8_t)0);
rfid2.write((uint8_t)1);
rfid2.write((uint8_t)130);
rfid2.write((uint8_t)131);
delay(10);
}
void set_flag2()
{
if(Str2[2] == 6){
flag2++;
}
if(Str2[2] == 2){
flag2 = 0;
}
}