Update fingerprint library to v2.0.4

This commit is contained in:
Theo Arends 2020-11-11 12:35:41 +01:00
parent 4824132413
commit daec8b9eb5
48 changed files with 1124 additions and 626 deletions

View File

@ -0,0 +1,46 @@
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
- **For Arduino projects check these very common issues to ensure they don't apply**:
- For uploading sketches or communicating with the board make sure you're using
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
- **Be sure you are supplying adequate power to the board.** Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
- **Double check all soldering joints and connections.** Flakey connections
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
- **Ensure you are using an official Arduino or Adafruit board.** We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
VERSION HERE**
- List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): **LIST REPRO STEPS BELOW**

View File

@ -0,0 +1,26 @@
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
Before you open the request please review the following guidelines and tips to
help it be more easily integrated:
- **Describe the scope of your change--i.e. what the change does and what parts
of the code were modified.** This will help us understand any risks of integrating
the code.
- **Describe any known limitations with your change.** For example if the change
doesn't apply to a supported platform of the library please mention it.
- **Please run any tests or examples that can exercise your modified code.** We
strive to not break users of the code and running tests/examples helps with this
process.
Thank you again for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to manage and
can't immediately respond to every request. There is no need to bump or check in
on a pull request (it will clutter the discussion of the request).
Also don't be worried if the request is closed or not integrated--sometimes the
priorities of Adafruit's GitHub code (education, ease of use) might not match the
priorities of the pull request. Don't fret, the open source community thrives on
forks and GitHub makes it easy to keep your changes in a forked repo.
After reviewing the guidelines above you can delete this text from the pull request.

View File

