Library for fingerprint R503 Adaptation from Arduino Library

Dependencies:   Fingerprint-Lib

This a library and demo for fingerprint R503

For datasheet, see here -> https://cdn-shop.adafruit.com/product-files/4651/4651_R503%20fingerprint%20module%20user%20manual.pdf

This is an adaptation of Adafruit library (Arduino) to ARM MBED, tested on NUCLEO L073RZ

https://os.mbed.com/media/uploads/cdupaty/r503b.jpg https://os.mbed.com/media/uploads/cdupaty/r503-nucleol073rzpetit.jpg

For this exemple default connexions on NUCLEOL073RZ are :

TX <-> PC_0

RX <-> PC_1

WAKEUP <-> PB_0 , this is an Interrupt , you must connect a pull-up resistor (4K to 15k) between WAKEUP and DC3.3v

Power Supply 3.3v on Arduino connector

3.3VT : 5v on Arduino connector

IMPORTANT !!! There ara yet some bugs with communications UART

Revision:
5:022e24a51359
Parent:
4:a2d1329d042c
Child:
6:b2f55a604fbe
--- a/main.cpp	Wed Jan 22 12:34:48 2020 +0000
+++ b/main.cpp	Tue Mar 16 16:33:34 2021 +0000
@@ -1,22 +1,157 @@
-// Serial demo using mbed 5
+/***************************************************
+  This is an example sketch for our optical Fingerprint sensor
+
+  Designed specifically to work with the Adafruit BMP085 Breakout
+  ----> http://www.adafruit.com/products/751
 
+  These displays use TTL Serial to communicate, 2 pins are required to
+  interface
+  Adafruit invests time and resources providing this open source code,
+  please support Adafruit and open-source hardware by purchasing
+  products from Adafruit!
+
+  Written by Limor Fried/Ladyada for Adafruit Industries.
+  BSD license, all text above must be included in any redistribution
+ ****************************************************/
+
+
+#include <Fingerprint.h>
 #include "mbed.h"
-
 DigitalOut myled(LED1);
 Serial pc(USBTX, USBRX); // tx, rx
 
-int main() {
-    char c ;
-    pc.printf("Enter a character>");
-    while(1) {
-        myled = 0;  // turn on
-        c = pc.getc();
-        myled = 1;  // turn off
-        pc.putc(c);
-        pc.putc(c); // echo twice
-        pc.putc('\r');
-        pc.putc('\n');
-        wait(0.5);
-        pc.printf("Enter a character>");
+Fingerprint finger(PC_1,PC_0,PB_0,0x0); // TX,TX,RESET,pass
+
+void setup()
+{
+  pc.baud(9600);
+  wait_ms(100);
+  pc.printf("\n\nAdafruit finger detect test");
+
+  // set the data rate for the sensor serial port
+  finger.begin(57600);
+  wait_ms(5);
+  if (finger.verifyPassword()) {
+    pc.printf("Found fingerprint sensor!");
+  } else {
+    pc.printf("Did not find fingerprint sensor :(");
+    while (1)
+    {
+         wait_ms(1); 
     }
+  }
+
+  pc.printf("Reading sensor parameters");
+  finger.getParameters();
+  pc.printf("Status: 0x%X\n",finger.status_reg);
+  pc.printf("Sys ID: 0x%X\n",system_id);
+  pc.printf("Capacity: %d\n",capacity);
+  pc.printf("Security level: %d\n",security_level);
+  pc.printf("Device address: 0x%X\n",device_addr);
+  pc.printf("Packet len: %d\n",packet_len);
+  pc.printf("Baud rate: %d\n",baud_rate);
+
+  finger.getTemplateCount();
+
+  if (finger.templateCount == 0) {
+    pc.printf("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
+  }
+  else {
+    pc.printf("Waiting for valid finger...");
+      pc.printf("Sensor contains "); pc.printfinger.templateCount); pc.printf(" templates");
+  }
 }
+
+int main(void)                    // run over and over again
+{
+  setup();
+  while(1)
+  {
+  getFingerprintID();
+  wait_ms(50);            //don't ned to run this at full speed.
+  }
+  return 0;
+}
+
+uint8_t getFingerprintID() {
+  uint8_t p = finger.getImage();
+  switch (p) {
+    case FINGERPRINT_OK:
+      pc.printf("Image taken");
+      break;
+    case FINGERPRINT_NOFINGER:
+      pc.printf("No finger detected");
+      return p;
+    case FINGERPRINT_PACKETRECIEVEERR:
+      pc.printf("Communication error");
+      return p;
+    case FINGERPRINT_IMAGEFAIL:
+      pc.printf("Imaging error");
+      return p;
+    default:
+      pc.printf("Unknown error");
+      return p;
+  }
+
+  // OK success!
+
+  p = finger.image2Tz();
+  switch (p) {
+    case FINGERPRINT_OK:
+      pc.printf("Image converted");
+      break;
+    case FINGERPRINT_IMAGEMESS:
+      pc.printf("Image too messy");
+      return p;
+    case FINGERPRINT_PACKETRECIEVEERR:
+      pc.printf("Communication error");
+      return p;
+    case FINGERPRINT_FEATUREFAIL:
+      pc.printf("Could not find fingerprint features");
+      return p;
+    case FINGERPRINT_INVALIDIMAGE:
+      pc.printf("Could not find fingerprint features");
+      return p;
+    default:
+      pc.printf("Unknown error");
+      return p;
+  }
+
+  // OK converted!
+  p = finger.fingerSearch();
+  if (p == FINGERPRINT_OK) {
+    pc.printf("Found a print match!");
+  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
+    pc.printf("Communication error");
+    return p;
+  } else if (p == FINGERPRINT_NOTFOUND) {
+    pc.printf("Did not find a match");
+    return p;
+  } else {
+    pc.printf("Unknown error");
+    return p;
+  }
+
+  // found a match!
+  pc.printf("Found ID #"); pc.printfinger.fingerID);
+  pc.printf(" with confidence of "); pc.printfinger.confidence);
+
+  return finger.fingerID;
+}
+
+// returns -1 if failed, otherwise returns ID #
+int getFingerprintIDez() {
+  uint8_t p = finger.getImage();
+  if (p != FINGERPRINT_OK)  return -1;
+
+  p = finger.image2Tz();
+  if (p != FINGERPRINT_OK)  return -1;
+
+  p = finger.fingerFastSearch();
+  if (p != FINGERPRINT_OK)  return -1;
+
+  // found a match!
+  pc.printf("Found ID #"); pc.printfinger.fingerID);
+  pc.printf(" with confidence of "); pc.printfinger.confidence);
+  return finger.fingerID;
+}
\ No newline at end of file