Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

ID-12/ID-20 RFID Reader Driver


  • Please log in to reply
61 replies to this topic

#41 haxburgen

haxburgen

    Member

  • Members
  • PipPip
  • 21 posts

Posted 08 November 2011 - 04:14 AM

Thanks Trey for the reply. Attached is my code. RFID Pin 1 to gnd from netduino RFID Pin 2 to 5V from netduino RFID Pin 11 to 5V from netduino RFID Pin 9 to Digital Pin 0 from netduino RFID Pin 7 to gnd from netduino

Attached Files



#42 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 08 November 2011 - 05:14 AM

Thanks Trey for the reply.

Attached is my code.

RFID Pin 1 to gnd from netduino
RFID Pin 2 to 5V from netduino
RFID Pin 11 to 5V from netduino
RFID Pin 9 to Digital Pin 0 from netduino
RFID Pin 7 to gnd from netduino


Sorry to say nothing jumps out to me as a problem.
You get one scan, then nothing after?
I would put it some debug.print statements in the _rfidCardDataReceived sub.
Maybe its scanning, but its not getting the all the digits read.
When you scan, are you waiting enough time in between scans?
I started working on an Event/Queue driven scan because scans to close together would cause problems.

#43 haxburgen

haxburgen

    Member

  • Members
  • PipPip
  • 21 posts

Posted 14 November 2011 - 05:21 AM

Thanks trey for your response. Here is what I found out from debugging.

My Code.
/* This method receives card data from the RFID reader via serial callback. */
        private void _rfidCardDataReceived(object _cardPort, SerialDataReceivedEventArgs unused)
        {
            Debug.Print("here");
            // Do nothing if the reader is not supposed to be running.
            if (!_readerRunning) return;
            Debug.Print("running");
            // Capture the port that the data was received on.
            SerialPort cardPort = (SerialPort)_cardPort;

            // Read the ID string.
            cardPort.Read(rawData, 0, rawData.Length);

            // Isolate the actual ID string.
            for (int i = 0; i < idStringData.Length; i++)
            {
                idStringData[i] = (char)rawData[i + 1];
            }

            // Convert the ID character array to a proper string.
            String str = new String(idStringData);

            if (str.Length == 12)
            {
                Debug.Print("here?");
                int[] chk = new int[6];
                chk[0] = hexConvert(str.Substring(0, 2));
                chk[1] = hexConvert(str.Substring(2, 2));
                chk[2] = hexConvert(str.Substring(4, 2));
                chk[3] = hexConvert(str.Substring(6, 2));
                chk[4] = hexConvert(str.Substring(8, 2));
                chk[5] = hexConvert(str.Substring(10, 2));
                if ((chk[0] ^ chk[1] ^ chk[2] ^ chk[3] ^ chk[4]) == chk[5])
                {
                    //String finishedID = new String(idStringData);
                    cardPort.Write(rawData, 0, rawData.Length);
                    RfidEventArgs _args = new RfidEventArgs();
                    _args.RFID = _args.RFID = (((chk[1] << 8 | chk[2]) << 8 | chk[3]) << 8 | chk[4]).ToString();
                    _args.ReadTime = DateTime.Now;
                    OnRfidEvent(_args);
                }

            }

            // Wipe the receive buffer for next time.
            for (int i = 0; i < rawData.Length; i++)
            {
                rawData[i] = 0;
            }
        }
    }

here is the output on the first attempt

here
running
here?
Card scanned: 4482170, time: 01/01/2009 00:29:55


here is the output for every other attempt

here
running
here
running
here
running
here
running
here
running



#44 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 14 November 2011 - 06:02 AM

Thanks trey for your response. Here is what I found out from debugging.

My Code.

            // Wipe the receive buffer for next time.
            for (int i = 0; i < rawData.Length; i++)
            {
                rawData[i] = 0;
            }
        }




Please try it without these lines.
            // Wipe the receive buffer for next time.
            for (int i = 0; i < rawData.Length; i++)
            {
                rawData[i] = 0;
            }

I'm thinking if its clearing the data, while scanning, you are losing data.

