Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated headers, included enroll example

  • Loading branch information...
commit be9bc77638e75331de1ceda23b059c0f99f0935a 1 parent 2ab7801
@ladyada ladyada authored
View
30 Adafruit_Fingerprint.cpp
@@ -1,10 +1,10 @@
/***************************************************
- This is a library for the BMP085 Barometric Pressure & Temp Sensor
+ This is a library for our optical Fingerprint sensor
Designed specifically to work with the Adafruit BMP085 Breakout
- ----> https://www.adafruit.com/products/391
+ ----> http://www.adafruit.com/products/751
- These displays use I2C to communicate, 2 pins are required to
+ 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
@@ -63,8 +63,8 @@ uint8_t Adafruit_Fingerprint::getImage(void) {
return packet[1];
}
-uint8_t Adafruit_Fingerprint::image2Tz(void) {
- uint8_t packet[] = {FINGERPRINT_IMAGE2TZ, 1}; // store in slot #1
+uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
+ uint8_t packet[] = {FINGERPRINT_IMAGE2TZ, slot};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
@@ -74,6 +74,26 @@ uint8_t Adafruit_Fingerprint::image2Tz(void) {
}
+uint8_t Adafruit_Fingerprint::createModel(void) {
+ uint8_t packet[] = {FINGERPRINT_REGMODEL};
+ writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
+ uint8_t len = getReply(packet);
+
+ if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
+ return -1;
+ return packet[1];
+}
+
+
+uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
+ uint8_t packet[] = {FINGERPRINT_STORE, 0x01, id >> 8, id & 0xFF};
+ writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
+ uint8_t len = getReply(packet);
+
+ if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
+ return -1;
+ return packet[1];
+}
uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
fingerID = 0xFFFF;
View
23 Adafruit_Fingerprint.h
@@ -1,3 +1,18 @@
+/***************************************************
+ This is a library 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
+ ****************************************************/
#if (ARDUINO >= 100)
#include "Arduino.h"
@@ -15,6 +30,8 @@
#define FINGERPRINT_FEATUREFAIL 0x07
#define FINGERPRINT_NOMATCH 0x08
#define FINGERPRINT_NOTFOUND 0x09
+#define FINGERPRINT_ENROLLMISMATCH 0x0A
+#define FINGERPRINT_BADLOCATION 0x0B
#define FINGERPRINT_DBRANGEFAIL 0x0C
#define FINGERPRINT_UPLOADFEATUREFAIL 0x0D
#define FINGERPRINT_PACKETRESPONSEFAIL 0x0E
@@ -40,6 +57,8 @@
#define FINGERPRINT_GETIMAGE 0x01
#define FINGERPRINT_IMAGE2TZ 0x02
+#define FINGERPRINT_REGMODEL 0x05
+#define FINGERPRINT_STORE 0x06
#define FINGERPRINT_VERIFYPASSWORD 0x13
#define FINGERPRINT_HISPEEDSEARCH 0x1B
@@ -55,7 +74,9 @@ class Adafruit_Fingerprint {
boolean verifyPassword(void);
uint8_t getImage(void);
- uint8_t image2Tz(void);
+ uint8_t image2Tz(uint8_t slot = 1);
+ uint8_t createModel(void);
+ uint8_t storeModel(uint16_t id);
uint8_t fingerFastSearch(void);
void writePacket(uint32_t addr, uint8_t packettype, uint16_t len, uint8_t *packet);
uint8_t getReply(uint8_t packet[], uint16_t timeout=DEFAULTTIMEOUT);
View
2  README.txt
@@ -1,7 +1,7 @@
This is a library for our optical Fingerprint sensor
Pick one up today in the adafruit shop!
- ------> http://www.adafruit.com/
+ ------> http://www.adafruit.com/products/751
These displays use TTL Serial to communicate, 2 pins are required to
interface
View
193 examples/enroll/enroll.ino
@@ -0,0 +1,193 @@
+/***************************************************
+ 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 <Adafruit_Fingerprint.h>
+#include <SoftwareSerial.h>
+
+// pin #2 is IN from sensor (GREEN wire)
+// pin #3 is OUT from arduino (WHITE wire)
+SoftwareSerial mySerial(2, 3);
+
+Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
+
+void setup()
+{
+ Serial.begin(9600);
+ Serial.println("fingertest");
+
+ // set the data rate for the sensor serial port
+ finger.begin(57600);
+
+ if (finger.verifyPassword()) {
+ Serial.println("Found fingerprint sensor!");
+ } else {
+ Serial.println("Did not find fingerprint sensor :(");
+ while (1);
+ }
+}
+
+void loop() // run over and over again
+{
+ Serial.println("Type in the ID # you want to save this finger as...");
+ uint8_t id = 0;
+ while (true) {
+ while (! Serial.available());
+ char c = Serial.read();
+ if (! isdigit(c)) break;
+ id *= 10;
+ id += c - '0';
+ }
+ Serial.print("Enrolling ID #");
+ Serial.println(id);
+
+ while (! getFingerprintEnroll(id) );
+}
+
+uint8_t getFingerprintEnroll(uint8_t id) {
+ uint8_t p = -1;
+ Serial.println("Waiting for valid finger to enroll");
+ while (p != FINGERPRINT_OK) {
+ p = finger.getImage();
+ switch (p) {
+ case FINGERPRINT_OK:
+ Serial.println("Image taken");
+ break;
+ case FINGERPRINT_NOFINGER:
+ Serial.println(".");
+ break;
+ case FINGERPRINT_PACKETRECIEVEERR:
+ Serial.println("Communication error");
+ break;
+ case FINGERPRINT_IMAGEFAIL:
+ Serial.println("Imaging error");
+ break;
+ default:
+ Serial.println("Unknown error");
+ break;
+ }
+ }
+
+ // OK success!
+
+ p = finger.image2Tz(1);
+ switch (p) {
+ case FINGERPRINT_OK:
+ Serial.println("Image converted");
+ break;
+ case FINGERPRINT_IMAGEMESS:
+ Serial.println("Image too messy");
+ return p;
+ case FINGERPRINT_PACKETRECIEVEERR:
+ Serial.println("Communication error");
+ return p;
+ case FINGERPRINT_FEATUREFAIL:
+ Serial.println("Could not find fingerprint features");
+ return p;
+ case FINGERPRINT_INVALIDIMAGE:
+ Serial.println("Could not find fingerprint features");
+ return p;
+ default:
+ Serial.println("Unknown error");
+ return p;
+ }
+
+ Serial.println("Remove finger");
+ delay(2000);
+ p = 0;
+ while (p != FINGERPRINT_NOFINGER) {
+ p = finger.getImage();
+ }
+
+ p = -1;
+ Serial.println("Place same finger again");
+ while (p != FINGERPRINT_OK) {
+ p = finger.getImage();
+ switch (p) {
+ case FINGERPRINT_OK:
+ Serial.println("Image taken");
+ break;
+ case FINGERPRINT_NOFINGER:
+ Serial.print(".");
+ break;
+ case FINGERPRINT_PACKETRECIEVEERR:
+ Serial.println("Communication error");
+ break;
+ case FINGERPRINT_IMAGEFAIL:
+ Serial.println("Imaging error");
+ break;
+ default:
+ Serial.println("Unknown error");
+ break;
+ }
+ }
+
+ // OK success!
+
+ p = finger.image2Tz(2);
+ switch (p) {
+ case FINGERPRINT_OK:
+ Serial.println("Image converted");
+ break;
+ case FINGERPRINT_IMAGEMESS:
+ Serial.println("Image too messy");
+ return p;
+ case FINGERPRINT_PACKETRECIEVEERR:
+ Serial.println("Communication error");
+ return p;
+ case FINGERPRINT_FEATUREFAIL:
+ Serial.println("Could not find fingerprint features");
+ return p;
+ case FINGERPRINT_INVALIDIMAGE:
+ Serial.println("Could not find fingerprint features");
+ return p;
+ default:
+ Serial.println("Unknown error");
+ return p;
+ }
+
+
+ // OK converted!
+ p = finger.createModel();
+ if (p == FINGERPRINT_OK) {
+ Serial.println("Prints matched!");
+ } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
+ Serial.println("Communication error");
+ return p;
+ } else if (p == FINGERPRINT_ENROLLMISMATCH) {
+ Serial.println("Fingerprints did not match");
+ return p;
+ } else {
+ Serial.println("Unknown error");
+ return p;
+ }
+
+ p = finger.storeModel(id);
+ if (p == FINGERPRINT_OK) {
+ Serial.println("Stored!");
+ } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
+ Serial.println("Communication error");
+ return p;
+ } else if (p == FINGERPRINT_BADLOCATION) {
+ Serial.println("Could not store in that location");
+ return p;
+ } else if (p == FINGERPRINT_FLASHERR) {
+ Serial.println("Error writing to flash");
+ return p;
+ } else {
+ Serial.println("Unknown error");
+ return p;
+ }
+}
View
20 examples/fingerprint/fingerprint.ino
@@ -1,5 +1,21 @@
-#include <Adafruit_Fingerprint.h>
+/***************************************************
+ 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 <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
// pin #2 is IN from sensor (GREEN wire)
@@ -109,4 +125,4 @@ int getFingerprintIDez() {
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.