Reading a RFID tag (13.56MHz) and sending its data through bluetooth (HC-05 module) to an Android cellphone (using the BlueTerm APP).

Dependencies:   TextLCD beep mbed

Fork of RFID-RC522 by Thomas Kirchner

Files at this revision

API Documentation at this revision

Comitter:
Clovis
Date:
Tue Sep 23 07:08:59 2014 +0000
Parent:
2:a0c7513fb634
Commit message:
initial release: reads a RFID tag (13.56Mhz) and sends the data of the tag to a cellphone (through HC-05 bluetooth module). Tested for the FRDM-K64F (Freescale) platform.

Changed in this revision

MFRC522.h Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
beep.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MFRC522.h	Fri Jun 06 03:04:48 2014 +0000
+++ b/MFRC522.h	Tue Sep 23 07:08:59 2014 +0000
@@ -76,77 +76,6 @@
 
 #include "mbed.h"
 
-/**
-* MFRC522 example
-*
-* @code
-* #include "mbed.h"
-* #include "MFRC522.h"
-*
-* //KL25Z Pins for MFRC522 SPI interface
-* #define SPI_MOSI    PTC6
-* #define SPI_MISO    PTC7
-* #define SPI_SCLK    PTC5
-* #define SPI_CS      PTC4
-* // KL25Z Pin for MFRC522 reset
-* #define MF_RESET    PTC3
-* // KL25Z Pins for Debug UART port
-* #define UART_RX     PTA1
-* #define UART_TX     PTA2
-*
-* DigitalOut LedRed   (LED_RED);
-* DigitalOut LedGreen (LED_GREEN);
-*
-* Serial     DebugUART(UART_TX, UART_RX);
-* MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
-*
-* int main(void) {
-*   // Set debug UART speed
-*   DebugUART.baud(115200);
-*
-*   // Init. RC522 Chip
-*   RfChip.PCD_Init();
-*
-*   while (true) {
-*     LedRed   = 1;
-*     LedGreen = 1;
-*
-*     // Look for new cards
-*     if ( ! RfChip.PICC_IsNewCardPresent())
-*     {
-*       wait_ms(500);
-*       continue;
-*     }
-*
-*     LedRed   = 0;
-*
-*     // Select one of the cards
-*     if ( ! RfChip.PICC_ReadCardSerial())
-*     {
-*       wait_ms(500);
-*       continue;
-*     }
-*
-*     LedRed   = 1;
-*     LedGreen = 0;
-*
-*     // Print Card UID
-*     printf("Card UID: ");
-*     for (uint8_t i = 0; i < RfChip.uid.size; i++)
-*     {
-*       printf(" %X02", RfChip.uid.uidByte[i]);
-*     }
-*     printf("\n\r");
-*
-*     // Print Card type
-*     uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
-*     printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
-*     wait_ms(1000);
-*   }
-* }
-* @endcode
-*/
-
 class MFRC522 {
 public:
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue Sep 23 07:08:59 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Tue Sep 23 07:08:59 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
--- a/main.cpp	Fri Jun 06 03:04:48 2014 +0000
+++ b/main.cpp	Tue Sep 23 07:08:59 2014 +0000
@@ -1,67 +1,116 @@
 //Test of cheap 13.56 Mhz RFID-RC522 module from eBay
-//This code is based on Martin Olejar's MFRC522 library. Minimal changes
-//Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too
+//This code is based on Martin Olejar's and Thomas Kirchner's MFRC522 libraries. Minimal changes
+//Adapted for FRDM-K64F from Freescale, in 07/21/2014 by Clovis Fritzen.
 
-//Connect as follows:
-//RFID pins        ->  Nucleo header CN5 (Arduino-compatible header)
-//----------------------------------------
-//RFID IRQ=pin5    ->   Not used. Leave open
-//RFID MISO=pin4   ->   Nucleo SPI_MISO=PA_6=D12
-//RFID MOSI=pin3   ->   Nucleo SPI_MOSI=PA_7=D11
-//RFID SCK=pin2    ->   Nucleo SPI_SCK =PA_5=D13
-//RFID SDA=pin1    ->   Nucleo SPI_CS  =PB_6=D10
-//RFID RST=pin7    ->   Nucleo         =PA_9=D8
-//3.3V and Gnd to the respective pins                              
-                              
 #include "mbed.h"
 #include "MFRC522.h"
+#include "beep.h"
+#include "TextLCD.h"
 
-// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
-#define MF_RESET    D8
+// FRDM-K64F (Freescale) Pin for MFRC522 reset
+#define MF_RESET    PTD0
 
-DigitalOut LedGreen(LED1);
+// Defining the serial ports for PC and Bluetooth
+#define SERIAL_1  
+Serial pc(USBTX, USBRX);
+#ifdef SERIAL_1
+Serial blue(PTC15,PTC14);          // HC05
+#endif
+#ifdef SERIAL_2
+Serial blue(PTC17,PTC16);         // TX = P14  RX = P13
+#endif
+
 
-//Serial connection to PC for output
-Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut LedGreen(LED2), LedRed(LED1);
+TextLCD lcd(PTB9, PTA1, PTB23, PTA2, PTC2, PTC3); // rs, e, d4-d7
+Beep buzzer(PTA0);
+Timer timeBetweenCards;
+char tagname;
+char * cardtypetest;
+char cardid;
 
-MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
+
+
+//MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
+MFRC522    RfChip   (PTD2, PTD3, PTD1, PTE25, PTD0);
+
 
 int main(void) {
-  pc.printf("starting...\n");
+  
+  blue.baud(9600);
+  pc.baud(9600);
+  LedRed= 0;
+  pc.printf("Bluetooth and RFID Started\r\n");
 
   // Init. RC522 Chip
   RfChip.PCD_Init();
 
   while (true) {
+    
+    lcd.locate(0,0);
+    lcd.printf("%.2f seconds \n", timeBetweenCards.read());
+    tagname = '\0';
+    LedRed= 1;
     LedGreen = 1;
 
     // Look for new cards
     if ( ! RfChip.PICC_IsNewCardPresent())
     {
-      wait_ms(500);
+      //wait_ms(100);
       continue;
     }
 
     // Select one of the cards
     if ( ! RfChip.PICC_ReadCardSerial())
     {
-      wait_ms(500);
+      //wait_ms(100);
+      
       continue;
+      
     }
-
-    LedGreen = 0;
+    
+    // When a card is detected, a Green Led flashes and a buzzers bips!
+    blue.printf("%f seconds \n", timeBetweenCards.read());
+    timeBetweenCards.start();
+    LedGreen = 0; 
+    buzzer.beep(5000,0.3);
 
     // Print Card UID
-    pc.printf("Card UID: ");
+    printf("\n\r");
+    printf("Card UID: ");
+    
     for (uint8_t i = 0; i < RfChip.uid.size; i++)
     {
-      pc.printf(" %X02", RfChip.uid.uidByte[i]);
+      printf(" %X02", RfChip.uid.uidByte[i]);
+      cardid= RfChip.uid.uidByte[i];
+      blue.printf(" %X02 ", (char *) cardid);
+      tagname= RfChip.uid.uidByte[i]+ tagname;
+      blue.putc(tagname);
+      lcd.locate(0,1);
+      lcd.printf("Tag id: %.0d\n", tagname); 
+      
     }
-    pc.printf("\n\r");
+    printf("\n\r");
+    if (tagname == 226) {
+        printf ("BLUE Keychain");
+        printf("\n\r");
+        } else {
+            if (tagname == 92) {
+                
+        printf ("White card");
+        printf("\n\r");
+        }
+        }
+        
+            
+        
+        printf("Decimal tag ID:  %d \n\r", tagname);   
 
     // Print Card type
     uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
-    pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
-    wait_ms(1000);
+    printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
+    cardtypetest= RfChip.PICC_GetTypeName(piccType);
+    blue.printf("PICC Type: %s \n\r",(char *) cardtypetest);
+    //wait_ms(100);
   }
 }
\ No newline at end of file