Ciao a tutti.
Un mesetto fà ho comprato diversi componenti su ebay tra cui il più che famoso RC522 per poter leggere Rfid, solo che non riesco a trovare un codice per poter scrivere dei dati sopra a queste card...
Ho trovato solo estratti di codice fatti male e ad alcuni dei quali mancavano dei pezzi.
Quindi chiedo a voi se per caso avete già un codice fatto in passato oppure volete provare a farne uno.
Grazie XD
Guarda qui --> How to get started with the Mifare MF522-AN and Arduino – Grant Gibson
Nel codice ci sono anche le funzioni per scrivere (http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt)
dal codice ho estratto questo:
void loop()
{
uchar i,tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr; //Selection operation block address 0 to 63
String mynum = "";
//Find cards, return card type
status = MFRC522_Request(PICC_REQIDL, str);
if (status == MI_OK)
{
//Serial.println("Card detected");
//Serial.print(str[0],BIN);
//Serial.print(" , ");
//Serial.print(str[1],BIN);
//Serial.println(" ");
}
//Anti-collision, return card serial number 4 bytes
status = MFRC522_Anticoll(str);
memcpy(serNum, str, 5);
if (status == MI_OK)
{
checksum1 = serNum[0] ^ serNum[1] ^ serNum[2] ^ serNum[3];
//Serial.println("The card's number is : ");
Serial.print(2);
Serial.print(serNum[0]);
//Serial.print(" , ");
Serial.print(serNum[1],BIN);
//Serial.print(" , ");
Serial.print(serNum[2],BIN);
//Serial.print(" , ");
Serial.print(serNum[3],BIN);
//Serial.print(" , ");
Serial.print(serNum[4],BIN);
Serial.print(checksum1);
Serial.print(3);
//Serial.println(" ");
// Should really check all pairs, but for now we'll just use the first
if(serNum[0] == 88) {
Serial.println("Hello Grant");
} else if(serNum[0] == 173) {
Serial.println("Hello David");
}
delay(1000);
}
//Serial.println(" ");
MFRC522_Halt(); //Command card into hibernation
}
/*
* Function Name:Write_MFRC5200
* Function Description: To a certain MFRC522 register to write a byte of data
* Input Parameters:addr - register address; val - the value to be written
* Return value: None
*/
void Write_MFRC522(uchar addr, uchar val)
{
digitalWrite(chipSelectPin, LOW);
//Address Format:0XXXXXX0
SPI.transfer((addr<<1)&0x7E);
SPI.transfer(val);
digitalWrite(chipSelectPin, HIGH);
}
ma mi dà questo errore
sketch_nov03a.ino: In function 'void setup()':
sketch_nov03a:157: error: 'MFRC522_Init' was not declared in this scope
sketch_nov03a.ino: In function 'void loop()':
sketch_nov03a:171: error: 'MFRC522_Request' was not declared in this scope
sketch_nov03a:182: error: 'MFRC522_Anticoll' was not declared in this scope
sketch_nov03a:212: error: 'MFRC522_Halt' was not declared in this scope
cosa potrebbe essere?
Cerca le funzioni che hai tolto perché hai comunque lasciato le chiamate nel codice da te estratto.