@ -0,0 +1,34 @@
name: Arduino Library CI
on: [pull_request, push, repository_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci
- name: pre-install
run: bash ci/actions_install.sh
- name: test platforms
run: python3 ci/build_platform.py main_platforms
- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit Fingerprint Arduino Library"
run: bash ci/doxy_gen_and_deploy.sh

View File

@ -0,0 +1 @@
*~

View File

@ -0,0 +1,565 @@
/*!
* @file Adafruit_Fingerprint.cpp
*
* @mainpage Adafruit Fingerprint Sensor Library
*
* @section intro_sec Introduction
*
* This is a library for our optical Fingerprint sensor
*
* Designed specifically to work with the Adafruit Fingerprint sensor
* ----> 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!
*
* @section author Author
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
*
* @section license License
*
* BSD license, all text above must be included in any redistribution
*
*/
#include "Adafruit_Fingerprint.h"
//#define FINGERPRINT_DEBUG
/*!
* @brief Gets the command packet
*/
#define GET_CMD_PACKET(...) \
uint8_t data[] = {__VA_ARGS__}; \
Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), \
data); \
writeStructuredPacket(packet); \
if (getStructuredPacket(&packet) != FINGERPRINT_OK) \
return FINGERPRINT_PACKETRECIEVEERR; \
if (packet.type != FINGERPRINT_ACKPACKET) \
return FINGERPRINT_PACKETRECIEVEERR;
/*!
* @brief Sends the command packet
*/
#define SEND_CMD_PACKET(...) \
GET_CMD_PACKET(__VA_ARGS__); \
return packet.data[0];
/***************************************************************************
PUBLIC FUNCTIONS
***************************************************************************/
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
/**************************************************************************/
/*!
@brief Instantiates sensor with Software Serial
@param ss Pointer to SoftwareSerial object
@param password 32-bit integer password (default is 0)
*/
/**************************************************************************/
//Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss,
Adafruit_Fingerprint::Adafruit_Fingerprint(TasmotaSerial *ss,
uint32_t password) {
thePassword = password;
theAddress = 0xFFFFFFFF;
hwSerial = NULL;
swSerial = ss;
mySerial = swSerial;
}
#endif
/**************************************************************************/
/*!
@brief Instantiates sensor with Hardware Serial
@param hs Pointer to HardwareSerial object
@param password 32-bit integer password (default is 0)
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs,
uint32_t password) {
thePassword = password;
theAddress = 0xFFFFFFFF;
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
swSerial = NULL;
#endif
hwSerial = hs;
mySerial = hwSerial;
}
/**************************************************************************/
/*!
@brief Instantiates sensor with a stream for Serial
@param serial Pointer to a Stream object
@param password 32-bit integer password (default is 0)
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(Stream *serial, uint32_t password) {
thePassword = password;
theAddress = 0xFFFFFFFF;
hwSerial = NULL;
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
swSerial = NULL;
#endif
mySerial = serial;
}
/**************************************************************************/
/*!
@brief Initializes serial interface and baud rate
@param baudrate Sensor's UART baud rate (usually 57600, 9600 or 115200)
*/
/**************************************************************************/
void Adafruit_Fingerprint::begin(uint32_t baudrate) {
delay(1000); // one second delay to let the sensor 'boot up'
if (hwSerial)
hwSerial->begin(baudrate);
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
if (swSerial)
swSerial->begin(baudrate);
#endif
}
/**************************************************************************/
/*!
@brief Verifies the sensors' access password (default password is
0x0000000). A good way to also check if the sensors is active and responding
@returns True if password is correct
*/
/**************************************************************************/
boolean Adafruit_Fingerprint::verifyPassword(void) {
return checkPassword() == FINGERPRINT_OK;
}
uint8_t Adafruit_Fingerprint::checkPassword(void) {
GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD, (uint8_t)(thePassword >> 24),
(uint8_t)(thePassword >> 16), (uint8_t)(thePassword >> 8),
(uint8_t)(thePassword & 0xFF));
if (packet.data[0] == FINGERPRINT_OK)
return FINGERPRINT_OK;
else
return FINGERPRINT_PACKETRECIEVEERR;
}
/**************************************************************************/
/*!
@brief Get the sensors parameters, fills in the member variables
status_reg, system_id, capacity, security_level, device_addr, packet_len
and baud_rate
@returns True if password is correct
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getParameters(void) {
GET_CMD_PACKET(FINGERPRINT_READSYSPARAM);
status_reg = ((uint16_t)packet.data[1] << 8) | packet.data[2];
system_id = ((uint16_t)packet.data[3] << 8) | packet.data[4];
capacity = ((uint16_t)packet.data[5] << 8) | packet.data[6];
security_level = ((uint16_t)packet.data[7] << 8) | packet.data[8];
device_addr = ((uint32_t)packet.data[9] << 24) |
((uint32_t)packet.data[10] << 16) |
((uint32_t)packet.data[11] << 8) | (uint32_t)packet.data[12];
packet_len = ((uint16_t)packet.data[13] << 8) | packet.data[14];
if (packet_len == 0) {
packet_len = 32;
} else if (packet_len == 1) {
packet_len = 64;
} else if (packet_len == 2) {
packet_len = 128;
} else if (packet_len == 3) {
packet_len = 256;
}
baud_rate = (((uint16_t)packet.data[15] << 8) | packet.data[16]) * 9600;
return packet.data[0];
}
/**************************************************************************/
/*!
@brief Ask the sensor to take an image of the finger pressed on surface
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_NOFINGER</code> if no finger detected
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_IMAGEFAIL</code> on imaging error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getImage(void) {
SEND_CMD_PACKET(FINGERPRINT_GETIMAGE);
}
/**************************************************************************/
/*!
@brief Ask the sensor to convert image to feature template
@param slot Location to place feature template (put one in 1 and another in
2 for verification to create model)
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_IMAGEMESS</code> if image is too messy
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_FEATUREFAIL</code> on failure to identify
fingerprint features
@returns <code>FINGERPRINT_INVALIDIMAGE</code> on failure to identify
fingerprint features
*/
uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ, slot);
}
/**************************************************************************/
/*!
@brief Ask the sensor to take two print feature template and create a
model
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_ENROLLMISMATCH</code> on mismatch of fingerprints
*/
uint8_t Adafruit_Fingerprint::createModel(void) {
SEND_CMD_PACKET(FINGERPRINT_REGMODEL);
}
/**************************************************************************/
/*!
@brief Ask the sensor to store the calculated model for later matching
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written
to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8),
(uint8_t)(location & 0xFF));
}
/**************************************************************************/
/*!
@brief Ask the sensor to load a fingerprint model from flash into buffer 1
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::loadModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8),
(uint8_t)(location & 0xFF));
}
/**************************************************************************/
/*!
@brief Ask the sensor to transfer 256-byte fingerprint template from the
buffer to the UART
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::getModel(void) {
SEND_CMD_PACKET(FINGERPRINT_UPLOAD, 0x01);
}
/**************************************************************************/
/*!
@brief Ask the sensor to delete a model in memory
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written
to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::deleteModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(location >> 8),
(uint8_t)(location & 0xFF), 0x00, 0x01);
}
/**************************************************************************/
/*!
@brief Ask the sensor to delete ALL models in memory
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written
to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
SEND_CMD_PACKET(FINGERPRINT_EMPTY);
}
/**************************************************************************/
/*!
@brief Ask the sensor to search the current slot 1 fingerprint features to
match saved templates. The matching location is stored in <b>fingerID</b> and
the matching confidence in <b>confidence</b>
@returns <code>FINGERPRINT_OK</code> on fingerprint match success
@returns <code>FINGERPRINT_NOTFOUND</code> no match made
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
// high speed search of slot #1 starting at page 0x0000 and page #0x00A3
GET_CMD_PACKET(FINGERPRINT_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3);
fingerID = 0xFFFF;
confidence = 0xFFFF;
fingerID = packet.data[1];
fingerID <<= 8;
fingerID |= packet.data[2];
confidence = packet.data[3];
confidence <<= 8;
confidence |= packet.data[4];
return packet.data[0];
}
/**************************************************************************/
/*!
@brief Control the built in LED
@param on True if you want LED on, False to turn LED off
@returns <code>FINGERPRINT_OK</code> on success
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::LEDcontrol(bool on) {
if (on) {
SEND_CMD_PACKET(FINGERPRINT_LEDON);
} else {
SEND_CMD_PACKET(FINGERPRINT_LEDOFF);
}
}
/**************************************************************************/
/*!
@brief Control the built in Aura LED (if exists). Check datasheet/manual
for different colors and control codes available
@param control The control code (e.g. breathing, full on)
@param speed How fast to go through the breathing/blinking cycles
@param coloridx What color to light the indicator
@param count How many repeats of blinks/breathing cycles
@returns <code>FINGERPRINT_OK</code> on fingerprint match success
@returns <code>FINGERPRINT_NOTFOUND</code> no match made
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::LEDcontrol(uint8_t control, uint8_t speed,
uint8_t coloridx, uint8_t count) {
SEND_CMD_PACKET(FINGERPRINT_AURALEDCONFIG, control, speed, coloridx, count);
}
/**************************************************************************/
/*!
@brief Ask the sensor to search the current slot fingerprint features to
match saved templates. The matching location is stored in <b>fingerID</b> and
the matching confidence in <b>confidence</b>
@param slot The slot to use for the print search, defaults to 1
@returns <code>FINGERPRINT_OK</code> on fingerprint match success
@returns <code>FINGERPRINT_NOTFOUND</code> no match made
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::fingerSearch(uint8_t slot) {
// search of slot starting thru the capacity
GET_CMD_PACKET(FINGERPRINT_SEARCH, slot, 0x00, 0x00, capacity >> 8,
capacity & 0xFF);
fingerID = 0xFFFF;
confidence = 0xFFFF;
fingerID = packet.data[1];
fingerID <<= 8;
fingerID |= packet.data[2];
confidence = packet.data[3];
confidence <<= 8;
confidence |= packet.data[4];
return packet.data[0];
}
/**************************************************************************/
/*!
@brief Ask the sensor for the number of templates stored in memory. The
number is stored in <b>templateCount</b> on success.
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
GET_CMD_PACKET(FINGERPRINT_TEMPLATECOUNT);
templateCount = packet.data[1];
templateCount <<= 8;
templateCount |= packet.data[2];
return packet.data[0];
}
/**************************************************************************/
/*!
@brief Set the password on the sensor (future communication will require
password verification so don't forget it!!!)
@param password 32-bit password code
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::setPassword(uint32_t password) {
SEND_CMD_PACKET(FINGERPRINT_SETPASSWORD, (password >> 24), (password >> 16),
(password >> 8), password);
}
/**************************************************************************/
/*!
@brief Helper function to process a packet and send it over UART to the
sensor
@param packet A structure containing the bytes to transmit
*/
/**************************************************************************/
void Adafruit_Fingerprint::writeStructuredPacket(
const Adafruit_Fingerprint_Packet &packet) {
mySerial->write((uint8_t)(packet.start_code >> 8));
mySerial->write((uint8_t)(packet.start_code & 0xFF));
mySerial->write(packet.address[0]);
mySerial->write(packet.address[1]);
mySerial->write(packet.address[2]);
mySerial->write(packet.address[3]);
mySerial->write(packet.type);
uint16_t wire_length = packet.length + 2;
mySerial->write((uint8_t)(wire_length >> 8));
mySerial->write((uint8_t)(wire_length & 0xFF));
#ifdef FINGERPRINT_DEBUG
Serial.print("-> 0x");
Serial.print((uint8_t)(packet.start_code >> 8), HEX);
Serial.print(", 0x");
Serial.print((uint8_t)(packet.start_code & 0xFF), HEX);
Serial.print(", 0x");
Serial.print(packet.address[0], HEX);
Serial.print(", 0x");
Serial.print(packet.address[1], HEX);
Serial.print(", 0x");
Serial.print(packet.address[2], HEX);
Serial.print(", 0x");
Serial.print(packet.address[3], HEX);
Serial.print(", 0x");
Serial.print(packet.type, HEX);
Serial.print(", 0x");
Serial.print((uint8_t)(wire_length >> 8), HEX);
Serial.print(", 0x");
Serial.print((uint8_t)(wire_length & 0xFF), HEX);
#endif
uint16_t sum = ((wire_length) >> 8) + ((wire_length)&0xFF) + packet.type;
for (uint8_t i = 0; i < packet.length; i++) {
mySerial->write(packet.data[i]);
sum += packet.data[i];
#ifdef FINGERPRINT_DEBUG
Serial.print(", 0x");
Serial.print(packet.data[i], HEX);
#endif
}
mySerial->write((uint8_t)(sum >> 8));
mySerial->write((uint8_t)(sum & 0xFF));
#ifdef FINGERPRINT_DEBUG
Serial.print(", 0x");
Serial.print((uint8_t)(sum >> 8), HEX);
Serial.print(", 0x");
Serial.println((uint8_t)(sum & 0xFF), HEX);
#endif
return;
}
/**************************************************************************/
/*!
@brief Helper function to receive data over UART from the sensor and
process it into a packet
@param packet A structure containing the bytes received
@param timeout how many milliseconds we're willing to wait
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_TIMEOUT</code> or
<code>FINGERPRINT_BADPACKET</code> on failure
*/
/**************************************************************************/
uint8_t
Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet *packet,
uint16_t timeout) {
uint8_t byte;
uint16_t idx = 0, timer = 0;
#ifdef FINGERPRINT_DEBUG
Serial.print("<- ");
#endif
while (true) {
while (!mySerial->available()) {
delay(1);
timer++;
if (timer >= timeout) {
#ifdef FINGERPRINT_DEBUG
Serial.println("Timed out");
#endif
return FINGERPRINT_TIMEOUT;
}
}
byte = mySerial->read();
#ifdef FINGERPRINT_DEBUG
Serial.print("0x");
Serial.print(byte, HEX);
Serial.print(", ");
#endif
switch (idx) {
case 0:
if (byte != (FINGERPRINT_STARTCODE >> 8))
continue;
packet->start_code = (uint16_t)byte << 8;
break;
case 1:
packet->start_code |= byte;
if (packet->start_code != FINGERPRINT_STARTCODE)
return FINGERPRINT_BADPACKET;
break;
case 2:
case 3:
case 4:
case 5:
packet->address[idx - 2] = byte;
break;
case 6:
packet->type = byte;
break;
case 7:
packet->length = (uint16_t)byte << 8;
break;
case 8:
packet->length |= byte;
break;
default:
packet->data[idx - 9] = byte;
if ((idx - 8) == packet->length) {
#ifdef FINGERPRINT_DEBUG
Serial.println(" OK ");
#endif
return FINGERPRINT_OK;
}
break;
}
idx++;
}
// Shouldn't get here so...
return FINGERPRINT_BADPACKET;
}

