Connect MicroSD card to ardino rfid reader

Hello!

I have bought some parts to build an rfid reader.

You can find all info from here: http://www.jeremyblum.com/2011/07/08/tutorial-12-for-arduino-rfid-card-reading/

What I want to do next is to store the used tags on my rfid reader to be stored in an MicroSD card so that everytime anyone is using the tag on my rfid reader it wil store the tag ID to the microSD card. And for that i have bought a MicroSD Card Adapter v1.0 11/01/2013.

But I don’t know how to use it in the code that I got from the rfid reader project and witch pins should I use for the microSD card adapter?

This is the code I use:

//Jeremy Blum's Arduino Tutorial Series - Episode 12 - RFID Cards
//Sample Code - RFID Code Reading
//http://www.jeremyblum.com
//Some Code Adapted from http://www.cooking-hacks.com
//Code Updated on 1/21/2012 to comply with Arduino 1.0 Changes

 byte data[5];  //For holding the ID we receive
 int val = 0;
 byte jeremy[5] = {0x3E,0x00,0xFC,0xBD,0x88};
 byte david[5]  = {0x3E,0x00,0xFC,0xFF,0xA5};

 void setup()
 {
   // Start serial port 19200 bps
   Serial.begin(19200);
   
   // Setting Auto Read Mode - EM4102 Decoded Mode - No password
   // command: FF 01 09 87 01 03 02 00 10 20 30 40 37
   Serial.write(0xFF);  //Header
   Serial.write(0x01);  //Reserved
   Serial.write(0x09);  //Length (Command + Data)
   Serial.write(0x87);  //Command (0x87 sets auto mode behavior
   Serial.write(0x01);  //Data 1: Enable Auto-Read
   Serial.write(0x03);  //Data 2: Mode – Parity decoded – Manchester RF/64
   Serial.write(0x02);  //Data 3: Total number of block to be read (2)
   Serial.write((byte)0x00);  //Data 4: No password expected
   Serial.write(0x10);  //Data 5: Password byte 1
   Serial.write(0x20);  //Data 6: Password byte 2
   Serial.write(0x30);  //Data 7: Password byte 3
   Serial.write(0x40);  //Data 8: Password byte 4
   Serial.write(0x37);  //Checksum
   
   delay(500);
   while(Serial.available()>0)
   {
     Serial.read();
   }
   Serial.println();
   Serial.println("RFID module started in Auto Read Mode, Waiting for Card...");
 }

 void loop()
 {
 
   val = Serial.read();
   while (val != 0xff)
   {  //On Successful read, first byte will always be 0xFF
      val = Serial.read();
      delay(1000);
   }
   
   //we already read the header (0xff)
   Serial.read();              // reserved
   Serial.read();              // length
   Serial.read();              // command (indicates tag data)
   data[0] = Serial.read();    // we read data 1
   data[1] = Serial.read();    // we read data 2
   data[2] = Serial.read();    // we read data 3
   data[3] = Serial.read();    // we read data 4
   data[4] = Serial.read();    // we read data 5
   Serial.read();              // checksum
   
   // Indentify RFID Card
   boolean j_card = true;
   boolean d_card = true;
   Serial.print("Card found - Code: ");
   for (int i=0; i<5; i++)
   {
     if (data[i] < 16) Serial.print("0");
     Serial.print(data[i], HEX);
      
     //cross-check
     if (data[i] != jeremy[i]) j_card = false;
     if (data[i] != david[i]) d_card = false;
   }
   Serial.println();
   
   if (j_card) Serial.println("Hello Jeremy!");
   else if (d_card) Serial.println("Hello David!");
   else Serial.println("Not Recognized!  Get out of Here!");
   Serial.println();
 }

Please use code tags </> to inline code, not quote. You can edit your post accordingly.

The rfid is stored here:
byte data[5]; //For holding the ID we receive

This code at the end of loop() looks wrong to me:

   for (int i=0; i<5; i++)
   Serial.println();

IMO it should read

   for (int i=0; i<5; i++)
   Serial.println(data[i]); // or Serial.print(data[i],HEX);

Add your code here, to send the data to the SD card instead of or in addition to Serial.

Please use code tags </> to inline code, not quote. You can edit your post accordingly.

got that :smiley:

 for (int i=0; i<5; i++)
   Serial.println(data[i]); // or Serial.print(data[i],HEX);

So now that I have put in this code, what pins should I use for the microsd adapter?

got that

No, you don't. Please fix your post.

No, don't start a new thread. Edit your first post and fix it up.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Other thread deleted.

  • Moderator

New to the forum? Read this:

How to use this forum

Anyone that could help me?

[quote author=Nick Gammon link=msg=2385441 date=1441507900] No, don't start a new thread. Edit your first post and fix it up.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Other thread deleted.

  • Moderator

New to the forum? Read this:

How to use this forum

[/quote]

Thank you!