Maybe try this updated version as well.

        private void _rfidCardDataReceived(object _cardPort, SerialDataReceivedEventArgs unused)
        {
            // Do nothing if the reader is not supposed to be running.
            if (!_readerRunning) return;

            // Capture the port that the data was received on.
            SerialPort cardPort = (SerialPort)_cardPort;

            String cardID = String.Empty;
            int GPStoRead = cardPort.BytesToRead;
            if (GPStoRead == 16)
            {
                cardPort.Read(rawData, 0, rawData.Length);
                for (int i = 0; i < idStringData.Length; i++)
                {
                    idStringData[i] = (char)rawData[i + 1];   // skip first STX char 
                }
                String str = new string(idStringData);
                if (str.Length == 12)
                {
                    int[] chk = new int[6];
                    chk[0] = hexConvert(str.Substring(0, 2));
                    chk[1] = hexConvert(str.Substring(2, 2));
                    chk[2] = hexConvert(str.Substring(4, 2));
                    chk[3] = hexConvert(str.Substring(6, 2));
                    chk[4] = hexConvert(str.Substring(8, 2));
                    chk[5] = hexConvert(str.Substring(10, 2));
                    if ((chk[0] ^ chk[1] ^ chk[2] ^ chk[3] ^ chk[4]) == chk[5])
                    {
                        //String finishedID = new String(idStringData);
                        cardPort.Write(rawData, 0, rawData.Length);
                        RfidEventArgs _args = new RfidEventArgs();
                        _args.RFID = _args.RFID = (((chk[1] << 8 | chk[2]) << 8 | chk[3]) << 8 | chk[4]).ToString(); //((chk[2] << 8 | chk[3]) << 8 | chk[4]).ToString();
                        _args.ReadTime = DateTime.Now;
                        OnRfidEvent(_args);
                    }
                }

            }
        }

I think it adds an extra step of making sure a full card was read.

-Trey

#45 haxburgen

haxburgen

    Member

  • Members
  • PipPip
  • 21 posts

Posted 14 November 2011 - 06:20 AM

GGGREAT! That worked. Thanks.

#46 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 14 November 2011 - 01:29 PM

GGGREAT! That worked. Thanks.


That is great news!
You are welcome.

-Trey

#47 VicMax

VicMax

    New Member

  • Members
  • Pip
  • 4 posts

Posted 11 November 2012 - 09:29 PM

