Kendi sitesinden aldığım kod derleme sırasında hata veriyor. http://playground.arduino.cc/Learning/MFRC522 (http://playground.arduino.cc/Learning/MFRC522)
/*
* MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
* The library file MFRC522.h has a wealth of useful info. Please read it.
* The functions are documented in MFRC522.cpp.
*
* Based on code Dr.Leong ( [url=http://WWW.B2CQSHOP.COM]WWW.B2CQSHOP.COM[/url] )
* Created by Miguel Balboa (circuitito.com), Jan, 2012.
* Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013 (Translation to English, refactored, comments, anti collision, cascade levels.)
* Released into the public domain.
*
* Sample program showing how to read data from a PICC using a MFRC522 reader on the Arduino SPI interface.
*----------------------------------------------------------------------------- empty_skull
* Aggiunti pin per arduino Mega
* add pin configuration for arduino mega
* http://mac86project.altervista.org/
----------------------------------------------------------------------------- Nicola Coppola
* Pin layout should be as follows:
* Signal Pin Pin Pin
* Arduino Uno Arduino Mega MFRC522 board
* ------------------------------------------------------------
* Reset 9 5 RST
* SPI SS 10 53 SDA
* SPI MOSI 11 51 MOSI
* SPI MISO 12 50 MISO
* SPI SCK 13 52 SCK
*
* The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
[b]MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.[/b]
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
(http://s1.postimg.cc/5a9a9lwx7/Ekran_Al_nt_s.jpg) (http://postimg.cc/image/5a9a9lwx7/)
Kütüphaneyi ; Belgelerim içinde bulunan Arduino klasörü içindeki examples veya library içine atıp oradan çalıştırın.
Veya kütüphane dosyasını kendi Program Files klasörü içindeki lib klasörü içine yükleyin.
[b] MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.[/b]
hata buradaki satırdan kaynaklanıyor
[b]
yazan yeri sil.
Ek :
siz o yazıyı sildi iseniz ve hala düzelmedi ise derleyciyi kapatın
https://github.com/miguelbalboa/rfid
buradan kütüphaneyi indirin açın ve "Belgelerim" klasörü içindeki "Arduino" klasörün içinde "libraries" klasörü içine kopyalayın.
Derleyiciyi tekrar çalıştırın. Kodu derleyin.
Programı "Libraries" içine atınca çalıştı.
Fakat kart çalışmadı. Elimde Çin kopyası Arduino Mega 2560 var. Pinlerini Programda verildiği gibi değiştirdim.
Bir yerde yanlışım olmalı
* Typical pin layout used:
* ------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3
* Signal Pin Pin Pin Pin
* ------------------------------------------------------------
* RST/Reset RST 9 5 D9
* SPI SS SDA(SS) 10 53 D10
* SPI MOSI MOSI 11 / ICSP-4 51 D11
* SPI MISO MISO 12 / ICSP-1 50 D12
* SPI SCK SCK 13 / ICSP-3 52 D13
-----------------------------------------------------------------------------------------------------------------------------------
Benim bağlantım:
RC522 MEGA
------- ------
SDA 53
SCK 52
MOSI 51
MISO 50
IRQ BOŞ
GND GND
RST PWM 5
3.3V 3.3V
Bağlantılarım doğrumu' dur.
Program üzerindende pin numaralarını MEGA' ya göre değiştirdim.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 //
#define SS_PIN 53 //
mesaj birleştirme:: 27 Aralık 2014, 11:24:26
Kartı yeniden başlatınca çalıştı.
mesaj birleştirme:: 26 Aralık 2014, 21:31:19
MFRC522 Software Version: 0x91 = v1.0
Scan PICC to see UID, type, and data blocks...
Card UID: EE 33 CA 55
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
14 59 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
13 55 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
53 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
12 51 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
49 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
11 47 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
10 43 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
9 39 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
8 35 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
7 31 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
29 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
28 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
6 27 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
26 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
25 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
5 23 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
4 19 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
3 15 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
2 11 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
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 ]
0 3 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
0 EE 33 CA 55 42 88 04 00 85 00 B4 2E F0 BB 6A A8 [ 0 0 0 ]
bir kaç sn sonunda okuduğu kodlar bunlar.
Tebrikler ;
Artık mifare'ın detaylarına inebilirsiniz. Aşağıdaki linki iyice inceleyip anlamaya çalışmanızı öneririm.
https://www.picproje.org/index.php?topic=52963.0 (https://www.picproje.org/index.php?topic=52963.0)
Şimdi yapmak istediğim Ardunio içine sadece bir kart kodunu tanıtıp başka bir kart kodunda işlem yapmamasını istiyorum.
Ardunio sadece kendine ait kart kodunu okuyunca PWM13 çıkışındaki sarı led' i 1 sn yakacak.
MFRC522 Software Version: 0x91 = v1.0
Scan PICC to see UID, type, and data blocks...
Card UID: EE 33 CA 55
PICC type: MIFARE 1KB
Kütüphane içinde birkaç tane kod örneği var, hatta istersen içine şifre yazıp, okuyabilirsin
Ama başka bir şeyle değil de kartın kendisi için ise Card UID için
mfrc522.uid.uidByte, mfrc522.uid.size parametreleri var.Sanırım bunları başta okunuyor. Bir şekilde bunlar kullanılabilir sanırım.
Deneme şansım yok tabii..
delete
Kodlarınızı, kod bloğu (kod ekle butonu ile) içine almanız mümkün mü?
Bu şekilde takip etmek bir zor oluyor. Daha doğrusu yazdığınız mesajlara odaklanmak zorlaşıyor.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 //
#define SS_PIN 10 //
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
Serial.println("Scan PICC to see UID, type, and data blocks...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
void ShowReaderDetails() {
// Get the MFRC522 software version
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("MFRC522 Software Version: 0x");
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(" = v1.0");
else if (v == 0x92)
Serial.print(" = v2.0");
else
Serial.print(" (unknown)");
Serial.println("");
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) {
Serial.println("WARNING: Communication failure, is the MFRC522 properly connected?");
}
}
mesaj birleştirme:: 27 Aralık 2014, 13:37:07
---------------------------------------------------------------------------------------------------------------------------
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
MFRC522::MIFARE_Key key;
/**
* Initialize.
*/
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
// Prepare the key (used both as key A and as key B)
// using FFFFFFFFFFFFh which is the default at chip delivery from the factory
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
Serial.println("Scan a MIFARE Classic PICC to demonstrate Value Block mode.");
Serial.print("Using key (for A and B):");
dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
Serial.println();
Serial.println("BEWARE: Data will be written to the PICC, in sector #1");
}
/**
* Main loop.
*/
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;
// Show some details of the PICC (that is: the tag/card)
Serial.print("Card UID:");
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
Serial.print("PICC type: ");
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Check for compatibility
if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
&& piccType != MFRC522::PICC_TYPE_MIFARE_1K
&& piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println("This sample only works with MIFARE Classic cards.");
return;
}
// In this sample we use the second sector,
// that is: sector #1, covering block #4 up to and including block #7
byte sector = 1;
byte valueBlockA = 5;
byte valueBlockB = 6;
byte trailerBlock = 7;
byte status;
byte buffer[18];
byte size = sizeof(buffer);
long value;
// Authenticate using key A
Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Show the whole sector as it currently is
Serial.println("Current data in sector:");
mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
Serial.println();
// We need a sector trailer that defines blocks 5 and 6 as Value Blocks and enables key B
// The last block in a sector (block #3 for Mifare Classic 1K) is the Sector Trailer.
// See http://www.nxp.com/documents/data_sheet/MF1S503x.pdf sections 8.6 and 8.7:
// Bytes 0-5: Key A
// Bytes 6-8: Access Bits
// Bytes 9: User data
// Bytes 10-15: Key B (or user data)
byte trailerBuffer[] = {
255, 255, 255, 255, 255, 255, // Keep default key A
0, 0, 0,
0,
255, 255, 255, 255, 255, 255}; // Keep default key B
// The access bits are stored in a peculiar fashion.
// There are four groups:
// g[0] Access bits for block 0 (for sectors 0-31)
// or blocks 0-4 (for sectors 32-39)
// g[1] Access bits for block 1 (for sectors 0-31)
// or blocks 5-9 (for sectors 32-39)
// g[2] Access bits for block 2 (for sectors 0-31)
// or blocks 10-14 (for sectors 32-39)
// g[3] Access bits for the Sector Trailer: block 3 (for sectors 0-31)
// or block 15 (for sectors 32-39)
// Each group has access bits [C1 C2 C3], in this code C1 is MSB and C3 is LSB.
// Determine the bit pattern needed using MIFARE_SetAccessBits:
// g0=0 access bits for block 0 (of this sector) using [0 0 0] = 000b = 0
// which means key A|B have r/w for block 0 of this sector
// which (in this example) translates to block #4 within sector #1;
// this is the transport configuration (at factory delivery).
// g1=6 access bits for block 1 (of this sector) using [1 1 0] = 110b = 6
// which means block 1 (of this sector) is used as a value block,
// which (in this example) translates to block #5 within sector #1;
// where key A|B have r, key B has w, key B can increment,
// and key A|B can decrement, transfer, and restore.
// g2=6 same thing for block 2 (of this sector): set it to a value block;
// which (in this example) translates to block #6 within sector #1;
// g3=3 access bits for block 3 (of this sector): the Sector Trailer here;
// using [0 1 1] = 011b = 3 which means only key B has r/w access
// to the Sector Trailer (block 3 of this sector) from now on
// which (in this example) translates to block #7 within sector #1;
mfrc522.MIFARE_SetAccessBits(&trailerBuffer[6], 0, 6, 6, 3);
// Read the sector trailer as it is currently stored on the PICC
Serial.println("Reading sector trailer...");
status = mfrc522.MIFARE_Read(trailerBlock, buffer, &size);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Read() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Check if it matches the desired access pattern already;
// because if it does, we don't need to write it again...
if ( buffer[6] != trailerBuffer[6]
&& buffer[7] != trailerBuffer[7]
&& buffer[8] != trailerBuffer[8]) {
// They don't match (yet), so write it to the PICC
Serial.println("Writing new sector trailer...");
status = mfrc522.MIFARE_Write(trailerBlock, trailerBuffer, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
}
// Authenticate using key B
Serial.println("Authenticating again using key B...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// A value block has a 32 bit signed value stored three times
// and an 8 bit address stored 4 times. Make sure that valueBlockA
// and valueBlockB have that format (note that it will only format
// the block when it doesn't comply to the expected format already).
formatValueBlock(valueBlockA);
formatValueBlock(valueBlockB);
// Add 1 to the value of valueBlockA and store the result in valueBlockA.
Serial.print("Adding 1 to value of block "); Serial.println(valueBlockA);
status = mfrc522.MIFARE_Increment(valueBlockA, 1);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Increment() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Transfer(valueBlockA);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Transfer() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Show the new value of valueBlockA
status = mfrc522.MIFARE_GetValue(valueBlockA, &value);
if (status != MFRC522::STATUS_OK) {
Serial.print("mifare_GetValue() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
Serial.print("New value of value block "); Serial.print(valueBlockA);
Serial.print(" = "); Serial.println(value);
// Decrement 10 from the value of valueBlockB and store the result in valueBlockB.
Serial.print("Subtracting 10 from value of block "); Serial.println(valueBlockB);
status = mfrc522.MIFARE_Decrement(valueBlockB, 10);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Decrement() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Transfer(valueBlockB);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Transfer() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Show the new value of valueBlockB
status = mfrc522.MIFARE_GetValue(valueBlockB, &value);
if (status != MFRC522::STATUS_OK) {
Serial.print("mifare_GetValue() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
Serial.print("New value of value block "); Serial.print(valueBlockB);
Serial.print(" = "); Serial.println(value);
// Check some boundary...
if (value <= -100) {
Serial.println("Below -100, so resetting it to 255 = 0xFF just for fun...");
status = mfrc522.MIFARE_SetValue(valueBlockB, 255);
if (status != MFRC522::STATUS_OK) {
Serial.print("mifare_SetValue() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
}
// Dump the sector data
mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
Serial.println();
// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/**
* Ensure that a given block is formatted as a Value Block.
*/
void formatValueBlock(byte blockAddr) {
byte buffer[18];
byte size = sizeof(buffer);
byte status;
Serial.print("Reading block "); Serial.println(blockAddr);
status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Read() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
if ( (buffer[0] == (byte)~buffer[4])
&& (buffer[1] == (byte)~buffer[5])
&& (buffer[2] == (byte)~buffer[6])
&& (buffer[3] == (byte)~buffer[7])
&& (buffer[0] == buffer[8])
&& (buffer[1] == buffer[9])
&& (buffer[2] == buffer[10])
&& (buffer[3] == buffer[11])
&& (buffer[12] == (byte)~buffer[13])
&& (buffer[12] == buffer[14])
&& (buffer[12] == (byte)~buffer[15])) {
Serial.println("Block has correct Value Block format.");
}
else {
Serial.println("Formatting as Value Block...");
byte valueBlock[] = {
0, 0, 0, 0,
255, 255, 255, 255,
0, 0, 0, 0,
blockAddr, ~blockAddr, blockAddr, ~blockAddr };
status = mfrc522.MIFARE_Write(blockAddr, valueBlock, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
}
}
}
mesaj birleştirme:: 27 Aralık 2014, 13:38:03
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
MFRC522::MIFARE_Key key;
/**
* Initialize.
*/
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
// Prepare the key (used both as key A and as key B)
// using FFFFFFFFFFFFh which is the default at chip delivery from the factory
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
Serial.println("Scan a MIFARE Classic PICC to demonstrate read and write.");
Serial.print("Using key (for A and B):");
dump_byte_array(key.keyByte, MFRC522::MF_KEY_SIZE);
Serial.println();
Serial.println("BEWARE: Data will be written to the PICC, in sector #1");
}
/**
* Main loop.
*/
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;
// Show some details of the PICC (that is: the tag/card)
Serial.print("Card UID:");
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
Serial.print("PICC type: ");
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Check for compatibility
if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
&& piccType != MFRC522::PICC_TYPE_MIFARE_1K
&& piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println("This sample only works with MIFARE Classic cards.");
return;
}
// In this sample we use the second sector,
// that is: sector #1, covering block #4 up to and including block #7
byte sector = 1;
byte blockAddr = 4;
byte dataBlock[] = {
0x01, 0x02, 0x03, 0x04, // 1, 2, 3, 4,
0x05, 0x06, 0x07, 0x08, // 5, 6, 7, 8,
0x08, 0x09, 0xff, 0x0b, // 9, 10, 255, 12,
0x0c, 0x0d, 0x0e, 0x0f // 13, 14, 15, 16
};
byte trailerBlock = 7;
byte status;
byte buffer[18];
byte size = sizeof(buffer);
// Authenticate using key A
Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Show the whole sector as it currently is
Serial.println("Current data in sector:");
mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
Serial.println();
// Read data from the block
Serial.print("Reading data from block "); Serial.print(blockAddr);
Serial.println(" ...");
status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Read() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
}
Serial.print("Data in block "); Serial.print(blockAddr); Serial.println(":");
dump_byte_array(buffer, 16); Serial.println();
Serial.println();
// Authenticate using key B
Serial.println("Authenticating again using key B...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Write data to the block
Serial.print("Writing data into block "); Serial.print(blockAddr);
Serial.println(" ...");
dump_byte_array(dataBlock, 16); Serial.println();
status = mfrc522.MIFARE_Write(blockAddr, dataBlock, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
}
Serial.println();
// Read data from the block (again, should now be what we have written)
Serial.print("Reading data from block "); Serial.print(blockAddr);
Serial.println(" ...");
status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Read() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
}
Serial.print("Data in block "); Serial.print(blockAddr); Serial.println(":");
dump_byte_array(buffer, 16); Serial.println();
// Check that data in block is what we have written
// by counting the number of bytes that are equal
Serial.println("Checking result...");
byte count = 0;
for (byte i = 0; i < 16; i++) {
// Compare buffer (= what we've read) with dataBlock (= what we've written)
if (buffer[i] == dataBlock[i])
count++;
}
Serial.print("Number of bytes that match = "); Serial.println(count);
if (count == 16) {
Serial.println("Success :-)");
} else {
Serial.println("Failure, no match :-(");
Serial.println(" perhaps the write didn't work properly...");
}
Serial.println();
// Dump the sector data
Serial.println("Current data in sector:");
mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
Serial.println();
// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
}
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
mesaj birleştirme:: 27 Aralık 2014, 13:38:48
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
// Number of known default keys (hard-coded)
// NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array
#define NR_KNOWN_KEYS 8
// Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys
byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // A0 A1 A2 A3 A4 A5
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // B0 B1 B2 B3 B4 B5
{0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4D 3A 99 C3 51 DD
{0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1A 98 2C 7E 45 9A
{0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // D3 F7 D3 F7 D3 F7
{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // AA BB CC DD EE FF
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 00 00 00 00 00 00
};
/*
* Initialize.
*/
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Try the most used default keys to print block 0 of a MIFARE PICC.");
}
/*
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/*
* Try using the PICC (the tag/card) with the given key to access block 0.
* On success, it will show the key details, and dump the block data on Serial.
*
* @return true when the given key worked, false otherwise.
*/
boolean try_key(MFRC522::MIFARE_Key *key)
{
boolean result = false;
byte buffer[18];
byte block = 0;
byte status;
// Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
// Serial.print("PCD_Authenticate() failed: ");
// Serial.println(mfrc522.GetStatusCodeName(status));
return false;
}
// Read block
byte byteCount = sizeof(buffer);
status = mfrc522.MIFARE_Read(block, buffer, &byteCount);
if (status != MFRC522::STATUS_OK) {
// Serial.print("MIFARE_Read() failed: ");
// Serial.println(mfrc522.GetStatusCodeName(status));
}
else {
// Successful read
result = true;
Serial.print("Success with key:");
dump_byte_array((*key).keyByte, MFRC522::MF_KEY_SIZE);
Serial.println();
// Dump block data
Serial.print("Block "); Serial.print(block); Serial.print(":");
dump_byte_array(buffer, 16);
Serial.println();
}
Serial.println();
mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD
return result;
}
/*
* Main loop.
*/
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;
// Show some details of the PICC (that is: the tag/card)
Serial.print("Card UID:");
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
Serial.print("PICC type: ");
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Try the known default keys
MFRC522::MIFARE_Key key;
for (byte k = 0; k < NR_KNOWN_KEYS; k++) {
// Copy the known key into the MIFARE_Key structure
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) {
key.keyByte[i] = knownKeys[k][i];
}
// Try the key
if (try_key(&key)) {
// Found and reported on the key and block,
// no need to try other keys for this PICC
break;
}
}
}
mesaj birleştirme:: 26 Aralık 2014, 23:39:24
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10 //Arduino Uno
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Write personal data on a MIFARE PICC ");
}
void loop() {
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) return;
Serial.print("Card UID:"); //Dump UID
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print(" PICC type: "); // Dump PICC type
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
byte buffer[34];
byte block;
byte status, len;
Serial.setTimeout(20000L) ; // wait until 20 seconds for input from serial
// Ask personal data: Family name
Serial.println("Type Family name, ending with #");
len=Serial.readBytesUntil('#', (char *) buffer, 30) ; // read family name from serial
for (byte i = len; i < 30; i++) buffer[i] = '\s'; // pad with spaces
block = 1;
//Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Write block
status = mfrc522.MIFARE_Write(block, buffer, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
block = 2;
//Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Write block
status = mfrc522.MIFARE_Write(block, &buffer[16], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
// Ask personal data: First name
Serial.println("Type First name, ending with #");
len=Serial.readBytesUntil('#', (char *) buffer, 20) ; // read first name from serial
for (byte i = len; i < 20; i++) buffer[i] = '\s'; // pad with spaces
block = 4;
//Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Write block
status = mfrc522.MIFARE_Write(block, buffer, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
block = 5;
//Serial.println("Authenticating using key A...");
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK) {
Serial.print("PCD_Authenticate() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
// Write block
status = mfrc522.MIFARE_Write(block, &buffer[16], 16);
if (status != MFRC522::STATUS_OK) {
Serial.print("MIFARE_Write() failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else Serial.println("MIFARE_Write() success: ");
Serial.println(" ");
mfrc522.PICC_HaltA(); // Halt PICC
mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD
}
Birşey sorayım.
Arduino uno ile 2x16LCD ye birşeyler yazıyorum. Yazma yapıldığı zaman kendi kendine seri porttan birşeyler gönderiyor. Terminalden bakıyorum ama gelen karakterler anlamsız. üstelik seri portu aktif etmiyorum bile.
lcd.setCursor fonksiyonununda bile benzer bir durum var. Kodum çalışıyor ama nedenini merak ettim. Neden olur bu
Lcd kütüphanesinin kullandığı pinlerden biri seriportun txine denk geliyor olabilir.
6 hat bağlantı yaptığınızı düşünerek RW pinini direk GND'ye çektiğinizi düşünüyorum. Büyük ihtimalle arduino driver'ınızın RW pini TX piniyle bir şekilde çakışıyor :)
Manual olarak drivera müdahale etmeniz gerek. Yoksa arduino kendi kendine seri porttan data basmaz diye düşünüyorum :)
baktım arduino LCD kodunu anlamak zamanımı alacak bende kendi kodumu yazdım. 8 bitlik+3 kontrol hatlı.Hala bazı yerleri eksik olsada idare eder.
LCD bağlantı bacaklarına bir bakmak gerek, 0 ve 1 kullanılıyorsa bir yaklaşım olabilir.
Kendi kütüphanesini kullanıyorsan, orada seri portu kullanacak bir kod yok.
Gözümden kaçmış. Evet TX pini ile çakışma oluyormuş.