Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Home

angus71


  • angus71
    angus71
    2012-01-20

    Welcome to the Smartcard Lib for Arduino compatible boards wiki.

    Currently this is a project I'm working on to learn more about the Ardunio programming and interfacing to external hardware.

    As it might be quite hard to setup a complete smart card reader for the Arduino from scratch, I just looked around and found a old settop box, which had a seperate module to interface with the smart card.

    All the documentation and data sheets I read, had a lot to say about high frequency and other effects, you can face if you use chips like the TDA 8204T to interface with a smart card.

    This library can be used to talk to a directly to the Arduino board connected smartcard or a smartcard connected via a TDA 8204T (or compatible).

    Per default the library behaves, like the smartcard is directly connected to the Ardunio board, as this is the default for the most people (The connection is described in the schematic attached to a post below).

    I that you actually don't need a TDA 8204T or any other chip to talk to a smart card, as you can connect the smart card directly to the I/O pins of the Arduino board, but with the interface chip it's just safer for my Arduino board and my smart cards.

    Setup

    As per release 0.0.4, the default behaviour is changed to a directly connected smartcard and the TDA 8204T interface needs to be activated via a define in the code.

    See the attached schematic, how the signals need to be connected to the Arduino board.

    Smartcard Arduino UNO
    C1(Vcc) D11
    C2(RST) D7
    C3(CLK) D9
    C4(AUX1) N.C.
    C5(GND) GND
    C6(Vpp) N.C
    C7(I/O) D10
    C8(AUX2) N.C.
    SWITCH D8

    Currently the C3(CLK) - D9 connection is hard coded, as I didn't found a way to get the timer associated with a pin and access the registers. The D9 pin is used to generate a clock signal for the smart card.

    To have defined values for the C3(RST) and C7(I/O) signales I used 100k pull-up resistors and a 100k pull-down resistor for the switch signaling that the smardcard is inserted into the smartcard slot

    If USE_DEBUG_PIN is enabled, which is by default, the D13 is used to signal changes in the internal state machines. Used to trigger my logic state analyser.

    It is also possible to minimize the binary size, by enable synchronous or asynchronous communication in the header file.

     
    Last edit: angus71 2012-07-22
    • I would like to test your code, but I do not have a smart card reader. Do you know where I could find a simple schematic to connect smartcard directly arduino board??

       
      • angus71
        angus71
        2012-02-07

        The easiest way to get to this information would be the article about smart cards in wikipedia. In the english version is a pin out given and with the provided table it should be possible to connect it directly to the arduino board (See attached schematic)

        Smart Card Arduino (Based on the above given table)
        C1 - VCC D11 (!CMDVCC) *
        C2 - RST D7 (RSTIN)
        C3 - CLK D9 (XTAL1)
        C4 - Not Connected
        C5 - GND GND
        C6 - VPP Not Connected
        C7 - I/O D10 (I/OUC)
        C8 - Not Connected

        * With the new release 0.0.4 this works right out of the box, as direct connection is the default.

         
        Last edit: angus71 2012-07-22
  • tavovalencia
    tavovalencia
    2013-01-21

    Hi Angus, I'm really very interested in this project!! Thanks

    I have a doubt. My SC Connection switch is always closed and opens when the card is inserted, thereby if I connect the switch in a pull-down, it thinks that there are no-card-inserted when there actually is. I modified my connection to pull-up resistor by connecting as follow:

    * SWITCH 1 to GND
    * SWITCH 2 to (between D8 and 1K resistor that goes to 5V).
    

    Now it tries to read the card every-time I insert a card. However, each time I have inserted a card the following pattern happens:

    * Waiting for Smartcard
    * Smartcard found
    * Unable to identify card ... Please remove
    

    Not really sure what I'm doing wrong!

     
    Last edit: tavovalencia 2013-01-21
    • angus71
      angus71
      2013-01-21

      Hi tavovalencia,

      I think you should try a revision >= 20 from the trunk SCLib.h & SCLib.cpp as I added a feature to invert the card recognition (Parameter off_invert of the constructer set to true) after I've purchased a smartcard slot with the same switch behaviour as yours. That should do the trick, if go back to the pull down configuration.

      If you have further question just send me a mail.

       
      • tavovalencia
        tavovalencia
        2013-01-21

        Hi Angus,
        I don't know your email, so I'll continue with this thread.

        After I downloaded both files, I tried both ways with the pull-down (left on the attached image), It continuously said "waiting for Smartcard" (not recognizing it), and with pull-up (right on the attached image).

        It appears that the original circuit (on the left) can't work with my socket, not even with the new libraries, however, I kind of had a better result with the other schem:

        I started with the SCTest. -> The card was now found and the serial monitor showed:

        //Inserted CARD #1
        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        //After a couple of seconds repeats the same
        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        // Here I changed the cards (2nd)
        Smartcard found
        00|92 23 10 91 '.#..............'

        Waiting for Smartcard

        // Here I changed the cards (3rd)
        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        The good news is that three different smartcards were apparently recognized with 4-bytes each. But it kind of crashes after the 4th byte. I have to take the card out and re-enter it.

        When testing on the SCTest2 the thing is different. Once I entered the SC in the socket it read the card once and printed into serial monitor:

        Smartcard found
        Received ATR ...
        00|0C 02 0C 01 '................'
        SELECT FILE Command ...
        Received ... 0
        Waiting for Smartcard

        This happened VERY fast I tested this several times and after the "Waiting for Smartcard" print, I couldn't change the smartcard and have new readings without reseting the Arduino.

        I'm not sure but in both cases it seems like only the first 4 bytes are transmitted, then the program continues the loop without delays or without prompting anything... Is this right?

        PS> Link to Attached Image

         
        Last edit: tavovalencia 2013-01-21
        Attachments
        • angus71
          angus71
          2013-01-22

          Hi tavovalencia,

          If the ATR's you receive are correct, they lead to the point that you are using synchronus cards, as they normaly only have a 4 byte ATR. .. Like SL4432/SL4442 or other memory cards, which can be found often as keycards in hotels, member cards etc.

          Do you have additional information regarding the type of the card? I think, if the cards you used are synchrous, everything worked fine and now the protocol implementation has to be done to support the card type you want to use.
          I'm currently implementin a SL4432/SL4442 support class, which provides all the features of this card type for easy usage.

          So to have your problems fixed I think i have to ask some questions ;-.)

          1. What kind of Arduino are you using?

          There might be a problem, when using a Arduino Mega compatible board as the CLK Pin has to be moved from Digital 9 to Digital 11 and the function of the Digital 11 (Vcc) can be moved to every other digital pin avaialable (The CLK pin is tied to the TIMER1A and the output pin of the timer was moved).

          1. Do you have more information regarding the type and protocol of the cards you want to use?

          The SCTest2 is only working with asynchrous cards of protocol type T=0, that's the reason, why you might get the "Received .. 0" as the APDU command format is not supported by all the synchronous cards I know :-(

          I will have a look into the problem of the need to reset the Arduino this condition, that should not happen and I will rename/comment the examples a little bit better to have them more intuitive.

          Can you please send me the answers via the "Send me a message" form on my users page or open a discussion in the genral discusion form, as I don't think tha communication through the wiki is a good idea ;-.)

          regards,

          Angus

           
  • Prem
    Prem
    2013-02-21

    Hi Angus,
    I'm doing a work with SIM card, i want to copy the entire phonebook and message from one sim to another with arduino. Is it possible to use this library for the purpose?? how can i access and copy the phonebook and message location in the sim card?
    plz help me
    thank you :)

     
  • pedro
    pedro
    2013-11-26

    Oi amigos, pode me ajudar como faço para ler minha lista telefonica com arduino, o codigo fonte ja funciona mas agenda do sim card teria como ler?

     
    Last edit: pedro 2013-11-26