Hi there, I'm new using netduino aswell as the RFid-12, I've seen all of the guys here using the device but how about conecting it whit the sparkfun RFID USB board (https://www.sparkfun.com/products/9875) is it possible? or do i hace to connect it directly??

#48 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 12 November 2012 - 01:08 AM

Hi there,

I'm new using netduino aswell as the RFid-12, I've seen all of the guys here using the device but how about conecting it whit the sparkfun RFID USB board (https://www.sparkfun.com/products/9875) is it possible? or do i hace to connect it directly??


Welcome VixMax!

In this post http://forums.netdui...dpost__p__10290, I state how I have it hooked up.
The data sheet for your RFID, is the same for the ID-12 as well.
http://www.sparkfun....2-Datasheet.pdf

I just noticed this line on the first post by Charles..."This is a simple encapsulation class for the ID-2/ID-12/ID-20 RFID Card Reader modules."

So it looks like you should be able to hook yours up the same way I have stated above, which I believe is stated even earlier.
Good Luck!
Trey

#49 buzz

buzz

    New Member

  • Members
  • Pip
  • 2 posts

Posted 18 January 2013 - 06:32 AM

Finally got my ID-20 working well.  A big THANK YOU to everyone here who contributed...this stuff is truly fascinating.

 

I plan to run this RFID scanner in production with ~50 employees on it.  So after much stress testing, I'd like to contribute a few changes to the datareceived method to ensure maximum reliability.  Particularly with ID-20 reading multiple cards in quick succession.  Basically the code can't crash since no one may be around reboot it.

 

Changes I made:

- hopefully almost crashproof

- moved rawdata to local scope

- removed args.ReadTime, args.RFID output is now int, renamed class

- better error state output using args.Success (ie: to display error led's to user)

- better handles multiple/quick reads...basically when BytesToRead is not a perfect 16

- found that hexConvert was not as efficient as direct parsing of the paired hex

- removed cardPort.Write - this seems to echo the input...not sure why this was necessary...it seems to run fine w/o it and it speeds up the code quite a bit

 

 

private void _rfidCardDataReceived( object _cardPort, SerialDataReceivedEventArgs unused ){	// Do nothing if the reader is not supposed to be running.	if ( !_readerRunning ) return;	// Capture the port that the data was received on.	SerialPort cardPort = (SerialPort) _cardPort;	// Buffers for incoming card data.	byte[] rawData = new byte[16]; // Incoming raw bytes from the serial connection.	RfidEventArgs args = new RfidEventArgs();	string cardID = String.Empty;	int bytesToRead = cardPort.BytesToRead;	if ( bytesToRead == 16 )	{		cardPort.Read( rawData, 0, rawData.Length );		int[] chk = new int[6];		chk[0] = HexAsciiToInt( rawData, 1 );		chk[1] = HexAsciiToInt( rawData, 3 );		chk[2] = HexAsciiToInt( rawData, 5 );		chk[3] = HexAsciiToInt( rawData, 7 );		chk[4] = HexAsciiToInt( rawData, 9 );		chk[5] = HexAsciiToInt( rawData, 11 );		if ( ( chk[0] ^ chk[1] ^ chk[2] ^ chk[3] ^ chk[4] ) == chk[5] )		{			args.Success = true;			args.RFID = ( ( ( chk[1] << 8 | chk[2] ) << 8 | chk[3] ) << 8 | chk[4] );			OnRfidEvent( args );		}		else		{			args.Success = false;			args.ErrorMsg = "Checksum mismatch on RFID: " + ( chk[0] ^ chk[1] ^ chk[2] ^ chk[3] ^ chk[4] ) + " vs " + chk[5];			OnRfidEvent( args );		}	}	else if ( bytesToRead > 16 ) // bytesToRead exceeds 16 (ie: too many cards read at same time, nuke everything)	{		// clear buffer		cardPort.DiscardInBuffer();		args.Success = false;		args.ErrorMsg = "Serial port buffer exceeds 16 bytes: " + bytesToRead;		OnRfidEvent( args );	}}public int HexAsciiToInt( byte[] data, int offset, int length = 2 ){	int ret = 0;	for ( int i = 0; i < length; i++ )	{		ret = ret * (int) System.Math.Pow( 16, i ); // each digit is another power of 16		if ( data[offset + i] >= 48 && data[offset + i] <= 57 )			// number			ret += data[offset + i] - 48;		else			// letter A - F			ret += data[offset + i] - 55;	}	return ret;}

 

 

The full RFIDReader.cs...usage is similar to program code posted earlier in the thread except the class is renamed:

 

Attached File  RFIDReader.cs   4.28KB   9 downloads

 



#50 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 24 January 2013 - 12:02 PM

Hello everybody,

I'm testing my ID-12 with Netduino plus 2 and a library very similar to the one used in this thread. Everything works perfect for hours. But some times the ID-12 seems to become "slow/locked". It's difficult to explain, but happens that passing the tag at 2/3 cm nothing happens, I have to touch the ID-12 with the tag to allow it reading. Then I have to touch the ID-12 with the tag for several times until it becomes "unlocked" and starts reading at 6 cm fast and regularly.

When it's in the "locked/slow" state the led light for more than one seconds when it reads and the beeper sounds not regularly.

 

Hope somebody can help

Gerardo



#51 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 24 January 2013 - 04:14 PM

buzz,

Thanks for the contribution!

 

I would love to try it out, but will have to wait until time allows.

 

-Trey

 

Finally got my ID-20 working well.  A big THANK YOU to everyone here who contributed...this stuff is truly fascinating.

 

I plan to run this RFID scanner in production with ~50 employees on it.  So after much stress testing, I'd like to contribute a few changes to the datareceived method to ensure maximum reliability.  Particularly with ID-20 reading multiple cards in quick succession.  Basically the code can't crash since no one may be around reboot it.

 

Changes I made:

- hopefully almost crashproof

- moved rawdata to local scope

- removed args.ReadTime, args.RFID output is now int, renamed class

- better error state output using args.Success (ie: to display error led's to user)

- better handles multiple/quick reads...basically when BytesToRead is not a perfect 16

- found that hexConvert was not as efficient as direct parsing of the paired hex

- removed cardPort.Write - this seems to echo the input...not sure why this was necessary...it seems to run fine w/o it and it speeds up the code quite a bit



#52 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 24 January 2013 - 04:33 PM

Hello everybody,

I'm testing my ID-12 with Netduino plus 2 and a library very similar to the one used in this thread. Everything works perfect for hours. But some times the ID-12 seems to become "slow/locked". It's difficult to explain, but happens that passing the tag at 2/3 cm nothing happens, I have to touch the ID-12 with the tag to allow it reading. Then I have to touch the ID-12 with the tag for several times until it becomes "unlocked" and starts reading at 6 cm fast and regularly.

When it's in the "locked/slow" state the led light for more than one seconds when it reads and the beeper sounds not regularly.

 

Hope somebody can help

Gerardo

 

Gerardo,

This almost sounds like a power issue.  The id12 requires 5v at 30ma.  Are you running this from a battery? 

If you are using a breadboard, maybe a bad connection somewhere?  That was my biggest problem.

Sorry, like you, I'm at a loss what would cause this to freeze. 

Maybe try the library in this thread to rule out the code that you are currently using.  If you can, maybe even share your library so people have alternate libraries to choose from and to look for possible bugs.

Also try putting in a bunch of debug.print lines in your code to see if the code is responding correctly.

Some filter capacitors on the breadboards input power might help too.  Just thinking maybe there is interference. 

Do you have the RFID USB Reader from Sparkfun?

https://www.sparkfun.com/products/9963

You can plug this directly into a USB port and start up a terminal window and scan cards.  It will just spit out data.  This would be another way to test.

If you happen to have an FTDI cable or Serial to TTL converter, you can pretty much do the same thing. 

The Schematic for the above RFID USB reader is on sparkfuns site.

 

Sorry, no real answer for what is causing your problem.  Please reply back if you find a solution.

 

-Trey



#53 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 25 January 2013 - 10:16 AM

Gerardo,

This almost sounds like a power issue.  The id12 requires 5v at 30ma.  Are you running this from a battery? 

If you are using a breadboard, maybe a bad connection somewhere?  That was my biggest problem.

Sorry, like you, I'm at a loss what would cause this to freeze. 

Maybe try the library in this thread to rule out the code that you are currently using.  If you can, maybe even share your library so people have alternate libraries to choose from and to look for possible bugs.

Also try putting in a bunch of debug.print lines in your code to see if the code is responding correctly.

Some filter capacitors on the breadboards input power might help too.  Just thinking maybe there is interference. 

Do you have the RFID USB Reader from Sparkfun?

https://www.sparkfun.com/products/9963

You can plug this directly into a USB port and start up a terminal window and scan cards.  It will just spit out data.  This would be another way to test.

If you happen to have an FTDI cable or Serial to TTL converter, you can pretty much do the same thing. 

The Schematic for the above RFID USB reader is on sparkfuns site.

 

Sorry, no real answer for what is causing your problem.  Please reply back if you find a solution.

 

-Trey

Thank you Trey for your detailed reply.

Anyway I tried this thread code and got the same problem. The power is correct because i got it from ND2 Plus 5v volt header.The connections on the breadboard seem to be correct, I used the simplest scheme from Innovations. Do you suggest any other connections?

 

Gerardo



#54 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 26 January 2013 - 08:43 PM

Gerardo,

I would suggest picking up a RFID USB Reader from Sparkfun or making your own.  I would be trying to determine which element is having a problem.  Netduino or RFID reader.  So try them on different circuits and see if they work ok on their own. 

Maybe the Netduino had a nice static shock and it having issues. Maybe the RFID is faulty. 

Its really hard to say and sorry I dont have any definite solution.

 

Good Luck,

Trey

 

 

 

 

Thank you Trey for your detailed reply.

Anyway I tried this thread code and got the same problem. The power is correct because i got it from ND2 Plus 5v volt header.The connections on the breadboard seem to be correct, I used the simplest scheme from Innovations. Do you suggest any other connections?

 

Gerardo



#55 buzz

buzz

    New Member

  • Members
  • Pip
  • 2 posts

Posted 07 February 2013 - 05:01 PM

I've ordered more ID-20s recently and it seems the new batch (with "LV" prefix) from sparkfun exhibits weird issues.  You can read some of them in the ID-20 thread.  I've found that if you connect the reader to the 3v3 instead of 5v, it's almost 'normal'.  I just dont know if this is a good idea moving forward or how consistent it'll be.  I also saw another method using a resistor.



#56 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 07 February 2013 - 07:51 PM

Thanks for the update buzz!

Based on the thread, there is a fix by placing a 180ohm resistor in series with your buzzer.

 

Gerardo,

Hopfully this will fix your problem!

Please let us know!

 

 

I've ordered more ID-20s recently and it seems the new batch (with "LV" prefix) from sparkfun exhibits weird issues.  You can read some of them in the ID-20 thread.  I've found that if you connect the reader to the 3v3 instead of 5v, it's almost 'normal'.  I just dont know if this is a good idea moving forward or how consistent it'll be.  I also saw another method using a resistor.



#57 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 10 May 2013 - 05:43 PM

Hello Buzz and Trey.

Thanks a lot for sharing the solutions. I just "reactivated" my RFID project (a lot of work in last months) and found your solutions to my issue really helpful.

  • Changing from 5.0V to 3.3V the circuit Vin, It works like a charm! Really strange but I red from the new edition (11.04.2013) ID-Innovations datasheet, the following: "The choice of power supply is very important. The ideal power supply will be a linear type such as an LM7805 or a 3.3 volt equivalent. Batteries may also be used without a regulator, a suitable arrangement can consist of a 3volt lithium cell or 3x 1.5v cells to give 4.5 volts." It seems that the Trey got it at first! ("Gerardo This almost sounds like a power issue.").
  • Now it seems that the new release of ID-2/12/20 series (LA) is Low power working range from 2.8 to 5.0 volt. But may be the previous ones were too? Do not really understand. I will send them the video, the circuit powered at 5 (during locking) and the working one powered at 3.3. I'll let you know their answers.

 

Chris may the 3.3 Vout be more "linear" and stable than 5.0 Vout?

 

Gerardo



#58 Trey Aughenbaugh

Trey Aughenbaugh

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 14 May 2013 - 07:43 PM

Glad you reactivated your project and had some good news to share!  Thanks for the update!

Whatever you can share will be great news for anyone else just starting!

 

-Trey

 

Hello Buzz and Trey.

Thanks a lot for sharing the solutions. I just "reactivated" my RFID project (a lot of work in last months) and found your solutions to my issue really helpful.

  • Changing from 5.0V to 3.3V the circuit Vin, It works like a charm! Really strange but I red from the new edition (11.04.2013) ID-Innovations datasheet, the following: "The choice of power supply is very important. The ideal power supply will be a linear type such as an LM7805 or a 3.3 volt equivalent. Batteries may also be used without a regulator, a suitable arrangement can consist of a 3volt lithium cell or 3x 1.5v cells to give 4.5 volts." It seems that the Trey got it at first! ("Gerardo This almost sounds like a power issue.").
  • Now it seems that the new release of ID-2/12/20 series (LA) is Low power working range from 2.8 to 5.0 volt. But may be the previous ones were too? Do not really understand. I will send them the video, the circuit powered at 5 (during locking) and the working one powered at 3.3. I'll let you know their answers.

 

Chris may the 3.3 Vout be more "linear" and stable than 5.0 Vout?

 

Gerardo



#59 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 21 May 2013 - 02:37 PM

Hello again.

One problem solved, new one is underway!

Moving power from 5 to 3.3 allow the circuit to work perfectly. Now I added a webserver and a smtp client to the project, and as far as I use the reader just to read it works for hours, but when I try to send an email or to read data using the web server (i.e. whenever I use the NET), the dispose method of the RFIDReader class is called (i.e. ~RFIDReader()) without any action by my side! I use two different smtp client and three different webserver (Neonmika one, another one found on the net and a self made one with few rows of code, very very simple). What give me an hope  is that the call to the dispose method is always performed whenever a "clientSocket.Receive" is called, but I'm wondering why?

Did some of you experienced a similar behavior?

 

Thank you

Gerardo



#60 JJJ

JJJ

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationItaly

Posted 21 May 2013 - 03:41 PM

Hello again.

One problem solved, new one is underway!

Moving power from 5 to 3.3 allow the circuit to work perfectly. Now I added a webserver and a smtp client to the project, and as far as I use the reader just to read it works for hours, but when I try to send an email or to read data using the web server (i.e. whenever I use the NET), the dispose method of the RFIDReader class is called (i.e. ~RFIDReader()) without any action by my side! I use two different smtp client and three different webserver (Neonmika one, another one found on the net and a self made one with few rows of code, very very simple). What give me an hope  is that the call to the dispose method is always performed whenever a "clientSocket.Receive" is called, but I'm wondering why?

Did some of you experienced a similar behavior?

 

Thank you

Gerardo

SOLVED!

Sorry do not waste time in found any solution it was simply a GC problem. During my tests I simply wrote this:

        private static void StartRFID()        {            var idReader = new RFIDReader(SerialPorts.COM1, Pins.GPIO_PIN_D4);            idReader.RfidEvent += new RFIDReader.RfidEventDelegate(_idReader_RfidEvent);            idReader.Start();        }

So the GC during "collection" disposed my idReader variable. Right code is:

        private static void StartRFID()        {            idReader = new RFIDReader(SerialPorts.COM1, Pins.GPIO_PIN_D4);            idReader.RfidEvent += new RFIDReader.RfidEventDelegate(_idReader_RfidEvent);            idReader.Start();        }

Where the idReader is global scope declared.

 

Gerardo






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.