View File

@ -0,0 +1,196 @@
#ifndef ADAFRUIT_FINGERPRINT_H
#define ADAFRUIT_FINGERPRINT_H
/*!
* @file Adafruit_Fingerprint.h
*/
#include "Arduino.h"
#if defined(__AVR__) || defined(ESP8266)
//#include <SoftwareSerial.h>
#include <TasmotaSerial.h>
#elif defined(FREEDOM_E300_HIFIVE1)
#include <SoftwareSerial32.h>
#define SoftwareSerial SoftwareSerial32
#endif
#define FINGERPRINT_OK 0x00 //!< Command execution is complete
#define FINGERPRINT_PACKETRECIEVEERR 0x01 //!< Error when receiving data package
#define FINGERPRINT_NOFINGER 0x02 //!< No finger on the sensor
#define FINGERPRINT_IMAGEFAIL 0x03 //!< Failed to enroll the finger
#define FINGERPRINT_IMAGEMESS \
0x06 //!< Failed to generate character file due to overly disorderly
//!< fingerprint image
#define FINGERPRINT_FEATUREFAIL \
0x07 //!< Failed to generate character file due to the lack of character point
//!< or small fingerprint image
#define FINGERPRINT_NOMATCH 0x08 //!< Finger doesn't match
#define FINGERPRINT_NOTFOUND 0x09 //!< Failed to find matching finger
#define FINGERPRINT_ENROLLMISMATCH \
0x0A //!< Failed to combine the character files
#define FINGERPRINT_BADLOCATION \
0x0B //!< Addressed PageID is beyond the finger library
#define FINGERPRINT_DBRANGEFAIL \
0x0C //!< Error when reading template from library or invalid template
#define FINGERPRINT_UPLOADFEATUREFAIL 0x0D //!< Error when uploading template
#define FINGERPRINT_PACKETRESPONSEFAIL \
0x0E //!< Module failed to receive the following data packages
#define FINGERPRINT_UPLOADFAIL 0x0F //!< Error when uploading image
#define FINGERPRINT_DELETEFAIL 0x10 //!< Failed to delete the template
#define FINGERPRINT_DBCLEARFAIL 0x11 //!< Failed to clear finger library
#define FINGERPRINT_PASSFAIL \
0x13 //!< Find whether the fingerprint passed or failed
#define FINGERPRINT_INVALIDIMAGE \
0x15 //!< Failed to generate image because of lac of valid primary image
#define FINGERPRINT_FLASHERR 0x18 //!< Error when writing flash
#define FINGERPRINT_INVALIDREG 0x1A //!< Invalid register number
#define FINGERPRINT_ADDRCODE 0x20 //!< Address code
#define FINGERPRINT_PASSVERIFY 0x21 //!< Verify the fingerprint passed
#define FINGERPRINT_STARTCODE \
0xEF01 //!< Fixed falue of EF01H; High byte transferred first
#define FINGERPRINT_COMMANDPACKET 0x1 //!< Command packet
#define FINGERPRINT_DATAPACKET \
0x2 //!< Data packet, must follow command packet or acknowledge packet
#define FINGERPRINT_ACKPACKET 0x7 //!< Acknowledge packet
#define FINGERPRINT_ENDDATAPACKET 0x8 //!< End of data packet
#define FINGERPRINT_TIMEOUT 0xFF //!< Timeout was reached
#define FINGERPRINT_BADPACKET 0xFE //!< Bad packet was sent
#define FINGERPRINT_GETIMAGE 0x01 //!< Collect finger image
#define FINGERPRINT_IMAGE2TZ 0x02 //!< Generate character file from image
#define FINGERPRINT_SEARCH 0x04 //!< Search for fingerprint in slot
#define FINGERPRINT_REGMODEL \
0x05 //!< Combine character files and generate template
#define FINGERPRINT_STORE 0x06 //!< Store template
#define FINGERPRINT_LOAD 0x07 //!< Read/load template
#define FINGERPRINT_UPLOAD 0x08 //!< Upload template
#define FINGERPRINT_DELETE 0x0C //!< Delete templates
#define FINGERPRINT_EMPTY 0x0D //!< Empty library
#define FINGERPRINT_READSYSPARAM 0x0F //!< Read system parameters
#define FINGERPRINT_SETPASSWORD 0x12 //!< Sets passwords
#define FINGERPRINT_VERIFYPASSWORD 0x13 //!< Verifies the password
#define FINGERPRINT_HISPEEDSEARCH \
0x1B //!< Asks the sensor to search for a matching fingerprint template to the
//!< last model generated
#define FINGERPRINT_TEMPLATECOUNT 0x1D //!< Read finger template numbers
#define FINGERPRINT_AURALEDCONFIG 0x35 //!< Aura LED control
#define FINGERPRINT_LEDON 0x50 //!< Turn on the onboard LED
#define FINGERPRINT_LEDOFF 0x51 //!< Turn off the onboard LED
#define FINGERPRINT_LED_BREATHING 0x01 //!< Breathing light
#define FINGERPRINT_LED_FLASHING 0x02 //!< Flashing light
#define FINGERPRINT_LED_ON 0x03 //!< Always on
#define FINGERPRINT_LED_OFF 0x04 //!< Always off
#define FINGERPRINT_LED_GRADUAL_ON 0x05 //!< Gradually on
#define FINGERPRINT_LED_GRADUAL_OFF 0x06 //!< Gradually off
#define FINGERPRINT_LED_RED 0x01 //!< Red LED
#define FINGERPRINT_LED_BLUE 0x02 //!< Blue LED
#define FINGERPRINT_LED_PURPLE 0x03 //!< Purple LED
//#define FINGERPRINT_DEBUG
#define DEFAULTTIMEOUT 1000 //!< UART reading timeout in milliseconds
///! Helper class to craft UART packets
struct Adafruit_Fingerprint_Packet {
/**************************************************************************/
/*!
@brief Create a new UART-borne packet
@param type Command, data, ack type packet
@param length Size of payload
@param data Pointer to bytes of size length we will memcopy into the
internal buffer
*/
/**************************************************************************/
Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t *data) {
this->start_code = FINGERPRINT_STARTCODE;
this->type = type;
this->length = length;
address[0] = 0xFF;
address[1] = 0xFF;
address[2] = 0xFF;
address[3] = 0xFF;
if (length < 64)
memcpy(this->data, data, length);
else
memcpy(this->data, data, 64);
}
uint16_t start_code; ///< "Wakeup" code for packet detection
uint8_t address[4]; ///< 32-bit Fingerprint sensor address
uint8_t type; ///< Type of packet
uint16_t length; ///< Length of packet
uint8_t data[64]; ///< The raw buffer for packet payload
};
///! Helper class to communicate with and keep state for fingerprint sensors
class Adafruit_Fingerprint {
public:
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
// Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password = 0x0);
Adafruit_Fingerprint(TasmotaSerial *ss, uint32_t password = 0x0);
#endif
Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password = 0x0);
Adafruit_Fingerprint(Stream *serial, uint32_t password = 0x0);
void begin(uint32_t baud);
boolean verifyPassword(void);
uint8_t getParameters(void);
uint8_t getImage(void);
uint8_t image2Tz(uint8_t slot = 1);
uint8_t createModel(void);
uint8_t emptyDatabase(void);
uint8_t storeModel(uint16_t id);
uint8_t loadModel(uint16_t id);
uint8_t getModel(void);
uint8_t deleteModel(uint16_t id);
uint8_t fingerFastSearch(void);
uint8_t fingerSearch(uint8_t slot = 1);
uint8_t getTemplateCount(void);
uint8_t setPassword(uint32_t password);
uint8_t LEDcontrol(bool on);
uint8_t LEDcontrol(uint8_t control, uint8_t speed, uint8_t coloridx,
uint8_t count = 0);
void writeStructuredPacket(const Adafruit_Fingerprint_Packet &p);
uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet *p,
uint16_t timeout = DEFAULTTIMEOUT);
/// The matching location that is set by fingerFastSearch()
uint16_t fingerID;
/// The confidence of the fingerFastSearch() match, higher numbers are more
/// confidents
uint16_t confidence;
/// The number of stored templates in the sensor, set by getTemplateCount()
uint16_t templateCount;
uint16_t status_reg = 0x0; ///< The status register (set by getParameters)
uint16_t system_id = 0x0; ///< The system identifier (set by getParameters)
uint16_t capacity = 64; ///< The fingerprint capacity (set by getParameters)
uint16_t security_level = 0; ///< The security level (set by getParameters)
uint32_t device_addr =
0xFFFFFFFF; ///< The device address (set by getParameters)
uint16_t packet_len = 64; ///< The max packet length (set by getParameters)
uint16_t baud_rate = 57600; ///< The UART baud rate (set by getParameters)
private:
uint8_t checkPassword(void);
uint32_t thePassword;
uint32_t theAddress;
uint8_t recvPacket[20];
Stream *mySerial;
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
// SoftwareSerial *swSerial;
TasmotaSerial *swSerial;
#endif
HardwareSerial *hwSerial;
};
#endif

