element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Ralph Yamamoto's Blog Reading and Writing RFID Tags
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 17 Dec 2018 6:18 AM Date Created
  • Views 4596 views
  • Likes 5 likes
  • Comments 19 comments
  • rfid_reader
  • rfid_tag
  • rc522
Related
Recommended

Reading and Writing RFID Tags

ralphjy
ralphjy
17 Dec 2018

I am going to start a project soon where I want to use RFID tags to enable user authentication and individual profiles for a home automation remote controller.  I haven't worked with RFID tags before, even though they are fairly ubiquitous at this point.  I imagine this is old hat to most folks, but I thought I'd share my learning.

 

I purchased an RC522 RFID Reader/Writer module and a set of RFID tags on Amazon.  The RC522 chip itself offers multiple interfaces (SPI, I2C, Serial UART), but I discovered that the board that I got was only set up for SPI.  I had wanted to use I2C, but decided it wasn't worth hacking up the board.  The Reader/Writer supports most of the standard Mifare card types (Mini, 1K, 4K, Ultralight, DESFire EV1, and Plus).  The tags that were included were Mifare 1K.

 

I had a breadboard already set up with a Sparkfun ESP8266 Thing Dev and a 128x64 OLED display, so I decided to use that for testing.

image

 

I've been using the Arduino IDE to program my Thing Dev and there is an MFRC522 library available so that worked out well.  Took a while adjusting the pin configurations to get the SPI and I2C to coexist nicely.

 

Been having fun reading stuff that I have lying around.  I had a Ventra ticket from a recent trip to Chicago and it happened to be an Ultralight card.

 

Then I moved on to testing the write capability using the example code that is in the library.

 

Here's the output:

 

  Card UID: 72 DF 5D 96

  PICC type: MIFARE 1KB

  Authenticating using key A...

  Current data in sector:

     1      7   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ]

             6   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

             5   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

             4   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

 

  Reading data from block 4 ...

  Data in block 4:

   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

 

  Authenticating again using key B...

  Writing data into block 4 ...

   01 02 03 04 05 06 07 08 09 0A FF 0B 0C 0D 0E 0F

 

  Reading data from block 4 ...

  Data in block 4:

   01 02 03 04 05 06 07 08 09 0A FF 0B 0C 0D 0E 0F

  Checking result...

  Number of bytes that match = 16

  Success :-)

 

  Current data in sector:

     1      7   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ]

             6   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

             5   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ]

             4   01 02 03 04  05 06 07 08  09 0A FF 0B  0C 0D 0E 0F  [ 0 0 0 ]

 

*************************************************************************************

 

The 1K card has 16 sectors of 4 blocks and each block has 16 bytes (16x4x16 = 1024 bytes).  The fourth block (sector trailer) in each sector contains the authentication keys.

In the example above I was writing Block 4 which is the first block in the second sector.  You can see the authentication key in Block 7.

The factory default is 0xFFFFFFFFFFFF.

 

Now I need to figure out what type of data keys I want to store for my application......

  • Sign in to reply

Top Comments

  • e14phil
    e14phil over 7 years ago +6
    Awesome Great work! I have had a play with this RFID kit before, its a really neat package with great arduino library support. The reason I have played with it is that I have an NFC/RFID chip implanted…
  • Fred27
    Fred27 over 7 years ago in reply to ralphjy +6
    The trouble with storing the acess groups on the card is that you have no way of revoking access if someone loses their card. If you just use the read-only ID then you retain control of who gets in. My…
  • Fred27
    Fred27 over 7 years ago +5
    I'm glad you're enjoying your first forays into the world of RFID and NFC. If you're doing some home automation you can probably limit your efforts to just reading the ID on the card and having a list…
Parents
  • Fred27
    Fred27 over 7 years ago

    I'm glad you're enjoying your first forays into the world of RFID and NFC. If you're doing some home automation you can probably limit your efforts to just reading the ID on the card and having a list of IDs (stored wherever is convenient) that you give access to. No need to write to tags.

     

    Fred - another NFC implantee!

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Fred27
    Fred27 over 7 years ago

    I'm glad you're enjoying your first forays into the world of RFID and NFC. If you're doing some home automation you can probably limit your efforts to just reading the ID on the card and having a list of IDs (stored wherever is convenient) that you give access to. No need to write to tags.

     

    Fred - another NFC implantee!

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • e14phil
    e14phil over 7 years ago in reply to Fred27

    All the cool kids / evil Illuminati types are doing it

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 7 years ago in reply to Fred27

    The implementation that I'm considering would store the personalization info on the tag rather than the controller.  The controller would have generic categories like access groups (admin,user,guest,etc) and slots for user preferences.  That way, the controller could just read the info rather than need to look it up (either on the device or on the network or the cloud).  I'm just starting so I haven't really looked at what different NFC/RFID protocols exist besides the Mifare ones.  In truth, writing the tags is more of a learning exercise although I hate wasting that extra storage image.

     

    What type of info is stored on your implanted devices?  Just a unique ID?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • e14phil
    e14phil over 7 years ago in reply to ralphjy

    Nice!

     

    I currently use the Tag ID for access control, I register the tag with the door control systems at my local hackspace / work.

    I use the data sector to store a URL. I use this as a Business card. The data sector can be overwritten at any point by my self and has been set as permanently Read/Write just in case some on try to maliciously write a bad data to it and lock it as read only.

     

    Phil

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 7 years ago in reply to e14phil

    Thanks Phil, I'll go back through and read your blog posts.  Probably will answer most of the questions that I had.  A quick question - are all of these 13.56MHz tags generic?  I.e. do any of them require unique reader/writers or should I be able to use the RC522 on all of them?

     

    Ralph

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 7 years ago in reply to ralphjy

    The trouble with storing the acess groups on the card is that you have no way of revoking access if someone loses their card. If you just use the read-only ID then you retain control of who gets in.

     

    My implant just has a link to this page about having it implanted. https://0xfred.wordpress.com/2014/05/23/my-nfc-implant/

    • Cancel
    • Vote Up +6 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube