This is a RFID based attendance system. The current program is only for two users but can be easily scaled for more users. Apart from FRDM-K64F board, we have MFRC522, Nokia 5110 LCD and SD card as external hardware. Each time a legitimate card is flashed the name of the person will be displayed on the LCD and his information will be stored in SD card if it's already not there. I have used existing libraries for all the harware. Here is the list. MFRC522 - By Martin Olejar SDFileSystem - By Andrew Lindsay NOKIA_5110 - By Chris Yan.
Dependencies: MFRC522 NOKIA_5110 SDFileSystem mbed
Fork of FTF2014_lab4 by
main.cpp
- Committer:
- abhishekgoyanka
- Date:
- 2015-05-02
- Revision:
- 5:9f7e1200059e
- Parent:
- 4:6ba6c4be9dde
- Child:
- 6:bc2ca526022f
File content as of revision 5:9f7e1200059e:
#include "mbed.h" #include "SDFileSystem.h" #include "MFRC522.h" #include <stdio.h> #include "N5110.h" // FRDM-K64F (Freescale) Pin for MFRC522 reset #define MF_RESET PTD0 FILE *fp; DigitalOut LedGreen(LED2); //Serial connection to PC for output Serial pc(USBTX, USBRX); // serial comm on the FRDM board //Serial uart(PTC17, PTC16); // VCC,SCE,RST,D/C,MOSI,SCLK,LED //N5110 lcd(PTB2, PTC12, PTD0, PTB3, PTD6, PTD5, PTC12); N5110 lcd(PTB2, PTC12, PTD0, PTB3, PTD6, PTD5, PTA0); //MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); MFRC522 RfChip (PTD2, PTD3, PTD1, PTE25, PTD0); SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS char buffer[1024]; //UNKNOWN foe now //uint8_t line[100]; uint8_t user[10]; uint8_t userlist[2][10]; char sam[16]="BC02CD022B02702"; char tempsam[16]; char abhishek[17]="6902BC029C021A02"; char abhishektemp[17]; int usercount=0; //int found=0; int flagSam=0; int flagAbi=0; //checks if the card scanner is run for the first time int main() { pc.printf("Initializing \n"); //wait(2); // initialise display lcd.init(); // Init. RC522 Chip RfChip.PCD_Init(); fp = fopen("/sd/attendance.txt", "r"); if (fp != NULL) { fclose(fp); remove("/sd/attendance.txt"); pc.printf("Remove an existing file with the same name \n"); } while (true) { LedGreen = 1; // Look for new cards if ( ! RfChip.PICC_IsNewCardPresent()) { RfChip.PCD_Init(); wait_ms(300); continue; } // Select one of the cards if ( ! RfChip.PICC_ReadCardSerial()) { wait_ms(200); continue; } LedGreen = 0; // Print Card UID printf("Card UID: "); for (uint8_t i = 0; i < RfChip.uid.size; i++) { printf("%X02", RfChip.uid.uidByte[i]); user[i]=RfChip.uid.uidByte[i]; } printf("\n"); sprintf(abhishektemp,"%X02%X02%X02%X02",user[0],user[1],user[2],user[3]); printf("Abitemp is %s",abhishektemp); if(strcmp(abhishektemp, abhishek)==0) { printf("\n found abhishek\n"); if (flagAbi==1) { printf("Already logged in!\n"); lcd.printString("Abichek",0,0); } else if (flagAbi==0) { printf("\nWriting data to the sd card \n"); fp = fopen("/sd/attendance.txt", "rw"); if (fp == NULL) { pc.printf("Unable to write the file \n"); } else { while(!feof(fp)) {}; fprintf(fp, "\nAbhishek PRESENT \n"); fclose(fp); } flagAbi=1; lcd.printString("ABHISHEK",0,0); } } else if(strcmp(abhishektemp,sam)==0) { printf("\n found Sam\n"); if (flagSam==1) { printf("Already logged in!\n"); lcd.printString("Sam",0,0); } else if (flagSam==0) { printf("\nWriting data to the sd card \n"); fp = fopen("/sd/attendance.txt", "w"); if (fp == NULL) { pc.printf("Unable to write the file \n"); } else { while(!feof(fp)) {}; fprintf(fp, "\nSAM PRESENT \n"); fclose(fp); } flagSam=1; printf("FlagSam=%i\n",flagSam); lcd.printString("Sam",0,0); } printf("Just after continue\n"); } else { continue; } printf("\nReading data from the SD card. \n"); fp = fopen("/sd/attendance.txt", "r"); if (fp != NULL) { int size = fread(buffer, sizeof(char), 1024, fp); printf("Number of data read: %d, text from attendance.txt file: %s \n", size, buffer); fclose(fp); } } }