View File

@ -1,12 +1,16 @@
# Adafruit Fingerprint Sensor Library [![Build Status](https://travis-ci.org/adafruit/Adafruit-Fingerprint-Sensor-Library.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit-Fingerprint-Sensor-Library) # Adafruit-Fingerprint-Sensor-Library [![Build Status](https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-Fingerprint-Sensor-Library/html/index.html)
<img src="https://cdn-shop.adafruit.com/970x728/751-03.jpg" height="300"/> <img src="https://cdn-shop.adafruit.com/970x728/751-03.jpg" height="300"/>
<img src="https://cdn-shop.adafruit.com/1200x900/4651-00.jpg" height="300"/>
Secure your project with biometrics - this all-in-one optical fingerprint sensor will make adding fingerprint detection and verification super simple. These modules are typically used in safes - there's a high powered DSP chip that does the image rendering, calculation, feature-finding and searching. Connect to any microcontroller or system with TTL serial, and send packets of data to take photos, detect prints, hash and search. You can also enroll new fingers directly - up to 162 finger prints can be stored in the onboard FLASH memory. There's a red LED in the lens that lights up during a photo so you know its working. Secure your project with biometrics - this all-in-one optical fingerprint sensor will make adding fingerprint detection and verification super simple. These modules are typically used in safes - there's a high powered DSP chip that does the image rendering, calculation, feature-finding and searching. Connect to any microcontroller or system with TTL serial, and send packets of data to take photos, detect prints, hash and search. You can also enroll new fingers directly - up to 162 finger prints can be stored in the onboard FLASH memory. There's a red LED in the lens that lights up during a photo so you know its working.
The Rugged Panel Mount Fingerprint Sensor with Bi-Color LED Ring even has an LED ring built around the detection pad, which can be set to red, blue or purple (as well as some fading/blinking effects) for a great user experience.
Designed specifically to work with the Adafruit Fingerprint sensor
Designed specifically to work with the Adafruit Fingerprint sensors
* http://www.adafruit.com/products/751 * http://www.adafruit.com/products/751
* https://www.adafruit.com/product/4651
Pick one up today in the adafruit shop! Pick one up today in the adafruit shop!

