Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Object for NPX's MFRC522 MIFARE 13.56MHz RFID Readers - Page 2 — Parallax Forums

Propeller Object for NPX's MFRC522 MIFARE 13.56MHz RFID Readers

2»

Comments

  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2014-06-12 14:02
    Duane Degn wrote: »
    I purchased a couple from this seller since they were in the US and I was hoping to get the readers fast.

    I received a reader from Electrodragon yesterday. If you're interested in purchasing a reader from Electrodragon, let me know and I'll test mine.

    Sorry to ask this, I'm betting you already know, but just to be sure, you're using the 13.56MHz Cards right? The Parallax cards won't work with these readers,

    Yeah - they come with a card and key FOB. I contacted chip_partner at ebay to see if anyone else has had a problem with the modules.

    I may just toss them and forget about it...

    Your modules from cenn2010 look identical.
  • Michel LMichel L Posts: 141
    edited 2014-06-12 14:14
    Yeah - they come with a card and key FOB. I contacted chip_partner at ebay to see if anyone else has had a problem with the modules.

    I may just toss them and forget about it...

    Your modules from cenn2010 look identical.

    For a project I did with a colleague using RFID I used this same module (bought also from chip_partner as far as I can remember) together with a RaspberryPi. All my 3 units worked without problems (used in a dancing as member cards, giving more then 500 scans a night).
    I never wrote anything into the cards, I only read the UID's so I can't say if writing works or not.

    I'm glad that someone is writing an object for this. I'd love to reuse my readers with the propeller.
  • vanmunchvanmunch Posts: 568
    edited 2014-06-18 11:22
    Hey Ron, I'm sorry to hear that they're not working for you. In the picture it looks like your MOSI jumper is sticking out a bit from the breadboard? I'm curious what the light source is that's illuminating the lower right mounting hole? (I don't think it's the LED on the board because I can't get mine to reflect that same way.) My other suggestion is to check out the solder joints and make sure you have good contact and no bridging. I'm guessing that you've already tried these things, but just in case.... :)

    Hey Duane, is there any chance you could post your code where you're able to read data from the cards using the propeller? It would be really helpful for a project I'm working on. Thanks again for all of your great work with these readers!

    Dave
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2014-06-18 13:35
    vanmunch wrote: »
    Hey Ron, I'm sorry to hear that they're not working for you. In the picture it looks like your MOSI jumper is sticking out a bit from the breadboard? I'm curious what the light source is that's illuminating the lower right mounting hole? (I don't think it's the LED on the board because I can't get mine to reflect that same way.) My other suggestion is to check out the solder joints and make sure you have good contact and no bridging. I'm guessing that you've already tried these things, but just in case.... :)

    Hey Duane, is there any chance you could post your code where you're able to read data from the cards using the propeller? It would be really helpful for a project I'm working on. Thanks again for all of your great work with these readers!

    Dave

    Thanks Dave -

    The MOSI connection was okay - I actually tried it using a different Propeller board and breadboard setup.
    The green led reflection is from the power LED on the Activity Board. Just got some bad boards it seems.

    - Ron
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-18 13:52
    vanmunch wrote: »
    Hey Duane, is there any chance you could post your code where you're able to read data from the cards using the propeller? It would be really helpful for a project I'm working on. Thanks again for all of your great work with these readers!

    I've had my MFRC522 board in front of me most of the week. I keep thinking I'm an hour away to getting back to work on this. I'll post something by the end of the day tomorrow. Hopefully I'll have time to clean it up a bit before then so it's not so embarrassing to post. (Don't say "no hurry". If I don't have a deadline, it's much less likely to get done.)

    I'll also post the Arduino code which can read and write data to the cards.
  • vanmunchvanmunch Posts: 568
    edited 2014-06-19 06:00
    Duane Degn wrote: »
    I've had my MFRC522 board in front of me most of the week. I keep thinking I'm an hour away to getting back to work on this. I'll post something by the end of the day tomorrow. Hopefully I'll have time to clean it up a bit before then so it's not so embarrassing to post. (Don't say "no hurry". If I don't have a deadline, it's much less likely to get done.)

    I'll also post the Arduino code which can read and write data to the cards.

    AHHHHHHHH!!!!! WORLD ENDING DISASTER* IF TODAYS' DEADLINE IS MISSED!!!!! AHHHHHHHH!!!!!!

    *feel free to insert your favorite disaster for inspiration :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-10-23 20:52
    Well darn. I apparently didn't find the right pair of Arduino and Propeller files which will let the Arduino write to the cards and have the Propeller read from the card.

    The Propeller says all the data read (from only one sector) are zeros. I don't think this is correct.

    I'll look at this again in the morning. Hopefully your reactor won't meltdown (disaster of choice) before I get a working version to you tomorrow.

    I know I've had the Arduino write data to the cards and have been able to read the data from the card with the Propeller. I'll double check passwords etc. in the morning.

    I don't think the attached code is worth downloading. I will post more code tomorrow (hopefully working).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-06-22 11:50
    Okay, I think I'm getting my head back around how these things work.

    The Arduino code above only writes to memory locations 8 - 15 (of a possible 64 locations).
    for (i=8; i<16; i++)
          {  
            if (i % 4 != 3)
            {
              Write(i, writeData[dataIndex], sectorKeyA[0], sectorNewKeyA[1]);
              if (dataIndex == 9)
              {
                dataIndex = 0;
              }
              else
              {
                dataIndex++;
              }  
            }
          }
    

    The "dataIndex" is an variable to indicate which set of 16 characters to write to the card.

    The attached Propeller program will read the data from these locations.

    The program starts with "Press any key to begin" messages. Once a key is pressed the following message and menu is displayed.
    Program Name = Mfrc522Demo140622dRFID 
    Object Name = Mfrc522_140323b
    MFRC522 SPI Interface Demonstration Program
    
    
    Initializing RFID Reader
    
    
         Top Menu
    
    
    Please Select Which Submenu to Use
    Use "X" to return to this top menu.
    A) take Action based on which card is found
    R) Read from card
    W) Write to card
    T) Test new features
    D) simple Demo (programmed test stuff)
    

    The only menu option which currently works is "D" (upper or lowercase).

    The card with the data to be read needs to be already against the reader prior to pressing "d".

    Once "d" is selected (assuming the card has been written to with the above Arduino code), the following output will be given.
    Card detected, type = $0400
    The card's number is  : $XXXXXXXX
    Card's CRC value = $53
    Calculated checksum = $53
    Card Data Successfully Read
    Checking to see if card can be identified.
    Card $XXXXXXXX has a memory of 8 units.
    Checking password
    Password Block = 11
    Successful Read
    Data As Hex =
    $5A,  $65,  $72,  $6F,  $20,  $20,  $20,  $20,  $20,  $31,  $34,  $30,  $34,  $31,  $36,  $61,
    $00,
    Data As Text = Zero     140416a
    Checking password
    Password Block = 11
    Successful Read
    Data As Hex =
    $4F,  $6E,  $65,  $20,  $20,  $20,  $20,  $20,  $20,  $31,  $34,  $30,  $34,  $31,  $36,  $61,
    $00,
    Data As Text = One      140416a
    Checking password
    Password Block = 11
    Successful Read
    Data As Hex =
    $54,  $77,  $6F,  $20,  $20,  $20,  $20,  $20,  $20,  $31,  $34,  $30,  $34,  $31,  $36,  $61,
    $00,
    Data As Text = Two      140416a
    Checking password
    Password Block Skipped (no data stored here)
    Checking password
    Password Block = 15
    Successful Read
    Data As Hex =
    $54,  $68,  $72,  $65,  $65,  $20,  $20,  $20,  $20,  $31,  $34,  $30,  $34,  $31,  $36,  $61,
    $00,
    Data As Text = Three    140416a
    Checking password
    Password Block = 15
    Successful Read
    Data As Hex =
    $46,  $6F,  $75,  $72,  $20,  $20,  $20,  $20,  $20,  $31,  $34,  $30,  $34,  $31,  $36,  $61,
    $00,
    Data As Text = Four     140416a
    Checking password
    Password Block = 15
    Successful Read
    Data As Hex =
    $46,  $69,  $69,  $76,  $65,  $20,  $20,  $20,  $20,  $31,  $34,  $30,  $34,  $31,  $36,  $61,
    $00,
    Data As Text = Fiive    140416a
    Checking password
    Password Block Skipped (no data stored here)
    ****** Unknown card ******
    You might want to write this number down in order
    to add it to the program's choices.
    $XXXXXXXX
    
    
    

    The data is displayed in both hexadecimal and as ASCII characters. Notice of eight locations to read, only six contained useful data (two locations contain passwords).

    The Arduino program used this array to load the original data to the card.
    uchar  writeData[10][16] ={{'Z', 'e', 'r', 'o', ' ', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'O', 'n', 'e', ' ', ' ', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'T', 'w', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'T', 'h', 'r', 'e', 'e', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'F', 'o', 'u', 'r', ' ', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'F', 'i', 'i', 'v', 'e', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'S', 'i', 'x', ' ', ' ', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'S', 'e', 'v', 'e', 'n', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'E', 'i', 'g', 'h', 't', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'},
                            {'N', 'i', 'n', 'e', ' ', ' ', ' ', ' ', ' ', '1', '4', '0', '4', '1', '6', 'a'}};
    

    (No, I don't know why "Fiive" is in there.) The card's memory is divided up into "sectors" and "blocks". There are 16 sectors in an original Mifare card. Each sector contains 4 blocks each block contains 16 bytes. You'll often see the cards listed as having 1KBytes (16 * 4 * 16 = 1024) but one of the four blocks in each sector contains the password information and can't be used for data storage. The first block on the card holds the card's serial number and other read only information so that's another 16 bytes not available for storage. After deducting these unusable locations, you're left with 752 bytes.

    Both the Arduino code and the Propeller code use a memory address system which numbers each block from zero to 63. The first code block of this post shows the Arduino code to write to memory locations 8 through 15. Location 8 corresponds to sector 2 block 0. Memory location 15 is sector 3 block 3. Since location 15 is block #3 of the sector, the program will not write to the sector since it contains the password and can not be written to without a special change password command.

    The Spin code to read from these locations starts with:
    repeat memoryIndex from 8 to 15
    

    Here I just hard coded the memory locations to read as a quick test to see if the read section of the code was working.

    To read a memory location, the password has to be checked against the password held in block #3 of the sector to be read.

    There are two passwords for each sector. One password allows one to both read and write to the sector, while the second password allows read only access.

    Both the Arduino code and the Propeller code use $FF for each of the password bytes (IIRC passwords are 6 bytes long).

    I know I've been able to get the Arduino to change the password of a card and I plan to add this feature to the Propeller code but first, I want to get the Propeller code to write to the cards.

    As you can see from this post, I'm hoping to have a menu system to select what sorts of actions to take. I originally planned to allow the memory locations to be read and/or written to be entered through the terminal. I may make these parameters constants just to keep the complexity of the program down to a reasonable level. Data to be written to the cards will probably stored in the DAT section.

    I'm still debating about what sort of password features to include. Each of the 16 sectors can have their own passwords. I think initially, I'll just use a single password for the whole card or I may make an array of 96 bytes to hold 16 six byte passwords.

    Edit: Deleted attached program. The program in post #40 can both read and write. The program attached to this post (Mfrc5221406Demo140622d) had 0 views.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-10-23 20:52
    I was able to get the program to write to the cards.

    There are now two options in the menu.
    Top Menu
    
    Please Select Which Submenu to Use
    Use "X" to return to this top menu.
    T) Test new features
    D) simple Demo (programmed test stuff)
    

    The "Test new features" will write to memory locations 16 through 24 (really to location 23 since 24 is a password location). "simple Demo" will read from these same locations.

    The locations written to and read from are set with the constants "FIRST_READ_LOCATION" and "LAST_READ_LOCATION".

    The data written to the card is in the DAT section under "otherData".

    My earlier trouble with writing data to the card came from not having enough room in my temporary buffer. I hadn't left room for the check sum.

    The current code includes I/O pins I used to trigger my logic analyzer. I'll post a cleaner version in the near future.

    For some reason, the choices in the top menu are only good once per reset. You can select "t" or "d" and your choice should work the first time but subsequent choices don't work. If the Propeller is reset, then another choice may be made. It might work if a second card were held against the reader but I haven't tested this. I'll get this bug figured out asap.
  • GarethGareth Posts: 278
    edited 2014-07-11 08:13
    Perfect once again Duane..... Just picked up one of these 522 units (could not resist)
    Your code works every time YAY ... and the unit is sensitive to 4cm.....
    I have an old type RFID attached to my main door (which works....) however I am tempted to change it now due to the sensitivity of the 522.
    Now "G" wonders why he did not get more "Chips"
    Best Regards ....
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-11 08:27
    Gareth wrote: »
    Perfect once again Duane..... Just picked up one of these 522 units (could not resist)
    Your code works every time YAY ... and the unit is sensitive to 4cm.....
    I have an old type RFID attached to my main door (which works....) however I am tempted to change it now due to the sensitivity of the 522.
    Now "G" wonders why he did not get more "Chips"
    Best Regards ....

    Very good to hear G.

    These things work really well. I picked up some extra cards at ElectroDragon. I think there are less expensive sources but ElectroDragon seems like a good place to me.

    I still need/want to figure out the whole password thing for these devices. I know I was able to change the password to a sector with the Arduino code but I'm not sure how. If the password section were in place, one could use these to hold "money" of sorts.
Sign In or Register to comment.