Library for fingerprint R503 Adaptation from Arduino Library
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
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
Diff: main.cpp
- Revision:
- 7:afa17a46252b
- Parent:
- 6:b2f55a604fbe
- Child:
- 9:0e0ddc4a53e3
--- a/main.cpp Wed Mar 17 14:14:55 2021 +0000 +++ b/main.cpp Sat Mar 20 22:54:22 2021 +0000 @@ -1,47 +1,63 @@ /*************************************************** 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 + + STM32 adaptation by Christian Dupaty 03/2021 ****************************************************/ - #include <Fingerprint.h> #include "mbed.h" -DigitalOut myled(LED1); + +DigitalOut ledV(LED1); // for various information without terminal Serial pc(USBTX, USBRX); // tx, rx +Fingerprint finger(PC_1,PC_0,0x0); // TX,TX,pass +InterruptIn fD(PB_0); // IT from fingerprint detection (see datasheet WAKEUP) +DigitalIn btnBleu(USER_BUTTON); // to start enroll + +bool fingerON=false; -Fingerprint finger(PC_1,PC_0,PB_0,0x0); // TX,TX,RESET,pass +// interrupt funtion +void fingerDetect(void) +{ + ledV=1; + wait_ms(100); + ledV=0; + fingerON=true; +} + +// original setup fonction on Arduino void setup() { pc.baud(9600); wait_ms(100); - pc.printf("\n\nAdafruit finger detect test"); + pc.printf("\nR503 Finger detect test\nSTM32 version with MBED compiler and library\n"); // set the data rate for the sensor serial port finger.begin(57600); - wait_ms(5); + wait_ms(200); if (finger.verifyPassword()) { - pc.printf("Found fingerprint sensor!"); + pc.printf("\nFound fingerprint sensor!\n"); } else { - pc.printf("Did not find fingerprint sensor :("); + pc.printf("\nDid not find fingerprint sensor -> STOP !!!!\n"); while (1) { - wait_ms(1); + ledV=1; + wait_ms(100); + ledV=0; + wait_ms(100); } } - pc.printf("Reading sensor parameters"); + pc.printf("Reading sensor parameters\n"); finger.getParameters(); pc.printf("Status: 0x%X\n",finger.status_reg); pc.printf("Sys ID: 0x%X\n",finger.system_id); @@ -54,31 +70,33 @@ finger.getTemplateCount(); if (finger.templateCount == 0) { - pc.printf("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example."); + pc.printf("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.\n"); } else { - pc.printf("Waiting for valid finger..."); + pc.printf("Waiting for valid finger...\n"); pc.printf("Sensor contains : %d templates\n",finger.templateCount); } + fD.fall(&fingerDetect); } +// -------------------------------------- uint8_t getFingerprintID() { uint8_t p = finger.getImage(); switch (p) { case FINGERPRINT_OK: - pc.printf("Image taken"); + pc.printf("Image taken\n"); break; case FINGERPRINT_NOFINGER: - pc.printf("No finger detected"); + pc.printf("No finger detected\n"); return p; case FINGERPRINT_PACKETRECIEVEERR: - pc.printf("Communication error"); + pc.printf("Communication error\n"); return p; case FINGERPRINT_IMAGEFAIL: - pc.printf("Imaging error"); + pc.printf("Imaging error\n"); return p; default: - pc.printf("Unknown error"); + pc.printf("Unknown error\n"); return p; } @@ -87,37 +105,37 @@ p = finger.image2Tz(); switch (p) { case FINGERPRINT_OK: - pc.printf("Image converted"); + pc.printf("Image converted\n"); break; case FINGERPRINT_IMAGEMESS: - pc.printf("Image too messy"); + pc.printf("Image too messy\n"); return p; case FINGERPRINT_PACKETRECIEVEERR: - pc.printf("Communication error"); + pc.printf("Communication error\n"); return p; case FINGERPRINT_FEATUREFAIL: - pc.printf("Could not find fingerprint features"); + pc.printf("Could not find fingerprint feature\n"); return p; case FINGERPRINT_INVALIDIMAGE: - pc.printf("Could not find fingerprint features"); + pc.printf("Could not find fingerprint features\n"); return p; default: - pc.printf("Unknown error"); + pc.printf("Unknown error\n"); return p; } // OK converted! p = finger.fingerSearch(); if (p == FINGERPRINT_OK) { - pc.printf("Found a print match!"); + pc.printf("Found a print match!\n"); } else if (p == FINGERPRINT_PACKETRECIEVEERR) { - pc.printf("Communication error"); + pc.printf("Communication error\n"); return p; } else if (p == FINGERPRINT_NOTFOUND) { - pc.printf("Did not find a match"); + pc.printf("Did not find a match\n"); return p; } else { - pc.printf("Unknown error"); + pc.printf("Unknown error\n"); return p; } @@ -145,14 +163,57 @@ return finger.fingerID; } +void demoLED(void) +{ +// control (3 on)(4off), speed (0-255) , color (1 red, 2 blue, 3 purple), cycles (0 infinit,- 255) +// red + finger.LEDcontrol(3,128,1,10); + wait_ms(500); +// blue + finger.LEDcontrol(3,128,2,10); + wait_ms(500); +// cyan + finger.LEDcontrol(3,128,3,10); + wait_ms(500); +// flash 5 + finger.LEDcontrol(2,10,1,5); + wait_ms(1000); +// slow light on + finger.LEDcontrol(5,50,2,5); + wait_ms(1000); +// flash slow + finger.LEDcontrol(1,50,2,5); + wait_ms(1000); +} + int main(void) // run over and over again { +unsigned char c=1; setup(); + demoLED(); + finger.LEDcontrol(3,128,1,10); + pc.printf("\nPret ! \n"); while(1) { - getFingerprintID(); - wait_ms(50); //don't ned to run this at full speed. + + if (fingerON) + { + pc.printf("Doigt detecte ! \n"); + fingerON=false; + getFingerprintID(); + pc.printf("\nPret ! \n"); + } + if (!btnBleu) + { + pc.printf("\nEnregistrement empreinte \n"); + c=finger.createModel(); + if (c==FINGERPRINT_OK) pc.printf("Empreinte enregistree \n"); + if (c==FINGERPRINT_PACKETRECIEVEERR) pc.printf("Erreur de communication \n"); + if (c==FINGERPRINT_ENROLLMISMATCH) pc.printf("Erreur de scan \n"); + pc.printf("\nPret ! \n"); + } + wait_ms(500); //don't need to run this at full speed. } - return 0; + // return 0; }