View File

@ -13,16 +13,21 @@
#include <Adafruit_Fingerprint.h> #include <Adafruit_Fingerprint.h>
// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial... // For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire) // pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire) // pin #3 is OUT from arduino (WHITE wire)
// comment these two lines if using hardware serial // Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3); SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
// Using sensor without password // Using sensor without password
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

View File

@ -16,16 +16,22 @@
#include <Adafruit_Fingerprint.h> #include <Adafruit_Fingerprint.h>
// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial... // For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire) // pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire) // pin #3 is OUT from arduino (WHITE wire)
// comment these two lines if using hardware serial // Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3); SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup() void setup()

View File

@ -13,16 +13,22 @@
#include <Adafruit_Fingerprint.h> #include <Adafruit_Fingerprint.h>
// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial... // For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire) // pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire) // pin #3 is OUT from arduino (WHITE wire)
// comment these two lines if using hardware serial // Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3); SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup() void setup()

View File

@ -16,16 +16,22 @@
#include <Adafruit_Fingerprint.h> #include <Adafruit_Fingerprint.h>
// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial... // For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire) // pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire) // pin #3 is OUT from arduino (WHITE wire)
// comment these two lines if using hardware serial // Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3); SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
uint8_t id; uint8_t id;
@ -46,6 +52,16 @@ void setup()
Serial.println("Did not find fingerprint sensor :("); Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); } while (1) { delay(1); }
} }
Serial.println(F("Reading sensor parameters"));
finger.getParameters();
Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
Serial.print(F("Security level: ")); Serial.println(finger.security_level);
Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
} }
uint8_t readnumber(void) { uint8_t readnumber(void) {
@ -209,4 +225,6 @@ uint8_t getFingerprintEnroll() {
Serial.println("Unknown error"); Serial.println("Unknown error");
return p; return p;
} }
return true;
} }

