![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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@8:ea7d0c9a35c4, 2015-05-03 (annotated)
- Committer:
- abhishekgoyanka
- Date:
- Sun May 03 18:27:02 2015 +0000
- Revision:
- 8:ea7d0c9a35c4
- Parent:
- 7:caeacf521320
- Child:
- 9:f7c69716fad8
at max efficiency
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 0:a83db87be46c | 1 | #include "mbed.h" |
Kojto | 0:a83db87be46c | 2 | #include "SDFileSystem.h" |
abhishekgoyanka | 3:ade6c26d1b90 | 3 | #include "MFRC522.h" |
abhishekgoyanka | 3:ade6c26d1b90 | 4 | #include <stdio.h> |
abhishekgoyanka | 7:caeacf521320 | 5 | #include "NOKIA_5110.h" |
abhishekgoyanka | 7:caeacf521320 | 6 | |
abhishekgoyanka | 3:ade6c26d1b90 | 7 | // FRDM-K64F (Freescale) Pin for MFRC522 reset |
abhishekgoyanka | 3:ade6c26d1b90 | 8 | #define MF_RESET PTD0 |
abhishekgoyanka | 3:ade6c26d1b90 | 9 | FILE *fp; |
abhishekgoyanka | 3:ade6c26d1b90 | 10 | |
abhishekgoyanka | 3:ade6c26d1b90 | 11 | DigitalOut LedGreen(LED2); |
abhishekgoyanka | 3:ade6c26d1b90 | 12 | |
abhishekgoyanka | 3:ade6c26d1b90 | 13 | //Serial connection to PC for output |
abhishekgoyanka | 3:ade6c26d1b90 | 14 | Serial pc(USBTX, USBRX); // serial comm on the FRDM board |
abhishekgoyanka | 3:ade6c26d1b90 | 15 | |
abhishekgoyanka | 3:ade6c26d1b90 | 16 | //MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); |
abhishekgoyanka | 3:ade6c26d1b90 | 17 | MFRC522 RfChip (PTD2, PTD3, PTD1, PTE25, PTD0); |
Kojto | 0:a83db87be46c | 18 | |
Kojto | 0:a83db87be46c | 19 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
abhishekgoyanka | 8:ea7d0c9a35c4 | 20 | char buffer[1024]; |
abhishekgoyanka | 3:ade6c26d1b90 | 21 | uint8_t user[10]; |
abhishekgoyanka | 8:ea7d0c9a35c4 | 22 | char kanu[16]="BC02CD022B02702"; |
abhishekgoyanka | 3:ade6c26d1b90 | 23 | char abhishek[17]="6902BC029C021A02"; |
abhishekgoyanka | 8:ea7d0c9a35c4 | 24 | char temp[17]; |
abhishekgoyanka | 8:ea7d0c9a35c4 | 25 | int flag1=0; |
abhishekgoyanka | 8:ea7d0c9a35c4 | 26 | int flag2=0; //checks if the card scanner is run for the first time |
abhishekgoyanka | 3:ade6c26d1b90 | 27 | |
abhishekgoyanka | 3:ade6c26d1b90 | 28 | int main() |
abhishekgoyanka | 3:ade6c26d1b90 | 29 | |
abhishekgoyanka | 3:ade6c26d1b90 | 30 | { |
Kojto | 0:a83db87be46c | 31 | pc.printf("Initializing \n"); |
abhishekgoyanka | 3:ade6c26d1b90 | 32 | |
abhishekgoyanka | 7:caeacf521320 | 33 | LcdPins myPins; |
abhishekgoyanka | 7:caeacf521320 | 34 | myPins.sce = PTC12; |
abhishekgoyanka | 7:caeacf521320 | 35 | myPins.rst = PTC4; |
abhishekgoyanka | 7:caeacf521320 | 36 | myPins.dc = PTB3; |
abhishekgoyanka | 7:caeacf521320 | 37 | myPins.mosi = PTD6; |
abhishekgoyanka | 7:caeacf521320 | 38 | myPins.miso = NC; |
abhishekgoyanka | 7:caeacf521320 | 39 | myPins.sclk = PTD5; |
abhishekgoyanka | 7:caeacf521320 | 40 | |
abhishekgoyanka | 7:caeacf521320 | 41 | NokiaLcd myLcd( myPins ); |
abhishekgoyanka | 7:caeacf521320 | 42 | |
abhishekgoyanka | 7:caeacf521320 | 43 | // Start the LCD |
abhishekgoyanka | 7:caeacf521320 | 44 | myLcd.InitLcd(); |
abhishekgoyanka | 7:caeacf521320 | 45 | myLcd.DrawString("HELLO"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 46 | wait( 3 ); |
abhishekgoyanka | 7:caeacf521320 | 47 | myLcd.ShutdownLcd(); |
abhishekgoyanka | 3:ade6c26d1b90 | 48 | |
abhishekgoyanka | 3:ade6c26d1b90 | 49 | // Init. RC522 Chip |
abhishekgoyanka | 3:ade6c26d1b90 | 50 | RfChip.PCD_Init(); |
Kojto | 0:a83db87be46c | 51 | |
abhishekgoyanka | 3:ade6c26d1b90 | 52 | fp = fopen("/sd/attendance.txt", "r"); |
abhishekgoyanka | 3:ade6c26d1b90 | 53 | if (fp != NULL) |
abhishekgoyanka | 3:ade6c26d1b90 | 54 | { |
Kojto | 0:a83db87be46c | 55 | fclose(fp); |
abhishekgoyanka | 3:ade6c26d1b90 | 56 | remove("/sd/attendance.txt"); |
Kojto | 0:a83db87be46c | 57 | pc.printf("Remove an existing file with the same name \n"); |
Kojto | 0:a83db87be46c | 58 | } |
abhishekgoyanka | 3:ade6c26d1b90 | 59 | |
abhishekgoyanka | 3:ade6c26d1b90 | 60 | while (true) |
abhishekgoyanka | 3:ade6c26d1b90 | 61 | { |
abhishekgoyanka | 3:ade6c26d1b90 | 62 | LedGreen = 1; |
abhishekgoyanka | 3:ade6c26d1b90 | 63 | |
abhishekgoyanka | 3:ade6c26d1b90 | 64 | // Look for new cards |
abhishekgoyanka | 3:ade6c26d1b90 | 65 | if ( ! RfChip.PICC_IsNewCardPresent()) |
abhishekgoyanka | 3:ade6c26d1b90 | 66 | { |
abhishekgoyanka | 5:9f7e1200059e | 67 | RfChip.PCD_Init(); |
abhishekgoyanka | 5:9f7e1200059e | 68 | wait_ms(300); |
abhishekgoyanka | 7:caeacf521320 | 69 | // continue; |
abhishekgoyanka | 3:ade6c26d1b90 | 70 | } |
abhishekgoyanka | 3:ade6c26d1b90 | 71 | |
abhishekgoyanka | 3:ade6c26d1b90 | 72 | // Select one of the cards |
abhishekgoyanka | 3:ade6c26d1b90 | 73 | if ( ! RfChip.PICC_ReadCardSerial()) |
abhishekgoyanka | 3:ade6c26d1b90 | 74 | { |
abhishekgoyanka | 3:ade6c26d1b90 | 75 | wait_ms(200); |
abhishekgoyanka | 3:ade6c26d1b90 | 76 | continue; |
abhishekgoyanka | 3:ade6c26d1b90 | 77 | } |
abhishekgoyanka | 3:ade6c26d1b90 | 78 | |
abhishekgoyanka | 3:ade6c26d1b90 | 79 | LedGreen = 0; |
abhishekgoyanka | 3:ade6c26d1b90 | 80 | |
abhishekgoyanka | 3:ade6c26d1b90 | 81 | // Print Card UID |
abhishekgoyanka | 3:ade6c26d1b90 | 82 | printf("Card UID: "); |
abhishekgoyanka | 3:ade6c26d1b90 | 83 | for (uint8_t i = 0; i < RfChip.uid.size; i++) |
abhishekgoyanka | 3:ade6c26d1b90 | 84 | { |
abhishekgoyanka | 4:6ba6c4be9dde | 85 | printf("%X02", RfChip.uid.uidByte[i]); |
abhishekgoyanka | 3:ade6c26d1b90 | 86 | user[i]=RfChip.uid.uidByte[i]; |
abhishekgoyanka | 3:ade6c26d1b90 | 87 | } |
abhishekgoyanka | 4:6ba6c4be9dde | 88 | printf("\n"); |
abhishekgoyanka | 5:9f7e1200059e | 89 | |
abhishekgoyanka | 8:ea7d0c9a35c4 | 90 | sprintf(temp,"%X02%X02%X02%X02",user[0],user[1],user[2],user[3]); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 91 | printf("temp is %s",temp); |
abhishekgoyanka | 4:6ba6c4be9dde | 92 | |
abhishekgoyanka | 8:ea7d0c9a35c4 | 93 | if(strcmp(temp, abhishek)==0) |
abhishekgoyanka | 5:9f7e1200059e | 94 | { |
abhishekgoyanka | 5:9f7e1200059e | 95 | printf("\n found abhishek\n"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 96 | if (flag2==1) |
abhishekgoyanka | 5:9f7e1200059e | 97 | { |
abhishekgoyanka | 5:9f7e1200059e | 98 | printf("Already logged in!\n"); |
abhishekgoyanka | 7:caeacf521320 | 99 | |
abhishekgoyanka | 7:caeacf521320 | 100 | myLcd.InitLcd(); |
abhishekgoyanka | 7:caeacf521320 | 101 | myLcd.DrawString("ABHISHEK"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 102 | wait( 3 ); |
abhishekgoyanka | 7:caeacf521320 | 103 | myLcd.ShutdownLcd(); |
abhishekgoyanka | 7:caeacf521320 | 104 | |
abhishekgoyanka | 5:9f7e1200059e | 105 | } |
abhishekgoyanka | 8:ea7d0c9a35c4 | 106 | else if (flag2==0) |
abhishekgoyanka | 5:9f7e1200059e | 107 | { |
abhishekgoyanka | 5:9f7e1200059e | 108 | printf("\nWriting data to the sd card \n"); |
abhishekgoyanka | 6:bc2ca526022f | 109 | fp = fopen("/sd/attendance.txt", "a+"); |
abhishekgoyanka | 5:9f7e1200059e | 110 | if (fp == NULL) |
abhishekgoyanka | 5:9f7e1200059e | 111 | { |
abhishekgoyanka | 5:9f7e1200059e | 112 | pc.printf("Unable to write the file \n"); |
abhishekgoyanka | 5:9f7e1200059e | 113 | } |
abhishekgoyanka | 5:9f7e1200059e | 114 | else |
abhishekgoyanka | 8:ea7d0c9a35c4 | 115 | { |
abhishekgoyanka | 5:9f7e1200059e | 116 | fprintf(fp, "\nAbhishek PRESENT \n"); |
abhishekgoyanka | 5:9f7e1200059e | 117 | fclose(fp); |
abhishekgoyanka | 5:9f7e1200059e | 118 | } |
abhishekgoyanka | 8:ea7d0c9a35c4 | 119 | flag2=1; |
abhishekgoyanka | 7:caeacf521320 | 120 | |
abhishekgoyanka | 7:caeacf521320 | 121 | myLcd.InitLcd(); |
abhishekgoyanka | 7:caeacf521320 | 122 | myLcd.DrawString("ABHISHEK"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 123 | wait( 3 ); |
abhishekgoyanka | 7:caeacf521320 | 124 | myLcd.ShutdownLcd(); |
abhishekgoyanka | 5:9f7e1200059e | 125 | } |
abhishekgoyanka | 5:9f7e1200059e | 126 | } |
abhishekgoyanka | 8:ea7d0c9a35c4 | 127 | else if(strcmp(temp,kanu)==0) |
abhishekgoyanka | 5:9f7e1200059e | 128 | { |
abhishekgoyanka | 8:ea7d0c9a35c4 | 129 | printf("\n found Kanu\n"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 130 | if (flag1==1) |
abhishekgoyanka | 5:9f7e1200059e | 131 | { |
abhishekgoyanka | 5:9f7e1200059e | 132 | printf("Already logged in!\n"); |
abhishekgoyanka | 7:caeacf521320 | 133 | |
abhishekgoyanka | 7:caeacf521320 | 134 | myLcd.InitLcd(); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 135 | myLcd.DrawString("KANU"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 136 | wait( 3 ); |
abhishekgoyanka | 7:caeacf521320 | 137 | myLcd.ShutdownLcd(); |
abhishekgoyanka | 7:caeacf521320 | 138 | |
abhishekgoyanka | 5:9f7e1200059e | 139 | } |
abhishekgoyanka | 8:ea7d0c9a35c4 | 140 | else if (flag1==0) |
abhishekgoyanka | 5:9f7e1200059e | 141 | { |
abhishekgoyanka | 5:9f7e1200059e | 142 | printf("\nWriting data to the sd card \n"); |
abhishekgoyanka | 6:bc2ca526022f | 143 | fp = fopen("/sd/attendance.txt", "a+"); |
abhishekgoyanka | 5:9f7e1200059e | 144 | if (fp == NULL) |
abhishekgoyanka | 5:9f7e1200059e | 145 | { |
abhishekgoyanka | 5:9f7e1200059e | 146 | pc.printf("Unable to write the file \n"); |
abhishekgoyanka | 5:9f7e1200059e | 147 | } |
abhishekgoyanka | 5:9f7e1200059e | 148 | else |
abhishekgoyanka | 8:ea7d0c9a35c4 | 149 | { |
abhishekgoyanka | 8:ea7d0c9a35c4 | 150 | fprintf(fp, "\nKANU PRESENT \n"); |
abhishekgoyanka | 5:9f7e1200059e | 151 | fclose(fp); |
abhishekgoyanka | 5:9f7e1200059e | 152 | } |
abhishekgoyanka | 8:ea7d0c9a35c4 | 153 | flag1=1; |
abhishekgoyanka | 8:ea7d0c9a35c4 | 154 | printf("flag1=%i\n",flag1); |
abhishekgoyanka | 7:caeacf521320 | 155 | |
abhishekgoyanka | 7:caeacf521320 | 156 | myLcd.InitLcd(); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 157 | myLcd.DrawString("KANU"); |
abhishekgoyanka | 8:ea7d0c9a35c4 | 158 | wait( 3 ); |
abhishekgoyanka | 7:caeacf521320 | 159 | myLcd.ShutdownLcd(); |
abhishekgoyanka | 5:9f7e1200059e | 160 | |
abhishekgoyanka | 5:9f7e1200059e | 161 | } |
abhishekgoyanka | 3:ade6c26d1b90 | 162 | |
abhishekgoyanka | 5:9f7e1200059e | 163 | printf("Just after continue\n"); |
abhishekgoyanka | 5:9f7e1200059e | 164 | } |
abhishekgoyanka | 3:ade6c26d1b90 | 165 | |
abhishekgoyanka | 5:9f7e1200059e | 166 | else |
abhishekgoyanka | 5:9f7e1200059e | 167 | { |
abhishekgoyanka | 5:9f7e1200059e | 168 | continue; |
abhishekgoyanka | 5:9f7e1200059e | 169 | } |
abhishekgoyanka | 4:6ba6c4be9dde | 170 | |
Kojto | 0:a83db87be46c | 171 | printf("\nReading data from the SD card. \n"); |
abhishekgoyanka | 3:ade6c26d1b90 | 172 | fp = fopen("/sd/attendance.txt", "r"); |
abhishekgoyanka | 3:ade6c26d1b90 | 173 | if (fp != NULL) |
abhishekgoyanka | 3:ade6c26d1b90 | 174 | { |
Kojto | 0:a83db87be46c | 175 | int size = fread(buffer, sizeof(char), 1024, fp); |
abhishekgoyanka | 3:ade6c26d1b90 | 176 | printf("Number of data read: %d, text from attendance.txt file: %s \n", size, buffer); |
Kojto | 0:a83db87be46c | 177 | fclose(fp); |
Kojto | 0:a83db87be46c | 178 | } |
Kojto | 0:a83db87be46c | 179 | } |
abhishekgoyanka | 5:9f7e1200059e | 180 | } |