Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
man.cpp
00001 //Test of cheap 13.56 Mhz RFID-RC522 module from eBay 00002 //This code is based on Martin Olejar's MFRC522 library. Minimal changes 00003 //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too 00004 00005 //Connect as follows: 00006 //RFID pins -> Nucleo header CN5 (Arduino-compatible header) 00007 //---------------------------------------- 00008 //RFID IRQ=pin5 -> Not used. Leave open 00009 //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 00010 //RFID MOSI=pin3 -> Nucleo SPI_MOSI=PA_7=D11 00011 //RFID SCK=pin2 -> Nucleo SPI_SCK =PA_5=D13 00012 //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 00013 //RFID RST=pin7 -> Nucleo =PA_9=D8 00014 //3.3V and Gnd to the respective pins 00015 00016 #include "mbed.h" 00017 #include "MFRC522.h" 00018 #include <sstream> 00019 #include <string> 00020 00021 // CARD number 00022 uint8_t CARD_1 = 0x10; 00023 uint8_t CARD_2 = 0xA0; 00024 uint8_t CARD_3 = 0x26; 00025 uint8_t CARD_4 = 0x83; 00026 00027 uint8_t CARD_5 = 0x50; 00028 uint8_t CARD_6 = 0x4C; 00029 uint8_t CARD_7 = 0x33; 00030 uint8_t CARD_8 = 0x83; 00031 00032 uint8_t CARD_9 = 0x10; 00033 uint8_t CARD_10 = 0x70; 00034 uint8_t CARD_11 = 0xFD; 00035 uint8_t CARD_12 = 0x73; 00036 00037 #define SPI_MOSI D11 00038 #define SPI_MISO D12 00039 #define SPI_SCLK D13 00040 #define SPI_CS D10 00041 00042 // WIZWiki-W7500 Pin for MFRC522 reset(pick another D pin if you need D8) 00043 #define MF_RESET D9 00044 #define VOLUME 0.08 00045 00046 00047 Serial pc(USBTX, USBRX); 00048 00049 MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET); // Init MFRC522 card 00050 00051 DigitalOut LedGreen(D7); 00052 DigitalOut LedYellow(D6); 00053 PwmOut Buzzer(D5); 00054 float beat_duration; 00055 00056 // Plays a sound with the defined frequency, duration, and volume 00057 void playNote(float frequency, float volume) 00058 { 00059 Buzzer.period(1.0/(double)frequency); 00060 Buzzer = ((double)volume/2.0); 00061 } 00062 char* store_buf; 00063 char data2[8]; 00064 00065 int main(void) 00066 { 00067 printf("Welcome to My Smart Home.... "); 00068 wait_ms(50); 00069 printf("\n\r"); 00070 printf("Please swipe card.. Here "); 00071 wait_ms(50); 00072 printf("\n\r"); 00073 // Init. RC522 Chip 00074 RfChip.PCD_Init(); 00075 00076 while (true) { 00077 LedGreen = 1; 00078 // Look for new cards 00079 if ( ! RfChip.PICC_IsNewCardPresent()) { 00080 wait_ms(50); 00081 continue; 00082 } 00083 LedGreen = 0; 00084 wait_ms(50); 00085 // Select one of the cards 00086 if ( ! RfChip.PICC_ReadCardSerial()) { 00087 wait_ms(50); 00088 continue; 00089 } 00090 LedGreen = 1; 00091 wait_ms(50); 00092 00093 // Print Card UID 00094 for (uint8_t i = 0; i < RfChip.uid.size; i++) { 00095 store_buf+= sprintf(store_buf,"%X",RfChip.uid.uidByte[i]); 00096 } 00097 printf("\n\r"); 00098 // Print Card type 00099 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); 00100 LedGreen = 0; 00101 wait_ms(50); 00102 00103 // store_buf=data2; 00104 if((RfChip.uid.uidByte[0] == CARD_1) && (RfChip.uid.uidByte[1] == CARD_2) && (RfChip.uid.uidByte[2] == CARD_3) && (RfChip.uid.uidByte[3] == CARD_4)) { 00105 LedYellow=1; 00106 // wait_ms(1000); 00107 pc.printf("Yello Led is On....."); 00108 printf("\n\r"); 00109 00110 } else if((RfChip.uid.uidByte[0] == CARD_5) && (RfChip.uid.uidByte[1] == CARD_6) && (RfChip.uid.uidByte[2] == CARD_7) && (RfChip.uid.uidByte[3] == CARD_8)) { 00111 playNote(999.999, VOLUME); 00112 pc.printf("Buzzer is On....."); 00113 printf("\n\r"); 00114 00115 } else if((RfChip.uid.uidByte[0] == CARD_9) && (RfChip.uid.uidByte[1] == CARD_10) && (RfChip.uid.uidByte[2] == CARD_11) && (RfChip.uid.uidByte[3] == CARD_12)) { 00116 pc.printf("This is a master Card: "); 00117 printf("\n\r"); 00118 LedYellow=0; 00119 Buzzer=0; 00120 pc.printf("ALL Device off....."); 00121 printf("\n\r"); 00122 pc.printf("Thank you....."); 00123 } 00124 printf("\n\r"); 00125 00126 00127 00128 } 00129 }
Generated on Wed Jul 13 2022 02:07:58 by
1.7.2