View File

@ -17,16 +17,22 @@
#include <Adafruit_Fingerprint.h> #include <Adafruit_Fingerprint.h>
// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
// #define mySerial Serial1
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial... // For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire) // pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire) // pin #3 is OUT from arduino (WHITE wire)
// comment these two lines if using hardware serial // Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3); SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup() void setup()
@ -38,7 +44,7 @@ void setup()
// set the data rate for the sensor serial port // set the data rate for the sensor serial port
finger.begin(57600); finger.begin(57600);
delay(5);
if (finger.verifyPassword()) { if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!"); Serial.println("Found fingerprint sensor!");
} else { } else {
@ -46,14 +52,30 @@ void setup()
while (1) { delay(1); } while (1) { delay(1); }
} }
Serial.println(F("Reading sensor parameters"));
finger.getParameters();
Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
Serial.print(F("Security level: ")); Serial.println(finger.security_level);
Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
finger.getTemplateCount(); finger.getTemplateCount();
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
Serial.println("Waiting for valid finger..."); if (finger.templateCount == 0) {
Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
}
else {
Serial.println("Waiting for valid finger...");
Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
}
} }
void loop() // run over and over again void loop() // run over and over again
{ {
getFingerprintIDez(); getFingerprintID();
delay(50); //don't ned to run this at full speed. delay(50); //don't ned to run this at full speed.
} }
@ -102,7 +124,7 @@ uint8_t getFingerprintID() {
} }
// OK converted! // OK converted!
p = finger.fingerFastSearch(); p = finger.fingerSearch();
if (p == FINGERPRINT_OK) { if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!"); Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) { } else if (p == FINGERPRINT_PACKETRECIEVEERR) {

View File

@ -0,0 +1,85 @@
/***************************************************
This is an example sketch for our optical Fingerprint sensor with LED ring
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>
#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup()
{
Serial.begin(9600);
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
Serial.println("\n\nAdafruit finger detect test");
// set the data rate for the sensor serial port
finger.begin(57600);
delay(5);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
Serial.println(F("Reading sensor parameters"));
finger.getParameters();
Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
Serial.print(F("Security level: ")); Serial.println(finger.security_level);
Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);
}
void loop() // run over and over again
{
// LED fully on
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
delay(250);
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);
delay(250);
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE);
delay(250);
// flash red LED
finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10);
delay(2000);
// Breathe blue LED till we say to stop
finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE);
delay(3000);
finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_PURPLE);
delay(2000);
finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_PURPLE);
delay(2000);
}

View File

@ -12,15 +12,25 @@
#include <Adafruit_Fingerprint.h> #include <Adafruit_Fingerprint.h>
int getFingerprintIDez(); #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire) // pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire) // pin #3 is OUT from arduino (WHITE wire)
// Set up the serial port to use softwareserial..
SoftwareSerial mySerial(2, 3); SoftwareSerial mySerial(2, 3);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is green wire, #1 is white
#define mySerial Serial1
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int getFingerprintIDez();
void setup() void setup()
{ {
while(!Serial); while(!Serial);

View File

@ -1,5 +1,5 @@
name=Adafruit Fingerprint Sensor Library name=Adafruit Fingerprint Sensor Library
version=1.1.2 version=2.0.4
author=Adafruit author=Adafruit
maintainer=Adafruit <info@adafruit.com> maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for interfacing to the fingerprint sensor in the Adafruit shop sentence=Arduino library for interfacing to the fingerprint sensor in the Adafruit shop

View File

@ -1,369 +0,0 @@
/***************************************************
This is a library for our optical Fingerprint sensor
Designed specifically to work with the Adafruit Fingerprint sensor
----> 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 <TasmotaSerial.h>
//#define FINGERPRINT_DEBUG
#if ARDUINO >= 100
#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__)
#else
#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE)
#endif
#define SERIAL_WRITE_U16(v) SERIAL_WRITE((uint8_t)(v>>8)); SERIAL_WRITE((uint8_t)(v & 0xFF));
#define GET_CMD_PACKET(...) \
uint8_t data[] = {__VA_ARGS__}; \
Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), data); \
writeStructuredPacket(packet); \
if (getStructuredPacket(&packet) != FINGERPRINT_OK) return FINGERPRINT_PACKETRECIEVEERR; \
if (packet.type != FINGERPRINT_ACKPACKET) return FINGERPRINT_PACKETRECIEVEERR;
#define SEND_CMD_PACKET(...) GET_CMD_PACKET(__VA_ARGS__); return packet.data[0];
/***************************************************************************
PUBLIC FUNCTIONS
***************************************************************************/
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
/**************************************************************************/
/*!
@brief Instantiates sensor with Software Serial
@param ss Pointer to SoftwareSerial object
@param password 32-bit integer password (default is 0)
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(TasmotaSerial *ss, uint32_t password) {
thePassword = password;
theAddress = 0xFFFFFFFF;
hwSerial = NULL;
swSerial = ss;
mySerial = swSerial;
}
#endif
/**************************************************************************/
/*!
@brief Instantiates sensor with Hardware Serial
@param hs Pointer to HardwareSerial object
@param password 32-bit integer password (default is 0)
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password) {
thePassword = password;
theAddress = 0xFFFFFFFF;
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
swSerial = NULL;
#endif
hwSerial = hs;
mySerial = hwSerial;
}
/**************************************************************************/
/*!
@brief Initializes serial interface and baud rate
@param baudrate Sensor's UART baud rate (usually 57600, 9600 or 115200)
*/
/**************************************************************************/
void Adafruit_Fingerprint::begin(uint32_t baudrate) {
delay(1000); // one second delay to let the sensor 'boot up'
if (hwSerial) hwSerial->begin(baudrate);
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
if (swSerial) swSerial->begin(baudrate);
#endif
}
/**************************************************************************/
/*!
@brief Verifies the sensors' access password (default password is 0x0000000). A good way to also check if the sensors is active and responding
@returns True if password is correct
*/
/**************************************************************************/
boolean Adafruit_Fingerprint::verifyPassword(void) {
return checkPassword() == FINGERPRINT_OK;
}
uint8_t Adafruit_Fingerprint::checkPassword(void) {
GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD,
(uint8_t)(thePassword >> 24), (uint8_t)(thePassword >> 16),
(uint8_t)(thePassword >> 8), (uint8_t)(thePassword & 0xFF));
if (packet.data[0] == FINGERPRINT_OK)
return FINGERPRINT_OK;
else
return FINGERPRINT_PACKETRECIEVEERR;
}
/**************************************************************************/
/*!
@brief Ask the sensor to take an image of the finger pressed on surface
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_NOFINGER</code> if no finger detected
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_IMAGEFAIL</code> on imaging error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getImage(void) {
SEND_CMD_PACKET(FINGERPRINT_GETIMAGE);
}
/**************************************************************************/
/*!
@brief Ask the sensor to convert image to feature template
@param slot Location to place feature template (put one in 1 and another in 2 for verification to create model)
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_IMAGEMESS</code> if image is too messy
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_FEATUREFAIL</code> on failure to identify fingerprint features
@returns <code>FINGERPRINT_INVALIDIMAGE</code> on failure to identify fingerprint features
*/
uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ,slot);
}
/**************************************************************************/
/*!
@brief Ask the sensor to take two print feature template and create a model
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_ENROLLMISMATCH</code> on mismatch of fingerprints
*/
uint8_t Adafruit_Fingerprint::createModel(void) {
SEND_CMD_PACKET(FINGERPRINT_REGMODEL);
}
/**************************************************************************/
/*!
@brief Ask the sensor to store the calculated model for later matching
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF));
}
/**************************************************************************/
/*!
@brief Ask the sensor to load a fingerprint model from flash into buffer 1
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::loadModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF));
}
/**************************************************************************/
/*!
@brief Ask the sensor to transfer 256-byte fingerprint template from the buffer to the UART
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::getModel(void) {
SEND_CMD_PACKET(FINGERPRINT_UPLOAD, 0x01);
}
/**************************************************************************/
/*!
@brief Ask the sensor to delete a model in memory
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::deleteModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF), 0x00, 0x01);
}
/**************************************************************************/
/*!
@brief Ask the sensor to delete ALL models in memory
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
SEND_CMD_PACKET(FINGERPRINT_EMPTY);
}
/**************************************************************************/
/*!
@brief Ask the sensor to search the current slot 1 fingerprint features to match saved templates. The matching location is stored in <b>fingerID</b> and the matching confidence in <b>confidence</b>
@returns <code>FINGERPRINT_OK</code> on fingerprint match success
@returns <code>FINGERPRINT_NOTFOUND</code> no match made
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
// high speed search of slot #1 starting at page 0x0000 and page #0x00A3
GET_CMD_PACKET(FINGERPRINT_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3);
fingerID = 0xFFFF;
confidence = 0xFFFF;
fingerID = packet.data[1];
fingerID <<= 8;
fingerID |= packet.data[2];
confidence = packet.data[3];
confidence <<= 8;
confidence |= packet.data[4];
return packet.data[0];
}
/**************************************************************************/
/*!
@brief Ask the sensor for the number of templates stored in memory. The number is stored in <b>templateCount</b> on success.
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
GET_CMD_PACKET(FINGERPRINT_TEMPLATECOUNT);
templateCount = packet.data[1];
templateCount <<= 8;
templateCount |= packet.data[2];
return packet.data[0];
}
/**************************************************************************/
/*!
@brief Set the password on the sensor (future communication will require password verification so don't forget it!!!)
@param password 32-bit password code
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::setPassword(uint32_t password) {
SEND_CMD_PACKET(FINGERPRINT_SETPASSWORD, (password >> 24), (password >> 16), (password >> 8), password);
}
/**************************************************************************/
/*!
@brief Helper function to process a packet and send it over UART to the sensor
@param packet A structure containing the bytes to transmit
*/
/**************************************************************************/
void Adafruit_Fingerprint::writeStructuredPacket(const Adafruit_Fingerprint_Packet & packet) {
SERIAL_WRITE_U16(packet.start_code);
SERIAL_WRITE(packet.address[0]);
SERIAL_WRITE(packet.address[1]);
SERIAL_WRITE(packet.address[2]);
SERIAL_WRITE(packet.address[3]);
SERIAL_WRITE(packet.type);
uint16_t wire_length = packet.length + 2;
SERIAL_WRITE_U16(wire_length);
uint16_t sum = ((wire_length)>>8) + ((wire_length)&0xFF) + packet.type;
for (uint8_t i=0; i< packet.length; i++) {
SERIAL_WRITE(packet.data[i]);
sum += packet.data[i];
}
SERIAL_WRITE_U16(sum);
return;
}
/**************************************************************************/
/*!
@brief Helper function to receive data over UART from the sensor and process it into a packet
@param packet A structure containing the bytes received
@param timeout how many milliseconds we're willing to wait
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_TIMEOUT</code> or <code>FINGERPRINT_BADPACKET</code> on failure
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet * packet, uint16_t timeout) {
uint8_t byte;
uint16_t idx=0, timer=0;
while(true) {
while(!mySerial->available()) {
delay(1);
timer++;
if( timer >= timeout) {
#ifdef FINGERPRINT_DEBUG
//snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG " Time out"));
//AddLog(LOG_LEVEL_INFO);
#endif
return FINGERPRINT_TIMEOUT;
}
}
byte = mySerial->read();
//mydata[0] = idx;
mydata[idx] = byte;
#ifdef FINGERPRINT_DEBUG
//Serial.print("<- 0x"); Serial.println(byte, HEX);
//snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "<- 0x%x", byte));
//AddLog(LOG_LEVEL_INFO);
#endif
switch (idx) {
case 0:
if (byte != (FINGERPRINT_STARTCODE >> 8))
continue;
packet->start_code = (uint16_t)byte << 8;
break;
case 1:
packet->start_code |= byte;
if (packet->start_code != FINGERPRINT_STARTCODE)
return FINGERPRINT_BADPACKET;
break;
case 2:
case 3:
case 4:
case 5:
packet->address[idx-2] = byte;
break;
case 6:
packet->type = byte;
break;
case 7:
packet->length = (uint16_t)byte << 8;
break;
case 8:
packet->length |= byte;
break;
default:
packet->data[idx-9] = byte;
if((idx-8) == packet->length)
return FINGERPRINT_OK;
break;
}
idx++;
}
// Shouldn't get here so...
return FINGERPRINT_BADPACKET;
}

View File

@ -1,157 +0,0 @@
#ifndef ADAFRUIT_FINGERPRINT_H
#define ADAFRUIT_FINGERPRINT_H
/***************************************************
This is a library for our optical Fingerprint sensor
Designed specifically to work with the Adafruit Fingerprint sensor
----> 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 "Arduino.h"
#if defined(__AVR__) || defined(ESP8266)
//#include <SoftwareSerial.h>
#include <TasmotaSerial.h>
#elif defined(FREEDOM_E300_HIFIVE1)
#include <SoftwareSerial32.h>
#define SoftwareSerial SoftwareSerial32
#endif
#define FINGERPRINT_OK 0x00
#define FINGERPRINT_PACKETRECIEVEERR 0x01
#define FINGERPRINT_NOFINGER 0x02
#define FINGERPRINT_IMAGEFAIL 0x03
#define FINGERPRINT_IMAGEMESS 0x06
#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
#define FINGERPRINT_UPLOADFAIL 0x0F
#define FINGERPRINT_DELETEFAIL 0x10
#define FINGERPRINT_DBCLEARFAIL 0x11
#define FINGERPRINT_PASSFAIL 0x13
#define FINGERPRINT_INVALIDIMAGE 0x15
#define FINGERPRINT_FLASHERR 0x18
#define FINGERPRINT_INVALIDREG 0x1A
#define FINGERPRINT_ADDRCODE 0x20
#define FINGERPRINT_PASSVERIFY 0x21
#define FINGERPRINT_STARTCODE 0xEF01
#define FINGERPRINT_COMMANDPACKET 0x1
#define FINGERPRINT_DATAPACKET 0x2
#define FINGERPRINT_ACKPACKET 0x7
#define FINGERPRINT_ENDDATAPACKET 0x8
#define FINGERPRINT_TIMEOUT 0xFF
#define FINGERPRINT_BADPACKET 0xFE
#define FINGERPRINT_GETIMAGE 0x01
#define FINGERPRINT_IMAGE2TZ 0x02
#define FINGERPRINT_REGMODEL 0x05
#define FINGERPRINT_STORE 0x06
#define FINGERPRINT_LOAD 0x07
#define FINGERPRINT_UPLOAD 0x08
#define FINGERPRINT_DELETE 0x0C
#define FINGERPRINT_EMPTY 0x0D
#define FINGERPRINT_SETPASSWORD 0x12
#define FINGERPRINT_VERIFYPASSWORD 0x13
#define FINGERPRINT_HISPEEDSEARCH 0x1B
#define FINGERPRINT_TEMPLATECOUNT 0x1D
//#define FINGERPRINT_DEBUG
#define DEFAULTTIMEOUT 1000 ///< UART reading timeout in milliseconds
///! Helper class to craft UART packets
struct Adafruit_Fingerprint_Packet {
/**************************************************************************/
/*!
@brief Create a new UART-borne packet
@param type Command, data, ack type packet
@param length Size of payload
@param data Pointer to bytes of size length we will memcopy into the internal buffer
*/
/**************************************************************************/
Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t * data) {
this->start_code = FINGERPRINT_STARTCODE;
this->type = type;
this->length = length;
address[0] = 0xFF; address[1] = 0xFF;
address[2] = 0xFF; address[3] = 0xFF;
if(length<64)
memcpy(this->data, data, length);
else
memcpy(this->data, data, 64);
}
uint16_t start_code; ///< "Wakeup" code for packet detection
uint8_t address[4]; ///< 32-bit Fingerprint sensor address
uint8_t type; ///< Type of packet
uint16_t length; ///< Length of packet
uint8_t data[64]; ///< The raw buffer for packet payload
};
///! Helper class to communicate with and keep state for fingerprint sensors
class Adafruit_Fingerprint {
public:
uint8_t mydata[100];
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
Adafruit_Fingerprint(TasmotaSerial *ss, uint32_t password = 0x0);
#endif
Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password = 0x0);
void begin(uint32_t baud);
boolean verifyPassword(void);
uint8_t getImage(void);
uint8_t image2Tz(uint8_t slot = 1);
uint8_t createModel(void);
uint8_t emptyDatabase(void);
uint8_t storeModel(uint16_t id);
uint8_t loadModel(uint16_t id);
uint8_t getModel(void);
uint8_t deleteModel(uint16_t id);
uint8_t fingerFastSearch(void);
uint8_t getTemplateCount(void);
uint8_t setPassword(uint32_t password);
void writeStructuredPacket(const Adafruit_Fingerprint_Packet & p);
uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet * p, uint16_t timeout=DEFAULTTIMEOUT);
/// The matching location that is set by fingerFastSearch()
uint16_t fingerID;
/// The confidence of the fingerFastSearch() match, higher numbers are more confidents
uint16_t confidence;
/// The number of stored templates in the sensor, set by getTemplateCount()
uint16_t templateCount;
private:
uint8_t checkPassword(void);
uint32_t thePassword;
uint32_t theAddress;
uint8_t recvPacket[20];
Stream *mySerial;
#if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
TasmotaSerial *swSerial;
#endif
HardwareSerial *hwSerial;
};
#endif