SeeedStudio RFID Library

Has anyone got the seeed RFID library running lately with the 125Khz RFID module – UART

Found at
https://www.seeedstudio.com/125khz-rfid-module-uart-p-171.html?cPath=19_24

The RFID library is at

https://build.particle.io/libs/SeeedRFID/1.0.5/tab/SeeedRFID.cpp

Can’t seem to get the above library running but I did hack together some code that works fine but sends garbage as a start bit and stop bit (a rectangle gets printed). Wondering how to get rid of the garbage or how to get the proper package going.

Here is my hacked code:

String myOut = "";
unsigned long lastTime = 0;

void setup(){
   Serial1.begin(9600);
    Particle.publish("Starting","RFID Reader", 60, PRIVATE);
}


void loop(){
    if(Serial1.available()){
        while(Serial1.available()){
            char stuff= Serial1.read();
    
             myOut += String(stuff);   
        }
            Particle.publish("Tag Number = ", myOut, 60, PRIVATE);
            delay(3000);
            myOut = "";
    	
   }
}

The console shows (I only brought home one tag :blush: which registers twice if you scan to fast )

The first little rectangle is /u0002 and the second is /u0003 if that helps anyone?

Code such as the following does not seem to strip out the garbage, probably because the garbage is bits not bytes. Should I search for 0 as a start and 1 as a finish, since uART defaults to sending a stream of ones? The above /u0002 also doesn’t work.

    if (stuff == '/r'   || stuff == '/n'  ){} else {
     myOut += String(stuff);  
    }

Where did you get that information from?
Was this stripped from the console output or directly on the device?
Since /u0002 isn't anything you'd get with a Serial1.read() I guess it's the former, but you need the latter :wink:

Just for completeness, could it be that the datasheet of the reader tells anything about extra frame start/stop bytes?

If you know you'll only ever get hex digits, you can filter for these 0..9 & A..F

  if ('0' <= stuff && stuff <= '9' || 'A' <= stuff && stuff <= 'F')
1 Like

I will try your "if" statement which makes a lot of sense.

if ('0' <= stuff && stuff <= '9' || 'A' <= stuff && stuff <= 'F')

Still curious what would detect the rectangles. I think I will also try byte(0) and byte(1)

Worked great got rid of the rectangles. Still combines numbers. I should be able to flush the buffer somehow, but that would need detecting the end bit.

@rocksetta, the best way to find out what the “rectangles” are is to do a Serial.print() of stuff in HEX format:

Serial.print(stuff,HEX);

Just before the publish, add Serial.println(); to create a new line for each tag.

Now you will see the HEX value of each byte passed by the board.

1 Like

Unfortunately I am at school and the locked down computers makes working with putty almost impossible. Part of the reason I really like the console. I will see if I can print in HEX format on the console.

@rocksetta, then use printf() to build a string with the HEX values and publish that! Or change your current method with this:

myOut += String(stuff, HEX) + ",";

Untested but I think it will work.

1 Like

Thanks @peekay123 and @ScruffR.

Got everything working without an include file.:slight_smile:

String myOut = "";
unsigned long lastTime = 0;

void setup(){
   Serial1.begin(9600);  // activate UART using TX and RX
   Particle.publish("Starting","RFID Reader", 60, PRIVATE);
}

void loop(){
    if(Serial1.available()){
        while(Serial1.available()){
            char incoming = Serial1.read();
            //if ( ! (incoming == 0x2 || incoming == 0x3) ) ){ // this logic call also works !  
            if ( ! (incoming == byte(2) || incoming == byte(3) ) ){ 
                myOut += String(incoming);   
            }
        }
        if (myOut != ""){
           Particle.publish("Tag ID", String(myOut), 60, PRIVATE);
        }
        delay(30);
        myOut = "";
   }
}

Here is the connection diagram:

One last question. This is a 125Khz RFID module – UART should I be using a faster serial1 speed?

2 Likes

@rocksetta, the specs for the board show:

Baud Rate		9600 (TTL Electricity Level RS232 format)

So that’s as fast as it goes! BTW, the 125KHz refers to the RF frequency used for reading the tag. There are also 13.56MHz versions.

2 Likes