I figured out how to fix the post.

But could you help me with this project?

what pins should I use for the microsd adapter?

sd needs to use SPI pins - SCK, MISO, MOSI, and a chip select.

sd needs to use SPI pins - SCK, MISO, MOSI, and a chip select.

Alright!

but where should I put the vcc pin?

SD/uSD need 3.3V on power pin and 3.3V signals. Do you have a 3.3V supply and 3.3V buffers for SCK, MOSI, CS?

CrossRoads: SD/uSD need 3.3V on power pin and 3.3V signals. Do you have a 3.3V supply and 3.3V buffers for SCK, MOSI, CS?

Nope I don't have any buffer.

I use the pin MOSI to pin 11, MISO to 12, SCK to 13 and GND to GND on the arduino uno. I just don't know where to put the Vcc and CS pins.

Should I just use the second ICSP pins on the arduino board? It would make everything so much easier.

It would make everything so much easier.

No, they are wired up to the same pins. You have a 3V3 system with the SD card so you need to power it with 3V3. That means using a 3V3 regulator and capacitor to reduce the voltage and then resistive potential dividers to reduce the signals from the Arduino to the SD card but not when the signals are going the other way.

For an example see the schematic of the Adafruit wave shield.

Grumpy_Mike:
No, they are wired up to the same pins. You have a 3V3 system with the SD card so you need to power it with 3V3. That means using a 3V3 regulator and capacitor to reduce the voltage and then resistive potential dividers to reduce the signals from the Arduino to the SD card but not when the signals are going the other way.

For an example see the schematic of the Adafruit wave shield.

Well I found out that it has a built in regulator and all, so I don’t think I have to do that if I’m right.
-here is the link to that info: http://www.arduitronics.com/product/210/microsd-card-adapter-v1-1-catalex

If you guys could help me with the code at the same time you are helping me with the pinouts it would realy be a timesaver :slight_smile:

if you had posted that link at the start we all would have saved a lot of time.

I just don't know where to put the Vcc and CS pins.

Vcc to 5V CS to what ever pin you are going to use to select this SPI device. The normal one is pin 10 but it can be any pin. It should be an output and it is put low before accessing the SD card and high after. Normally the SD library will do this for you.

Jeremy Blum's Arduino Tutorial Series - Episode 12 - RFID Cards

While I have seen of his videos I have never seen any of his code. I am surprised how poor it is.

this bit of code is just rubbish:-

while (val != 0xff)
   {  //On Successful read, first byte will always be 0xFF
      val = Serial.read();
      delay(1000);
   }

//On Successful read, first byte will always be 0xFF//On Successful read, first byte will always be 0xFF

Crap, ---- on trying to read data from the buffer when there is no data in the buffer will read 0xff

Get some real code, See:- Open Access RFID

CS to what ever pin you are going to use to select this SPI device. The normal one is pin 10 but it can be any pin. It should be an output and it is put low before accessing the SD card and high after. Normally the SD library will do this for you.

how could I choose the pin I want? what codes should I be using and where shall I put them?

Can I just use this code?

const int chipSelect = 4;

And if I can, where should I put the code?

While I have seen of his videos I have never seen any of his code. I am surprised how poor it is.

Well I'm not after anything advanced right now becouse I just started and would like to keep going with this code so I can learn some stuff from it.

Now that the wiring is squared away, you need some SD code. I suggest the SDfat library that fat16lib maintains. There are example and test sketches there. https://github.com/greiman/SdFat

CrossRoads: Now that the wiring is squared away, you need some SD code. I suggest the SDfat library that fat16lib maintains. There are example and test sketches there. https://github.com/greiman/SdFat

Could you be more specific on what code I should be looking on?

I'm realy in a hurry as I have to finnish this project tomorrow so if you could help me making the full code in a faster way I would apreciate it.

Well I'm not after anything advanced right now

I am not talking about anything advanced I am talking about basic fundamental errors.

Can I just use this code?

Only if the variable chipSelect is used in the code when it comes to the data transfer.

The problem is that you have not posted any code nor have you given us any idea of what library you are using.

I have to finnish this project tomorrow

I think you should have started sooner. What is wrong with the open access code I pointed you to.

Only if the variable chipSelect is used in the code when it comes to the data transfer.

Don't know what you mean by that. Could you give me an example?

The problem is that you have not posted any code nor have you given us any idea of what library you are using.

Yes I have. The only code or anything else I am using is the code I have posted from the begining and need to add some codes so that I can store some RFID tags that are used in an SDcard.

I just want to know what code should I be using so when i use a tag on my rfid read it will automaticaly store the used rfid tag to the SDcard.

I think you should have started sooner. What is wrong with the open access code I pointed you to.

I'm not looking for another code to use I just need to add some code on the current code I'm using. It might not be anything wrong with it but I'm not sure if I could find anything from that code or use it on my rfid reader.