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.
Dependencies: mbed
Fork of RC522_LF by
Revision 2:2872862bf1c0, committed 2017-12-11
- Comitter:
- ataphon21938
- Date:
- Mon Dec 11 09:18:34 2017 +0000
- Parent:
- 1:486ccde79dc6
- Commit message:
- 11/12/2560
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 486ccde79dc6 -r 2872862bf1c0 main.cpp
--- a/main.cpp Sat Nov 14 08:28:43 2015 +0000
+++ b/main.cpp Mon Dec 11 09:18:34 2017 +0000
@@ -1,71 +1,63 @@
-//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
-
-//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"
-// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
-#define MF_RESET D8
+#define MF_RESET D8 // pin du Nucleo branchée à la pin RST du RC522
-DigitalOut LedGreen(LED1);
-
-//Serial connection to PC for output
-Serial pc(SERIAL_TX, SERIAL_RX);
+const char bonUID[4] = {0x90, 0xCF, 0x94, 0x75};
MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
+DigitalOut led_1(D2); // LED verte à la pin D2
+DigitalOut led_2(D3); // LED rouge à la pin D3
+
int main(void) {
- char uidcheck[ 100 ];
- pc.printf("starting...\n");
- // Init. RC522 Chip
RfChip.PCD_Init();
while (true) {
- LedGreen = 1;
-
- // Look for new cards
+
+ int refus = 0; // demeure nul si l'UID est bon
+
if ( ! RfChip.PICC_IsNewCardPresent())
{
wait_ms(500);
continue;
}
- // Select one of the cards
if ( ! RfChip.PICC_ReadCardSerial())
{
wait_ms(500);
continue;
}
-
- LedGreen = 0;
-
- // Print Card UID
- pc.printf("Card UID: ");
for (uint8_t i = 0; i < RfChip.uid.size; i++)
{
- pc.printf(" %X02", RfChip.uid.uidByte[i]);
- uidcheck[i] = RfChip.uid.uidByte[i];
+ if (RfChip.uid.uidByte[i] != bonUID[i]) {
+ refus++;
+ }
}
- pc.printf("\n\r");
-
- // 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("%d\n",refus);
+ printf("%d%d%d%d\n",RfChip.uid.uidByte[0],RfChip.uid.uidByte[1],RfChip.uid.uidByte[2],RfChip.uid.uidByte[3]);
+ /*printf("%d%d%d%d\n",bonUID[0],bonUID[1],bonUID[2],bonUID[3]);
+ printf("%d\n",RfChip.uid.size);*/
+ if (refus == 4) // UID accepté
+ {
+ printf("DATA1 OK \n");
+ printf("Temp = %d \n",RfChip.uid.uidByte[0]);
+ printf("Hum = %d \n",RfChip.uid.uidByte[1]);
+ printf("Lux = %d \n",RfChip.uid.uidByte[2]);
+ printf("water = %d \n",RfChip.uid.uidByte[3]);
+ // on allume la LED verte pendant quelques secondes
+ led_1 = 1; // On allume la LED 1
+ wait_ms(5000);
+ led_1 = 0; // On éteint la LED 1
+ }
+ else { // UID refusé
+ // on allume la LED rouge pendant quelques secondes
+ printf("DATA Error\n");
+ led_2 = 1;
+ wait_ms(5000);
+ led_2 = 0;
+ }
}
-
}
\ No newline at end of file
