(RFID project) SD problem with Ethernet library
hi everyone!
i'm doing rfid project using nfc pn532 (rfid reader) , arduino uno ethernet shield. is, when touch rfid card (i use mifare classic.) reader, data written mifare , micro sd card on ethernet shield.
my code here ... (my problem below code.)
the line "myfile = sd.open("test.txt");" doesn't work well, serial monitor send "error opening test.txt". but if doesn't include ethernet library (ethernet.h), project works!!!!!!!
i don't know how ethernet.h make happened.
want much. =( thank kind attention , help. xd
*note : don't wonder why include ethernet.h without using it. project haven't done yet.
i'm doing rfid project using nfc pn532 (rfid reader) , arduino uno ethernet shield. is, when touch rfid card (i use mifare classic.) reader, data written mifare , micro sd card on ethernet shield.
my code here ... (my problem below code.)
code: [select]
#if defined(arduino) && arduino >= 100
#include <arduino.h>
#else
#include <wprogram.h>
#endif
#include <spi.h>
#include <ethernet.h>
#include <sd.h>
#include <nfc.h>
nfc_module nfc;
file myfile;
u8 buf[5], sta;
void setup()
{
serial.begin(9600);
pinmode(4, output);
sd.begin(4);
nfc.begin();
uint32_t versiondata = nfc.get_version();
if (!versiondata) {
serial.println("didn't find pn53x board");
delay(2000);
asm volatile (" jmp 0"); // reboot if didn't find pn53x board.
}
nfc.samconfiguration();
serial.println("waiting card ...");
}
void loop()
{
sta = nfc.inlistpassivetarget(buf);
delay(200);
if (sta && buf[0] == 4)
{
serial.println("connected.");
readwritecard();
writesd();
serial.println("-----");
delay(1000);
serial.println("waiting card ...");
}
}
boolean newcard(u8 block60[16]){
int j = 0;
for(int = 0; < 16; i++){
if(block60[i] == 0){
j++;
}
}
if(j == 16){
return true;
} else{
return false;
}
}
void readwritecard(){
serial.println("a card found!");
serial.print("card id: ");
nfc.puthex(buf, buf[0]);
serial.println("");
u8 keya[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
u8 rdata[16], wdata[16];
u8 auth;
nfc.mifareauthentication(0, 60, &buf[1], buf[0], keya);
nfc.mifarereadblock(60, rdata);
if(newcard(rdata)){
serial.println("this new card.");
memcpy(wdata, (u8[]){4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, sizeof wdata);
nfc.mifarewriteblock(60, wdata);
}
nfc.mifarereadblock(60, rdata);
int block = rdata[0];
if((block + 1) % 4 == 0){
block++;
}
auth = nfc.mifareauthentication(0, block, &buf[1], buf[0], keya);
serial.print("authentication: ");
serial.print("block "); serial.print(block); serial.print(" ");
serial.println(auth);
if(auth){
memcpy(wdata, (u8[]){1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, sizeof wdata);
nfc.mifarewriteblock(block, wdata);
serial.print("card: "); nfc.puthex(wdata, 16); serial.println("");
nfc.mifareauthentication(0, 60, &buf[1], buf[0], keya);
memcpy(wdata, (u8[]){block+1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, sizeof wdata);
nfc.mifarewriteblock(60, wdata);
} else{
serial.println("authentication failed. block can't written.");
}
}
void writesd(){
myfile = sd.open("test.txt", file_write);
if (myfile) {
serial.print("writing test.txt...");
myfile.println("testing 1, 2, 3.");
myfile.close();
serial.println("done.");
} else {
serial.println("error opening test.txt");
}
myfile = sd.open("test.txt");
if (myfile) {
serial.println("test.txt:");
while (myfile.available()) {
serial.write(myfile.read());
}
myfile.close();
} else {
serial.println("error opening test.txt");
}
}
the line "myfile = sd.open("test.txt");" doesn't work well, serial monitor send "error opening test.txt". but if doesn't include ethernet library (ethernet.h), project works!!!!!!!
i don't know how ethernet.h make happened.

*note : don't wonder why include ethernet.h without using it. project haven't done yet.
you have run out of sram. there easy solution. use mega 2560.
Arduino Forum > Development > Suggestions for the Arduino Project > (RFID project) SD problem with Ethernet library
arduino
Comments
Post a Comment