├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── githubci.yml ├── .gitignore ├── Adafruit_Fingerprint.cpp ├── Adafruit_Fingerprint.h ├── README.md ├── documentation ├── ZFM-20_Fingerprint_Module.pdf ├── fingerprint_en.pdf └── readme.txt ├── examples ├── Leo_passthru │ ├── .uno.test.skip │ └── Leo_passthru.ino ├── blank │ └── blank.ino ├── changepassword │ └── changepassword.ino ├── delete │ └── delete.ino ├── emptyDatabase │ └── emptyDatabase.ino ├── enroll │ └── enroll.ino ├── fingerprint │ └── fingerprint.ino ├── ledcontrol │ └── ledcontrol.ino └── show_fingerprint_templates │ └── show_fingerprint_templates.ino ├── library.properties └── license.txt /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | 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. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | arduino-platform: ["uno", "leonardo", "mega2560", "zero", "esp8266", "esp32", "metro_m4", "trinket_m0"] 12 | 13 | steps: 14 | - uses: actions/setup-python@v4 15 | with: 16 | python-version: '3.x' 17 | - uses: actions/checkout@v3 18 | - uses: actions/checkout@v3 19 | with: 20 | repository: adafruit/ci-arduino 21 | path: ci 22 | 23 | - name: pre-install 24 | run: bash ci/actions_install.sh 25 | 26 | - name: test platforms 27 | run: python3 ci/build_platform.py ${{ matrix.arduino-platform }} 28 | 29 | - name: clang 30 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 31 | 32 | - name: doxygen 33 | env: 34 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 35 | PRETTYNAME : "Adafruit Fingerprint Arduino Library" 36 | run: bash ci/doxy_gen_and_deploy.sh 37 | 38 | 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /Adafruit_Fingerprint.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_Fingerprint.cpp 3 | * 4 | * @mainpage Adafruit Fingerprint Sensor Library 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * This is a library for our optical Fingerprint sensor 9 | * 10 | * Designed specifically to work with the Adafruit Fingerprint sensor 11 | * ----> http://www.adafruit.com/products/751 12 | * 13 | * These displays use TTL Serial to communicate, 2 pins are required to 14 | * interface 15 | * Adafruit invests time and resources providing this open source code, 16 | * please support Adafruit and open-source hardware by purchasing 17 | * products from Adafruit! 18 | * 19 | * @section author Author 20 | * 21 | * Written by Limor Fried/Ladyada for Adafruit Industries. 22 | * 23 | * @section license License 24 | * 25 | * BSD license, all text above must be included in any redistribution 26 | * 27 | */ 28 | 29 | #include "Adafruit_Fingerprint.h" 30 | 31 | //#define FINGERPRINT_DEBUG 32 | 33 | /*! 34 | * @brief Gets the command packet 35 | */ 36 | #define GET_CMD_PACKET(...) \ 37 | uint8_t data[] = {__VA_ARGS__}; \ 38 | Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), \ 39 | data); \ 40 | writeStructuredPacket(packet); \ 41 | if (getStructuredPacket(&packet) != FINGERPRINT_OK) \ 42 | return FINGERPRINT_PACKETRECIEVEERR; \ 43 | if (packet.type != FINGERPRINT_ACKPACKET) \ 44 | return FINGERPRINT_PACKETRECIEVEERR; 45 | 46 | /*! 47 | * @brief Sends the command packet 48 | */ 49 | #define SEND_CMD_PACKET(...) \ 50 | GET_CMD_PACKET(__VA_ARGS__); \ 51 | return packet.data[0]; 52 | 53 | /*************************************************************************** 54 | PUBLIC FUNCTIONS 55 | ***************************************************************************/ 56 | 57 | #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) 58 | /**************************************************************************/ 59 | /*! 60 | @brief Instantiates sensor with Software Serial 61 | @param ss Pointer to SoftwareSerial object 62 | @param password 32-bit integer password (default is 0) 63 | */ 64 | /**************************************************************************/ 65 | Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss, 66 | uint32_t password) { 67 | thePassword = password; 68 | theAddress = 0xFFFFFFFF; 69 | 70 | hwSerial = NULL; 71 | swSerial = ss; 72 | mySerial = swSerial; 73 | } 74 | #endif 75 | 76 | /**************************************************************************/ 77 | /*! 78 | @brief Instantiates sensor with Hardware Serial 79 | @param hs Pointer to HardwareSerial object 80 | @param password 32-bit integer password (default is 0) 81 | 82 | */ 83 | /**************************************************************************/ 84 | Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs, 85 | uint32_t password) { 86 | thePassword = password; 87 | theAddress = 0xFFFFFFFF; 88 | 89 | #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) 90 | swSerial = NULL; 91 | #endif 92 | hwSerial = hs; 93 | mySerial = hwSerial; 94 | } 95 | 96 | /**************************************************************************/ 97 | /*! 98 | @brief Instantiates sensor with a stream for Serial 99 | @param serial Pointer to a Stream object 100 | @param password 32-bit integer password (default is 0) 101 | 102 | */ 103 | /**************************************************************************/ 104 | 105 | Adafruit_Fingerprint::Adafruit_Fingerprint(Stream *serial, uint32_t password) { 106 | 107 | thePassword = password; 108 | theAddress = 0xFFFFFFFF; 109 | 110 | hwSerial = NULL; 111 | #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) 112 | swSerial = NULL; 113 | #endif 114 | mySerial = serial; 115 | } 116 | 117 | /**************************************************************************/ 118 | /*! 119 | @brief Initializes serial interface and baud rate 120 | @param baudrate Sensor's UART baud rate (usually 57600, 9600 or 115200) 121 | */ 122 | /**************************************************************************/ 123 | void Adafruit_Fingerprint::begin(uint32_t baudrate) { 124 | delay(1000); // one second delay to let the sensor 'boot up' 125 | 126 | if (hwSerial) 127 | hwSerial->begin(baudrate); 128 | #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) 129 | if (swSerial) 130 | swSerial->begin(baudrate); 131 | #endif 132 | } 133 | 134 | /**************************************************************************/ 135 | /*! 136 | @brief Verifies the sensors' access password (default password is 137 | 0x0000000). A good way to also check if the sensors is active and responding 138 | @returns True if password is correct 139 | */ 140 | /**************************************************************************/ 141 | boolean Adafruit_Fingerprint::verifyPassword(void) { 142 | return checkPassword() == FINGERPRINT_OK; 143 | } 144 | 145 | uint8_t Adafruit_Fingerprint::checkPassword(void) { 146 | GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD, (uint8_t)(thePassword >> 24), 147 | (uint8_t)(thePassword >> 16), (uint8_t)(thePassword >> 8), 148 | (uint8_t)(thePassword & 0xFF)); 149 | if (packet.data[0] == FINGERPRINT_OK) 150 | return FINGERPRINT_OK; 151 | else 152 | return FINGERPRINT_PACKETRECIEVEERR; 153 | } 154 | 155 | /**************************************************************************/ 156 | /*! 157 | @brief Get the sensors parameters, fills in the member variables 158 | status_reg, system_id, capacity, security_level, device_addr, packet_len 159 | and baud_rate 160 | @returns True if password is correct 161 | */ 162 | /**************************************************************************/ 163 | uint8_t Adafruit_Fingerprint::getParameters(void) { 164 | GET_CMD_PACKET(FINGERPRINT_READSYSPARAM); 165 | 166 | status_reg = ((uint16_t)packet.data[1] << 8) | packet.data[2]; 167 | system_id = ((uint16_t)packet.data[3] << 8) | packet.data[4]; 168 | capacity = ((uint16_t)packet.data[5] << 8) | packet.data[6]; 169 | security_level = ((uint16_t)packet.data[7] << 8) | packet.data[8]; 170 | device_addr = ((uint32_t)packet.data[9] << 24) | 171 | ((uint32_t)packet.data[10] << 16) | 172 | ((uint32_t)packet.data[11] << 8) | (uint32_t)packet.data[12]; 173 | packet_len = ((uint16_t)packet.data[13] << 8) | packet.data[14]; 174 | if (packet_len == 0) { 175 | packet_len = 32; 176 | } else if (packet_len == 1) { 177 | packet_len = 64; 178 | } else if (packet_len == 2) { 179 | packet_len = 128; 180 | } else if (packet_len == 3) { 181 | packet_len = 256; 182 | } 183 | baud_rate = (((uint16_t)packet.data[15] << 8) | packet.data[16]) * 9600; 184 | 185 | return packet.data[0]; 186 | } 187 | 188 | /**************************************************************************/ 189 | /*! 190 | @brief Ask the sensor to take an image of the finger pressed on surface 191 | @returns FINGERPRINT_OK on success 192 | @returns FINGERPRINT_NOFINGER if no finger detected 193 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 194 | @returns FINGERPRINT_IMAGEFAIL on imaging error 195 | */ 196 | /**************************************************************************/ 197 | uint8_t Adafruit_Fingerprint::getImage(void) { 198 | SEND_CMD_PACKET(FINGERPRINT_GETIMAGE); 199 | } 200 | 201 | /**************************************************************************/ 202 | /*! 203 | @brief Ask the sensor to convert image to feature template 204 | @param slot Location to place feature template (put one in 1 and another in 205 | 2 for verification to create model) 206 | @returns FINGERPRINT_OK on success 207 | @returns FINGERPRINT_IMAGEMESS if image is too messy 208 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 209 | @returns FINGERPRINT_FEATUREFAIL on failure to identify 210 | fingerprint features 211 | @returns FINGERPRINT_INVALIDIMAGE on failure to identify 212 | fingerprint features 213 | */ 214 | uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) { 215 | SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ, slot); 216 | } 217 | 218 | /**************************************************************************/ 219 | /*! 220 | @brief Ask the sensor to take two print feature template and create a 221 | model 222 | @returns FINGERPRINT_OK on success 223 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 224 | @returns FINGERPRINT_ENROLLMISMATCH on mismatch of fingerprints 225 | */ 226 | uint8_t Adafruit_Fingerprint::createModel(void) { 227 | SEND_CMD_PACKET(FINGERPRINT_REGMODEL); 228 | } 229 | 230 | /**************************************************************************/ 231 | /*! 232 | @brief Ask the sensor to store the calculated model for later matching 233 | @param location The model location # 234 | @returns FINGERPRINT_OK on success 235 | @returns FINGERPRINT_BADLOCATION if the location is invalid 236 | @returns FINGERPRINT_FLASHERR if the model couldn't be written 237 | to flash memory 238 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 239 | */ 240 | uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) { 241 | SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8), 242 | (uint8_t)(location & 0xFF)); 243 | } 244 | 245 | /**************************************************************************/ 246 | /*! 247 | @brief Ask the sensor to load a fingerprint model from flash into buffer 1 248 | @param location The model location # 249 | @returns FINGERPRINT_OK on success 250 | @returns FINGERPRINT_BADLOCATION if the location is invalid 251 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 252 | */ 253 | uint8_t Adafruit_Fingerprint::loadModel(uint16_t location) { 254 | SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8), 255 | (uint8_t)(location & 0xFF)); 256 | } 257 | 258 | /**************************************************************************/ 259 | /*! 260 | @brief Ask the sensor to transfer 256-byte fingerprint template from the 261 | buffer to the UART 262 | @returns FINGERPRINT_OK on success 263 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 264 | */ 265 | uint8_t Adafruit_Fingerprint::getModel(void) { 266 | SEND_CMD_PACKET(FINGERPRINT_UPLOAD, 0x01); 267 | } 268 | 269 | /**************************************************************************/ 270 | /*! 271 | @brief Ask the sensor to delete a model in memory 272 | @param location The model location # 273 | @returns FINGERPRINT_OK on success 274 | @returns FINGERPRINT_BADLOCATION if the location is invalid 275 | @returns FINGERPRINT_FLASHERR if the model couldn't be written 276 | to flash memory 277 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 278 | */ 279 | uint8_t Adafruit_Fingerprint::deleteModel(uint16_t location) { 280 | SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(location >> 8), 281 | (uint8_t)(location & 0xFF), 0x00, 0x01); 282 | } 283 | 284 | /**************************************************************************/ 285 | /*! 286 | @brief Ask the sensor to delete ALL models in memory 287 | @returns FINGERPRINT_OK on success 288 | @returns FINGERPRINT_BADLOCATION if the location is invalid 289 | @returns FINGERPRINT_FLASHERR if the model couldn't be written 290 | to flash memory 291 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 292 | */ 293 | uint8_t Adafruit_Fingerprint::emptyDatabase(void) { 294 | SEND_CMD_PACKET(FINGERPRINT_EMPTY); 295 | } 296 | 297 | /**************************************************************************/ 298 | /*! 299 | @brief Ask the sensor to search the current slot 1 fingerprint features to 300 | match saved templates. The matching location is stored in fingerID and 301 | the matching confidence in confidence 302 | @returns FINGERPRINT_OK on fingerprint match success 303 | @returns FINGERPRINT_NOTFOUND no match made 304 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 305 | */ 306 | /**************************************************************************/ 307 | uint8_t Adafruit_Fingerprint::fingerFastSearch(void) { 308 | // high speed search of slot #1 starting at page 0x0000 and page #0x00A3 309 | GET_CMD_PACKET(FINGERPRINT_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3); 310 | fingerID = 0xFFFF; 311 | confidence = 0xFFFF; 312 | 313 | fingerID = packet.data[1]; 314 | fingerID <<= 8; 315 | fingerID |= packet.data[2]; 316 | 317 | confidence = packet.data[3]; 318 | confidence <<= 8; 319 | confidence |= packet.data[4]; 320 | 321 | return packet.data[0]; 322 | } 323 | 324 | /**************************************************************************/ 325 | /*! 326 | @brief Control the built in LED 327 | @param on True if you want LED on, False to turn LED off 328 | @returns FINGERPRINT_OK on success 329 | */ 330 | /**************************************************************************/ 331 | uint8_t Adafruit_Fingerprint::LEDcontrol(bool on) { 332 | if (on) { 333 | SEND_CMD_PACKET(FINGERPRINT_LEDON); 334 | } else { 335 | SEND_CMD_PACKET(FINGERPRINT_LEDOFF); 336 | } 337 | } 338 | 339 | /**************************************************************************/ 340 | /*! 341 | @brief Control the built in Aura LED (if exists). Check datasheet/manual 342 | for different colors and control codes available 343 | @param control The control code (e.g. breathing, full on) 344 | @param speed How fast to go through the breathing/blinking cycles 345 | @param coloridx What color to light the indicator 346 | @param count How many repeats of blinks/breathing cycles 347 | @returns FINGERPRINT_OK on fingerprint match success 348 | @returns FINGERPRINT_NOTFOUND no match made 349 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 350 | */ 351 | /**************************************************************************/ 352 | uint8_t Adafruit_Fingerprint::LEDcontrol(uint8_t control, uint8_t speed, 353 | uint8_t coloridx, uint8_t count) { 354 | SEND_CMD_PACKET(FINGERPRINT_AURALEDCONFIG, control, speed, coloridx, count); 355 | } 356 | 357 | /**************************************************************************/ 358 | /*! 359 | @brief Ask the sensor to search the current slot fingerprint features to 360 | match saved templates. The matching location is stored in fingerID and 361 | the matching confidence in confidence 362 | @param slot The slot to use for the print search, defaults to 1 363 | @returns FINGERPRINT_OK on fingerprint match success 364 | @returns FINGERPRINT_NOTFOUND no match made 365 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 366 | */ 367 | /**************************************************************************/ 368 | uint8_t Adafruit_Fingerprint::fingerSearch(uint8_t slot) { 369 | // search of slot starting thru the capacity 370 | GET_CMD_PACKET(FINGERPRINT_SEARCH, slot, 0x00, 0x00, (uint8_t)(capacity >> 8), 371 | (uint8_t)(capacity & 0xFF)); 372 | 373 | fingerID = 0xFFFF; 374 | confidence = 0xFFFF; 375 | 376 | fingerID = packet.data[1]; 377 | fingerID <<= 8; 378 | fingerID |= packet.data[2]; 379 | 380 | confidence = packet.data[3]; 381 | confidence <<= 8; 382 | confidence |= packet.data[4]; 383 | 384 | return packet.data[0]; 385 | } 386 | 387 | /**************************************************************************/ 388 | /*! 389 | @brief Ask the sensor for the number of templates stored in memory. The 390 | number is stored in templateCount on success. 391 | @returns FINGERPRINT_OK on success 392 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 393 | */ 394 | /**************************************************************************/ 395 | uint8_t Adafruit_Fingerprint::getTemplateCount(void) { 396 | GET_CMD_PACKET(FINGERPRINT_TEMPLATECOUNT); 397 | 398 | templateCount = packet.data[1]; 399 | templateCount <<= 8; 400 | templateCount |= packet.data[2]; 401 | 402 | return packet.data[0]; 403 | } 404 | 405 | /**************************************************************************/ 406 | /*! 407 | @brief Set the password on the sensor (future communication will require 408 | password verification so don't forget it!!!) 409 | @param password 32-bit password code 410 | @returns FINGERPRINT_OK on success 411 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 412 | */ 413 | /**************************************************************************/ 414 | uint8_t Adafruit_Fingerprint::setPassword(uint32_t password) { 415 | SEND_CMD_PACKET(FINGERPRINT_SETPASSWORD, (uint8_t)(password >> 24), 416 | (uint8_t)(password >> 16), (uint8_t)(password >> 8), 417 | (uint8_t)(password & 0xFF)); 418 | } 419 | 420 | /**************************************************************************/ 421 | /*! 422 | @brief Writing module registers 423 | @param regAdd 8-bit address of register 424 | @param value 8-bit value will write to register 425 | @returns FINGERPRINT_OK on success 426 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 427 | @returns FINGERPRINT_ADDRESS_ERROR on register address error 428 | */ 429 | /**************************************************************************/ 430 | uint8_t Adafruit_Fingerprint::writeRegister(uint8_t regAdd, uint8_t value) { 431 | 432 | SEND_CMD_PACKET(FINGERPRINT_WRITE_REG, regAdd, value); 433 | } 434 | 435 | /**************************************************************************/ 436 | /*! 437 | @brief Change UART baudrate 438 | @param baudrate 8-bit Uart baudrate 439 | @returns FINGERPRINT_OK on success 440 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 441 | */ 442 | /**************************************************************************/ 443 | uint8_t Adafruit_Fingerprint::setBaudRate(uint8_t baudrate) { 444 | 445 | return (writeRegister(FINGERPRINT_BAUD_REG_ADDR, baudrate)); 446 | } 447 | 448 | /**************************************************************************/ 449 | /*! 450 | @brief Change security level 451 | @param level 8-bit security level 452 | @returns FINGERPRINT_OK on success 453 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 454 | */ 455 | /**************************************************************************/ 456 | uint8_t Adafruit_Fingerprint::setSecurityLevel(uint8_t level) { 457 | 458 | return (writeRegister(FINGERPRINT_SECURITY_REG_ADDR, level)); 459 | } 460 | 461 | /**************************************************************************/ 462 | /*! 463 | @brief Change packet size 464 | @param size 8-bit packet size 465 | @returns FINGERPRINT_OK on success 466 | @returns FINGERPRINT_PACKETRECIEVEERR on communication error 467 | */ 468 | /**************************************************************************/ 469 | uint8_t Adafruit_Fingerprint::setPacketSize(uint8_t size) { 470 | 471 | return (writeRegister(FINGERPRINT_PACKET_REG_ADDR, size)); 472 | } 473 | /**************************************************************************/ 474 | /*! 475 | @brief Helper function to process a packet and send it over UART to the 476 | sensor 477 | @param packet A structure containing the bytes to transmit 478 | */ 479 | /**************************************************************************/ 480 | 481 | void Adafruit_Fingerprint::writeStructuredPacket( 482 | const Adafruit_Fingerprint_Packet &packet) { 483 | 484 | mySerial->write((uint8_t)(packet.start_code >> 8)); 485 | mySerial->write((uint8_t)(packet.start_code & 0xFF)); 486 | mySerial->write(packet.address[0]); 487 | mySerial->write(packet.address[1]); 488 | mySerial->write(packet.address[2]); 489 | mySerial->write(packet.address[3]); 490 | mySerial->write(packet.type); 491 | 492 | uint16_t wire_length = packet.length + 2; 493 | mySerial->write((uint8_t)(wire_length >> 8)); 494 | mySerial->write((uint8_t)(wire_length & 0xFF)); 495 | 496 | #ifdef FINGERPRINT_DEBUG 497 | Serial.print("-> 0x"); 498 | Serial.print((uint8_t)(packet.start_code >> 8), HEX); 499 | Serial.print(", 0x"); 500 | Serial.print((uint8_t)(packet.start_code & 0xFF), HEX); 501 | Serial.print(", 0x"); 502 | Serial.print(packet.address[0], HEX); 503 | Serial.print(", 0x"); 504 | Serial.print(packet.address[1], HEX); 505 | Serial.print(", 0x"); 506 | Serial.print(packet.address[2], HEX); 507 | Serial.print(", 0x"); 508 | Serial.print(packet.address[3], HEX); 509 | Serial.print(", 0x"); 510 | Serial.print(packet.type, HEX); 511 | Serial.print(", 0x"); 512 | Serial.print((uint8_t)(wire_length >> 8), HEX); 513 | Serial.print(", 0x"); 514 | Serial.print((uint8_t)(wire_length & 0xFF), HEX); 515 | #endif 516 | 517 | uint16_t sum = ((wire_length) >> 8) + ((wire_length)&0xFF) + packet.type; 518 | for (uint8_t i = 0; i < packet.length; i++) { 519 | mySerial->write(packet.data[i]); 520 | sum += packet.data[i]; 521 | #ifdef FINGERPRINT_DEBUG 522 | Serial.print(", 0x"); 523 | Serial.print(packet.data[i], HEX); 524 | #endif 525 | } 526 | 527 | mySerial->write((uint8_t)(sum >> 8)); 528 | mySerial->write((uint8_t)(sum & 0xFF)); 529 | 530 | #ifdef FINGERPRINT_DEBUG 531 | Serial.print(", 0x"); 532 | Serial.print((uint8_t)(sum >> 8), HEX); 533 | Serial.print(", 0x"); 534 | Serial.println((uint8_t)(sum & 0xFF), HEX); 535 | #endif 536 | 537 | return; 538 | } 539 | 540 | /**************************************************************************/ 541 | /*! 542 | @brief Helper function to receive data over UART from the sensor and 543 | process it into a packet 544 | @param packet A structure containing the bytes received 545 | @param timeout how many milliseconds we're willing to wait 546 | @returns FINGERPRINT_OK on success 547 | @returns FINGERPRINT_TIMEOUT or 548 | FINGERPRINT_BADPACKET on failure 549 | */ 550 | /**************************************************************************/ 551 | uint8_t 552 | Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet *packet, 553 | uint16_t timeout) { 554 | uint8_t byte; 555 | uint16_t idx = 0, timer = 0; 556 | 557 | #ifdef FINGERPRINT_DEBUG 558 | Serial.print("<- "); 559 | #endif 560 | 561 | while (true) { 562 | while (!mySerial->available()) { 563 | delay(1); 564 | timer++; 565 | if (timer >= timeout) { 566 | #ifdef FINGERPRINT_DEBUG 567 | Serial.println("Timed out"); 568 | #endif 569 | return FINGERPRINT_TIMEOUT; 570 | } 571 | } 572 | byte = mySerial->read(); 573 | #ifdef FINGERPRINT_DEBUG 574 | Serial.print("0x"); 575 | Serial.print(byte, HEX); 576 | Serial.print(", "); 577 | #endif 578 | switch (idx) { 579 | case 0: 580 | if (byte != (FINGERPRINT_STARTCODE >> 8)) 581 | continue; 582 | packet->start_code = (uint16_t)byte << 8; 583 | break; 584 | case 1: 585 | packet->start_code |= byte; 586 | if (packet->start_code != FINGERPRINT_STARTCODE) 587 | return FINGERPRINT_BADPACKET; 588 | break; 589 | case 2: 590 | case 3: 591 | case 4: 592 | case 5: 593 | packet->address[idx - 2] = byte; 594 | break; 595 | case 6: 596 | packet->type = byte; 597 | break; 598 | case 7: 599 | packet->length = (uint16_t)byte << 8; 600 | break; 601 | case 8: 602 | packet->length |= byte; 603 | break; 604 | default: 605 | packet->data[idx - 9] = byte; 606 | if ((idx - 8) == packet->length) { 607 | #ifdef FINGERPRINT_DEBUG 608 | Serial.println(" OK "); 609 | #endif 610 | return FINGERPRINT_OK; 611 | } 612 | break; 613 | } 614 | idx++; 615 | if ((idx + 9) >= sizeof(packet->data)) { 616 | return FINGERPRINT_BADPACKET; 617 | } 618 | } 619 | // Shouldn't get here so... 620 | return FINGERPRINT_BADPACKET; 621 | } 622 | -------------------------------------------------------------------------------- /Adafruit_Fingerprint.h: -------------------------------------------------------------------------------- 1 | #ifndef ADAFRUIT_FINGERPRINT_H 2 | #define ADAFRUIT_FINGERPRINT_H 3 | 4 | /*! 5 | * @file Adafruit_Fingerprint.h 6 | */ 7 | 8 | #include "Arduino.h" 9 | #if defined(__AVR__) || defined(ESP8266) 10 | #include 11 | #elif defined(FREEDOM_E300_HIFIVE1) 12 | #include 13 | #define SoftwareSerial SoftwareSerial32 14 | #endif 15 | 16 | #define FINGERPRINT_OK 0x00 //!< Command execution is complete 17 | #define FINGERPRINT_PACKETRECIEVEERR 0x01 //!< Error when receiving data package 18 | #define FINGERPRINT_NOFINGER 0x02 //!< No finger on the sensor 19 | #define FINGERPRINT_IMAGEFAIL 0x03 //!< Failed to enroll the finger 20 | #define FINGERPRINT_IMAGEMESS \ 21 | 0x06 //!< Failed to generate character file due to overly disorderly 22 | //!< fingerprint image 23 | #define FINGERPRINT_FEATUREFAIL \ 24 | 0x07 //!< Failed to generate character file due to the lack of character point 25 | //!< or small fingerprint image 26 | #define FINGERPRINT_NOMATCH 0x08 //!< Finger doesn't match 27 | #define FINGERPRINT_NOTFOUND 0x09 //!< Failed to find matching finger 28 | #define FINGERPRINT_ENROLLMISMATCH \ 29 | 0x0A //!< Failed to combine the character files 30 | #define FINGERPRINT_BADLOCATION \ 31 | 0x0B //!< Addressed PageID is beyond the finger library 32 | #define FINGERPRINT_DBRANGEFAIL \ 33 | 0x0C //!< Error when reading template from library or invalid template 34 | #define FINGERPRINT_UPLOADFEATUREFAIL 0x0D //!< Error when uploading template 35 | #define FINGERPRINT_PACKETRESPONSEFAIL \ 36 | 0x0E //!< Module failed to receive the following data packages 37 | #define FINGERPRINT_UPLOADFAIL 0x0F //!< Error when uploading image 38 | #define FINGERPRINT_DELETEFAIL 0x10 //!< Failed to delete the template 39 | #define FINGERPRINT_DBCLEARFAIL 0x11 //!< Failed to clear finger library 40 | #define FINGERPRINT_PASSFAIL \ 41 | 0x13 //!< Find whether the fingerprint passed or failed 42 | #define FINGERPRINT_INVALIDIMAGE \ 43 | 0x15 //!< Failed to generate image because of lac of valid primary image 44 | #define FINGERPRINT_FLASHERR 0x18 //!< Error when writing flash 45 | #define FINGERPRINT_INVALIDREG 0x1A //!< Invalid register number 46 | #define FINGERPRINT_ADDRCODE 0x20 //!< Address code 47 | #define FINGERPRINT_PASSVERIFY 0x21 //!< Verify the fingerprint passed 48 | #define FINGERPRINT_STARTCODE \ 49 | 0xEF01 //!< Fixed falue of EF01H; High byte transferred first 50 | 51 | #define FINGERPRINT_COMMANDPACKET 0x1 //!< Command packet 52 | #define FINGERPRINT_DATAPACKET \ 53 | 0x2 //!< Data packet, must follow command packet or acknowledge packet 54 | #define FINGERPRINT_ACKPACKET 0x7 //!< Acknowledge packet 55 | #define FINGERPRINT_ENDDATAPACKET 0x8 //!< End of data packet 56 | 57 | #define FINGERPRINT_TIMEOUT 0xFF //!< Timeout was reached 58 | #define FINGERPRINT_BADPACKET 0xFE //!< Bad packet was sent 59 | 60 | #define FINGERPRINT_GETIMAGE 0x01 //!< Collect finger image 61 | #define FINGERPRINT_IMAGE2TZ 0x02 //!< Generate character file from image 62 | #define FINGERPRINT_SEARCH 0x04 //!< Search for fingerprint in slot 63 | #define FINGERPRINT_REGMODEL \ 64 | 0x05 //!< Combine character files and generate template 65 | #define FINGERPRINT_STORE 0x06 //!< Store template 66 | #define FINGERPRINT_LOAD 0x07 //!< Read/load template 67 | #define FINGERPRINT_UPLOAD 0x08 //!< Upload template 68 | #define FINGERPRINT_DELETE 0x0C //!< Delete templates 69 | #define FINGERPRINT_EMPTY 0x0D //!< Empty library 70 | #define FINGERPRINT_READSYSPARAM 0x0F //!< Read system parameters 71 | #define FINGERPRINT_SETPASSWORD 0x12 //!< Sets passwords 72 | #define FINGERPRINT_VERIFYPASSWORD 0x13 //!< Verifies the password 73 | #define FINGERPRINT_HISPEEDSEARCH \ 74 | 0x1B //!< Asks the sensor to search for a matching fingerprint template to the 75 | //!< last model generated 76 | #define FINGERPRINT_TEMPLATECOUNT 0x1D //!< Read finger template numbers 77 | #define FINGERPRINT_AURALEDCONFIG 0x35 //!< Aura LED control 78 | #define FINGERPRINT_LEDON 0x50 //!< Turn on the onboard LED 79 | #define FINGERPRINT_LEDOFF 0x51 //!< Turn off the onboard LED 80 | 81 | #define FINGERPRINT_LED_BREATHING 0x01 //!< Breathing light 82 | #define FINGERPRINT_LED_FLASHING 0x02 //!< Flashing light 83 | #define FINGERPRINT_LED_ON 0x03 //!< Always on 84 | #define FINGERPRINT_LED_OFF 0x04 //!< Always off 85 | #define FINGERPRINT_LED_GRADUAL_ON 0x05 //!< Gradually on 86 | #define FINGERPRINT_LED_GRADUAL_OFF 0x06 //!< Gradually off 87 | #define FINGERPRINT_LED_RED 0x01 //!< Red LED 88 | #define FINGERPRINT_LED_BLUE 0x02 //!< Blue LED 89 | #define FINGERPRINT_LED_PURPLE 0x03 //!< Purple LEDpassword 90 | 91 | #define FINGERPRINT_REG_ADDR_ERROR 0x1A //!< shows register address error 92 | #define FINGERPRINT_WRITE_REG 0x0E //!< Write system register instruction 93 | 94 | #define FINGERPRINT_BAUD_REG_ADDR 0x4 //!< BAUDRATE register address 95 | #define FINGERPRINT_BAUDRATE_9600 0x1 //!< UART baud 9600 96 | #define FINGERPRINT_BAUDRATE_19200 0x2 //!< UART baud 19200 97 | #define FINGERPRINT_BAUDRATE_28800 0x3 //!< UART baud 28800 98 | #define FINGERPRINT_BAUDRATE_38400 0x4 //!< UART baud 38400 99 | #define FINGERPRINT_BAUDRATE_48000 0x5 //!< UART baud 48000 100 | #define FINGERPRINT_BAUDRATE_57600 0x6 //!< UART baud 57600 101 | #define FINGERPRINT_BAUDRATE_67200 0x7 //!< UART baud 67200 102 | #define FINGERPRINT_BAUDRATE_76800 0x8 //!< UART baud 76800 103 | #define FINGERPRINT_BAUDRATE_86400 0x9 //!< UART baud 86400 104 | #define FINGERPRINT_BAUDRATE_96000 0xA //!< UART baud 96000 105 | #define FINGERPRINT_BAUDRATE_105600 0xB //!< UART baud 105600 106 | #define FINGERPRINT_BAUDRATE_115200 0xC //!< UART baud 115200 107 | 108 | #define FINGERPRINT_SECURITY_REG_ADDR 0x5 //!< Security level register address 109 | // The safety level is 1 The highest rate of false recognition , The rejection 110 | // rate is the lowest . The safety level is 5 The lowest tate of false 111 | // recognition, The rejection rate is the highest . 112 | #define FINGERPRINT_SECURITY_LEVEL_1 0X1 //!< Security level 1 113 | #define FINGERPRINT_SECURITY_LEVEL_2 0X2 //!< Security level 2 114 | #define FINGERPRINT_SECURITY_LEVEL_3 0X3 //!< Security level 3 115 | #define FINGERPRINT_SECURITY_LEVEL_4 0X4 //!< Security level 4 116 | #define FINGERPRINT_SECURITY_LEVEL_5 0X5 //!< Security level 5 117 | 118 | #define FINGERPRINT_PACKET_REG_ADDR 0x6 //!< Packet size register address 119 | #define FINGERPRINT_PACKET_SIZE_32 0X0 //!< Packet size is 32 Byte 120 | #define FINGERPRINT_PACKET_SIZE_64 0X1 //!< Packet size is 64 Byte 121 | #define FINGERPRINT_PACKET_SIZE_128 0X2 //!< Packet size is 128 Byte 122 | #define FINGERPRINT_PACKET_SIZE_256 0X3 //!< Packet size is 256 Byte 123 | 124 | //#define FINGERPRINT_DEBUG 125 | 126 | #define DEFAULTTIMEOUT 1000 //!< UART reading timeout in milliseconds 127 | 128 | ///! Helper class to craft UART packets 129 | struct Adafruit_Fingerprint_Packet { 130 | 131 | /**************************************************************************/ 132 | /*! 133 | @brief Create a new UART-borne packet 134 | @param type Command, data, ack type packet 135 | @param length Size of payload 136 | @param data Pointer to bytes of size length we will memcopy into the 137 | internal buffer 138 | */ 139 | /**************************************************************************/ 140 | 141 | Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t *data) { 142 | this->start_code = FINGERPRINT_STARTCODE; 143 | this->type = type; 144 | this->length = length; 145 | address[0] = 0xFF; 146 | address[1] = 0xFF; 147 | address[2] = 0xFF; 148 | address[3] = 0xFF; 149 | if (length < 64) 150 | memcpy(this->data, data, length); 151 | else 152 | memcpy(this->data, data, 64); 153 | } 154 | uint16_t start_code; ///< "Wakeup" code for packet detection 155 | uint8_t address[4]; ///< 32-bit Fingerprint sensor address 156 | uint8_t type; ///< Type of packet 157 | uint16_t length; ///< Length of packet 158 | uint8_t data[64]; ///< The raw buffer for packet payload 159 | }; 160 | 161 | ///! Helper class to communicate with and keep state for fingerprint sensors 162 | class Adafruit_Fingerprint { 163 | public: 164 | #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) 165 | Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password = 0x0); 166 | #endif 167 | Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password = 0x0); 168 | Adafruit_Fingerprint(Stream *serial, uint32_t password = 0x0); 169 | 170 | void begin(uint32_t baud); 171 | 172 | boolean verifyPassword(void); 173 | uint8_t getParameters(void); 174 | 175 | uint8_t getImage(void); 176 | uint8_t image2Tz(uint8_t slot = 1); 177 | uint8_t createModel(void); 178 | 179 | uint8_t emptyDatabase(void); 180 | uint8_t storeModel(uint16_t id); 181 | uint8_t loadModel(uint16_t id); 182 | uint8_t getModel(void); 183 | uint8_t deleteModel(uint16_t id); 184 | uint8_t fingerFastSearch(void); 185 | uint8_t fingerSearch(uint8_t slot = 1); 186 | uint8_t getTemplateCount(void); 187 | uint8_t setPassword(uint32_t password); 188 | uint8_t LEDcontrol(bool on); 189 | uint8_t LEDcontrol(uint8_t control, uint8_t speed, uint8_t coloridx, 190 | uint8_t count = 0); 191 | 192 | uint8_t setBaudRate(uint8_t baudrate); 193 | uint8_t setSecurityLevel(uint8_t level); 194 | uint8_t setPacketSize(uint8_t size); 195 | 196 | void writeStructuredPacket(const Adafruit_Fingerprint_Packet &p); 197 | uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet *p, 198 | uint16_t timeout = DEFAULTTIMEOUT); 199 | 200 | /// The matching location that is set by fingerFastSearch() 201 | uint16_t fingerID; 202 | /// The confidence of the fingerFastSearch() match, higher numbers are more 203 | /// confidents 204 | uint16_t confidence; 205 | /// The number of stored templates in the sensor, set by getTemplateCount() 206 | uint16_t templateCount; 207 | 208 | uint16_t status_reg = 0x0; ///< The status register (set by getParameters) 209 | uint16_t system_id = 0x0; ///< The system identifier (set by getParameters) 210 | uint16_t capacity = 64; ///< The fingerprint capacity (set by getParameters) 211 | uint16_t security_level = 0; ///< The security level (set by getParameters) 212 | uint32_t device_addr = 213 | 0xFFFFFFFF; ///< The device address (set by getParameters) 214 | uint16_t packet_len = 64; ///< The max packet length (set by getParameters) 215 | uint16_t baud_rate = 57600; ///< The UART baud rate (set by getParameters) 216 | 217 | private: 218 | uint8_t checkPassword(void); 219 | uint8_t writeRegister(uint8_t regAdd, uint8_t value); 220 | uint32_t thePassword; 221 | uint32_t theAddress; 222 | uint8_t recvPacket[20]; 223 | 224 | Stream *mySerial; 225 | #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) 226 | SoftwareSerial *swSerial; 227 | #endif 228 | HardwareSerial *hwSerial; 229 | }; 230 | 231 | #endif 232 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 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) 2 | 3 | 4 | 5 | 6 | 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. 7 | 8 | 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. 9 | 10 | 11 | Designed specifically to work with the Adafruit Fingerprint sensors 12 | * http://www.adafruit.com/products/751 13 | * https://www.adafruit.com/product/4651 14 | 15 | Pick one up today in the adafruit shop! 16 | 17 | These sensors use TTL Serial to communicate, 2 pins are required to interface 18 | 19 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 20 | 21 | Written by Limor Fried/Ladyada for Adafruit Industries. 22 | BSD license, check license.txt for more information 23 | All text above must be included in any redistribution 24 | -------------------------------------------------------------------------------- /documentation/ZFM-20_Fingerprint_Module.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit-Fingerprint-Sensor-Library/3e9b2cdeace0e36c9ba5831fd31f4f18e20653c4/documentation/ZFM-20_Fingerprint_Module.pdf -------------------------------------------------------------------------------- /documentation/fingerprint_en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit-Fingerprint-Sensor-Library/3e9b2cdeace0e36c9ba5831fd31f4f18e20653c4/documentation/fingerprint_en.pdf -------------------------------------------------------------------------------- /documentation/readme.txt: -------------------------------------------------------------------------------- 1 | The file ZFM-20_Fingerprint_Module.pdf is an automatic translation of the original Chinese datasheet, as performed by Google Translate. We provide it as a courtesy only, and have not reviewed the translation for accuracy or completeness. 2 | 3 | Original datasheet available here: 4 | http://www.adafruit.com/datasheets/DY001fingerprint.pdf 5 | 6 | ------- 7 | R.D. Lesniak, Oct. 31, 2012 -------------------------------------------------------------------------------- /examples/Leo_passthru/.uno.test.skip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit-Fingerprint-Sensor-Library/3e9b2cdeace0e36c9ba5831fd31f4f18e20653c4/examples/Leo_passthru/.uno.test.skip -------------------------------------------------------------------------------- /examples/Leo_passthru/Leo_passthru.ino: -------------------------------------------------------------------------------- 1 | //Leo_passthru 2 | // Allows Leonardo to pass serial data between fingerprint reader and Windows. 3 | // 4 | // Red connects to +5V 5 | // Black connects to Ground 6 | // Green goes to Digital 0 7 | // White goes to Digital 1 8 | 9 | void setup() { 10 | // put your setup code here, to run once: 11 | Serial1.begin(57600); 12 | Serial.begin(57600); 13 | } 14 | 15 | void loop() { 16 | 17 | while (Serial.available()) 18 | Serial1.write(Serial.read()); 19 | while (Serial1.available()) 20 | Serial.write(Serial1.read()); 21 | } -------------------------------------------------------------------------------- /examples/blank/blank.ino: -------------------------------------------------------------------------------- 1 | // this sketch will allow you to bypass the Atmega chip 2 | // and connect the fingerprint sensor directly to the USB/Serial 3 | // chip converter. 4 | 5 | // Red connects to +5V 6 | // Black connects to Ground 7 | // White goes to Digital 0 8 | // Green goes to Digital 1 9 | 10 | void setup() {} 11 | void loop() {} 12 | -------------------------------------------------------------------------------- /examples/changepassword/changepassword.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor 3 | Designed specifically to work with the Adafruit Fingerprint sensor 4 | ----> http://www.adafruit.com/products/751 5 | These displays use TTL Serial to communicate, 2 pins are required to 6 | interface 7 | Adafruit invests time and resources providing this open source code, 8 | please support Adafruit and open-source hardware by purchasing 9 | products from Adafruit! 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, all text above must be included in any redistribution 12 | ****************************************************/ 13 | 14 | #include 15 | 16 | 17 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 18 | // For UNO and others without hardware serial, we must use software serial... 19 | // pin #2 is IN from sensor (GREEN wire) 20 | // pin #3 is OUT from arduino (WHITE wire) 21 | // Set up the serial port to use softwareserial.. 22 | SoftwareSerial mySerial(2, 3); 23 | 24 | #else 25 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 26 | // #0 is green wire, #1 is white 27 | #define mySerial Serial1 28 | 29 | #endif 30 | 31 | // Using sensor without password 32 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 33 | 34 | // Using sensor with password 35 | //Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial, 1337); 36 | 37 | void setup() 38 | { 39 | while (!Serial); // For Yun/Leo/Micro/Zero/... 40 | 41 | Serial.begin(9600); 42 | Serial.println("Adafruit fingerprint sensor, change password example"); 43 | 44 | // set the data rate for the sensor serial port 45 | finger.begin(19200); 46 | 47 | if (finger.verifyPassword()) { 48 | Serial.println("Found fingerprint sensor!"); 49 | } else { 50 | Serial.println("Did not find fingerprint sensor :("); 51 | while (1); 52 | } 53 | 54 | Serial.print("Set password... "); 55 | uint8_t p = finger.setPassword(1337); 56 | if (p == FINGERPRINT_OK) { 57 | Serial.println("OK"); // Password is set 58 | } else { 59 | Serial.println("ERROR"); // Failed to set password 60 | } 61 | } 62 | 63 | void loop() 64 | { 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /examples/delete/delete.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor 3 | 4 | Designed specifically to work with the Adafruit Fingerprint sensor 5 | ----> http://www.adafruit.com/products/751 6 | 7 | These displays use TTL Serial to communicate, 2 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | #include 18 | 19 | 20 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 21 | // For UNO and others without hardware serial, we must use software serial... 22 | // pin #2 is IN from sensor (GREEN wire) 23 | // pin #3 is OUT from arduino (WHITE wire) 24 | // Set up the serial port to use softwareserial.. 25 | SoftwareSerial mySerial(2, 3); 26 | 27 | #else 28 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 29 | // #0 is green wire, #1 is white 30 | #define mySerial Serial1 31 | 32 | #endif 33 | 34 | 35 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 36 | 37 | void setup() 38 | { 39 | Serial.begin(9600); 40 | while (!Serial); // For Yun/Leo/Micro/Zero/... 41 | delay(100); 42 | Serial.println("\n\nDelete Finger"); 43 | 44 | // set the data rate for the sensor serial port 45 | finger.begin(57600); 46 | 47 | if (finger.verifyPassword()) { 48 | Serial.println("Found fingerprint sensor!"); 49 | } else { 50 | Serial.println("Did not find fingerprint sensor :("); 51 | while (1); 52 | } 53 | } 54 | 55 | 56 | uint8_t readnumber(void) { 57 | uint8_t num = 0; 58 | 59 | while (num == 0) { 60 | while (! Serial.available()); 61 | num = Serial.parseInt(); 62 | } 63 | return num; 64 | } 65 | 66 | void loop() // run over and over again 67 | { 68 | Serial.println("Please type in the ID # (from 1 to 127) you want to delete..."); 69 | uint8_t id = readnumber(); 70 | if (id == 0) {// ID #0 not allowed, try again! 71 | return; 72 | } 73 | 74 | Serial.print("Deleting ID #"); 75 | Serial.println(id); 76 | 77 | deleteFingerprint(id); 78 | } 79 | 80 | uint8_t deleteFingerprint(uint8_t id) { 81 | uint8_t p = -1; 82 | 83 | p = finger.deleteModel(id); 84 | 85 | if (p == FINGERPRINT_OK) { 86 | Serial.println("Deleted!"); 87 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 88 | Serial.println("Communication error"); 89 | } else if (p == FINGERPRINT_BADLOCATION) { 90 | Serial.println("Could not delete in that location"); 91 | } else if (p == FINGERPRINT_FLASHERR) { 92 | Serial.println("Error writing to flash"); 93 | } else { 94 | Serial.print("Unknown error: 0x"); Serial.println(p, HEX); 95 | } 96 | 97 | return p; 98 | } 99 | -------------------------------------------------------------------------------- /examples/emptyDatabase/emptyDatabase.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor 3 | Designed specifically to work with the Adafruit Fingerprint sensor 4 | ----> http://www.adafruit.com/products/751 5 | These displays use TTL Serial to communicate, 2 pins are required to 6 | interface 7 | Adafruit invests time and resources providing this open source code, 8 | please support Adafruit and open-source hardware by purchasing 9 | products from Adafruit! 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, all text above must be included in any redistribution 12 | ****************************************************/ 13 | 14 | #include 15 | 16 | 17 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 18 | // For UNO and others without hardware serial, we must use software serial... 19 | // pin #2 is IN from sensor (GREEN wire) 20 | // pin #3 is OUT from arduino (WHITE wire) 21 | // Set up the serial port to use softwareserial.. 22 | SoftwareSerial mySerial(2, 3); 23 | 24 | #else 25 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 26 | // #0 is green wire, #1 is white 27 | #define mySerial Serial1 28 | 29 | #endif 30 | 31 | 32 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 33 | 34 | void setup() 35 | { 36 | Serial.begin(9600); 37 | while (!Serial); // For Yun/Leo/Micro/Zero/... 38 | delay(100); 39 | 40 | Serial.println("\n\nDeleting all fingerprint templates!"); 41 | Serial.println("Press 'Y' key to continue"); 42 | 43 | while (1) { 44 | if (Serial.available() && (Serial.read() == 'Y')) { 45 | break; 46 | } 47 | } 48 | 49 | // set the data rate for the sensor serial port 50 | finger.begin(57600); 51 | 52 | if (finger.verifyPassword()) { 53 | Serial.println("Found fingerprint sensor!"); 54 | } else { 55 | Serial.println("Did not find fingerprint sensor :("); 56 | while (1); 57 | } 58 | 59 | finger.emptyDatabase(); 60 | 61 | Serial.println("Now database is empty :)"); 62 | } 63 | 64 | void loop() { 65 | } 66 | 67 | -------------------------------------------------------------------------------- /examples/enroll/enroll.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor 3 | 4 | Designed specifically to work with the Adafruit BMP085 Breakout 5 | ----> http://www.adafruit.com/products/751 6 | 7 | These displays use TTL Serial to communicate, 2 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | Small bug-fix by Michael cochez 15 | 16 | BSD license, all text above must be included in any redistribution 17 | ****************************************************/ 18 | 19 | #include 20 | 21 | 22 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 23 | // For UNO and others without hardware serial, we must use software serial... 24 | // pin #2 is IN from sensor (GREEN wire) 25 | // pin #3 is OUT from arduino (WHITE wire) 26 | // Set up the serial port to use softwareserial.. 27 | SoftwareSerial mySerial(2, 3); 28 | 29 | #else 30 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 31 | // #0 is green wire, #1 is white 32 | #define mySerial Serial1 33 | 34 | #endif 35 | 36 | 37 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 38 | 39 | uint8_t id; 40 | 41 | void setup() 42 | { 43 | Serial.begin(9600); 44 | while (!Serial); // For Yun/Leo/Micro/Zero/... 45 | delay(100); 46 | Serial.println("\n\nAdafruit Fingerprint sensor enrollment"); 47 | 48 | // set the data rate for the sensor serial port 49 | finger.begin(57600); 50 | 51 | if (finger.verifyPassword()) { 52 | Serial.println("Found fingerprint sensor!"); 53 | } else { 54 | Serial.println("Did not find fingerprint sensor :("); 55 | while (1) { delay(1); } 56 | } 57 | 58 | Serial.println(F("Reading sensor parameters")); 59 | finger.getParameters(); 60 | Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX); 61 | Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX); 62 | Serial.print(F("Capacity: ")); Serial.println(finger.capacity); 63 | Serial.print(F("Security level: ")); Serial.println(finger.security_level); 64 | Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX); 65 | Serial.print(F("Packet len: ")); Serial.println(finger.packet_len); 66 | Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate); 67 | } 68 | 69 | uint8_t readnumber(void) { 70 | uint8_t num = 0; 71 | 72 | while (num == 0) { 73 | while (! Serial.available()); 74 | num = Serial.parseInt(); 75 | } 76 | return num; 77 | } 78 | 79 | void loop() // run over and over again 80 | { 81 | Serial.println("Ready to enroll a fingerprint!"); 82 | Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as..."); 83 | id = readnumber(); 84 | if (id == 0) {// ID #0 not allowed, try again! 85 | return; 86 | } 87 | Serial.print("Enrolling ID #"); 88 | Serial.println(id); 89 | 90 | while (! getFingerprintEnroll() ); 91 | } 92 | 93 | uint8_t getFingerprintEnroll() { 94 | 95 | int p = -1; 96 | Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id); 97 | while (p != FINGERPRINT_OK) { 98 | p = finger.getImage(); 99 | switch (p) { 100 | case FINGERPRINT_OK: 101 | Serial.println("Image taken"); 102 | break; 103 | case FINGERPRINT_NOFINGER: 104 | Serial.print("."); 105 | break; 106 | case FINGERPRINT_PACKETRECIEVEERR: 107 | Serial.println("Communication error"); 108 | break; 109 | case FINGERPRINT_IMAGEFAIL: 110 | Serial.println("Imaging error"); 111 | break; 112 | default: 113 | Serial.println("Unknown error"); 114 | break; 115 | } 116 | } 117 | 118 | // OK success! 119 | 120 | p = finger.image2Tz(1); 121 | switch (p) { 122 | case FINGERPRINT_OK: 123 | Serial.println("Image converted"); 124 | break; 125 | case FINGERPRINT_IMAGEMESS: 126 | Serial.println("Image too messy"); 127 | return p; 128 | case FINGERPRINT_PACKETRECIEVEERR: 129 | Serial.println("Communication error"); 130 | return p; 131 | case FINGERPRINT_FEATUREFAIL: 132 | Serial.println("Could not find fingerprint features"); 133 | return p; 134 | case FINGERPRINT_INVALIDIMAGE: 135 | Serial.println("Could not find fingerprint features"); 136 | return p; 137 | default: 138 | Serial.println("Unknown error"); 139 | return p; 140 | } 141 | 142 | Serial.println("Remove finger"); 143 | delay(2000); 144 | p = 0; 145 | while (p != FINGERPRINT_NOFINGER) { 146 | p = finger.getImage(); 147 | } 148 | Serial.print("ID "); Serial.println(id); 149 | p = -1; 150 | Serial.println("Place same finger again"); 151 | while (p != FINGERPRINT_OK) { 152 | p = finger.getImage(); 153 | switch (p) { 154 | case FINGERPRINT_OK: 155 | Serial.println("Image taken"); 156 | break; 157 | case FINGERPRINT_NOFINGER: 158 | Serial.print("."); 159 | break; 160 | case FINGERPRINT_PACKETRECIEVEERR: 161 | Serial.println("Communication error"); 162 | break; 163 | case FINGERPRINT_IMAGEFAIL: 164 | Serial.println("Imaging error"); 165 | break; 166 | default: 167 | Serial.println("Unknown error"); 168 | break; 169 | } 170 | } 171 | 172 | // OK success! 173 | 174 | p = finger.image2Tz(2); 175 | switch (p) { 176 | case FINGERPRINT_OK: 177 | Serial.println("Image converted"); 178 | break; 179 | case FINGERPRINT_IMAGEMESS: 180 | Serial.println("Image too messy"); 181 | return p; 182 | case FINGERPRINT_PACKETRECIEVEERR: 183 | Serial.println("Communication error"); 184 | return p; 185 | case FINGERPRINT_FEATUREFAIL: 186 | Serial.println("Could not find fingerprint features"); 187 | return p; 188 | case FINGERPRINT_INVALIDIMAGE: 189 | Serial.println("Could not find fingerprint features"); 190 | return p; 191 | default: 192 | Serial.println("Unknown error"); 193 | return p; 194 | } 195 | 196 | // OK converted! 197 | Serial.print("Creating model for #"); Serial.println(id); 198 | 199 | p = finger.createModel(); 200 | if (p == FINGERPRINT_OK) { 201 | Serial.println("Prints matched!"); 202 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 203 | Serial.println("Communication error"); 204 | return p; 205 | } else if (p == FINGERPRINT_ENROLLMISMATCH) { 206 | Serial.println("Fingerprints did not match"); 207 | return p; 208 | } else { 209 | Serial.println("Unknown error"); 210 | return p; 211 | } 212 | 213 | Serial.print("ID "); Serial.println(id); 214 | p = finger.storeModel(id); 215 | if (p == FINGERPRINT_OK) { 216 | Serial.println("Stored!"); 217 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 218 | Serial.println("Communication error"); 219 | return p; 220 | } else if (p == FINGERPRINT_BADLOCATION) { 221 | Serial.println("Could not store in that location"); 222 | return p; 223 | } else if (p == FINGERPRINT_FLASHERR) { 224 | Serial.println("Error writing to flash"); 225 | return p; 226 | } else { 227 | Serial.println("Unknown error"); 228 | return p; 229 | } 230 | 231 | return true; 232 | } 233 | -------------------------------------------------------------------------------- /examples/fingerprint/fingerprint.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor 3 | 4 | Designed specifically to work with the Adafruit BMP085 Breakout 5 | ----> http://www.adafruit.com/products/751 6 | 7 | These displays use TTL Serial to communicate, 2 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | 18 | #include 19 | 20 | 21 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 22 | // For UNO and others without hardware serial, we must use software serial... 23 | // pin #2 is IN from sensor (GREEN wire) 24 | // pin #3 is OUT from arduino (WHITE wire) 25 | // Set up the serial port to use softwareserial.. 26 | SoftwareSerial mySerial(2, 3); 27 | 28 | #else 29 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 30 | // #0 is green wire, #1 is white 31 | #define mySerial Serial1 32 | 33 | #endif 34 | 35 | 36 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 37 | 38 | void setup() 39 | { 40 | Serial.begin(9600); 41 | while (!Serial); // For Yun/Leo/Micro/Zero/... 42 | delay(100); 43 | Serial.println("\n\nAdafruit finger detect test"); 44 | 45 | // set the data rate for the sensor serial port 46 | finger.begin(57600); 47 | delay(5); 48 | if (finger.verifyPassword()) { 49 | Serial.println("Found fingerprint sensor!"); 50 | } else { 51 | Serial.println("Did not find fingerprint sensor :("); 52 | while (1) { delay(1); } 53 | } 54 | 55 | Serial.println(F("Reading sensor parameters")); 56 | finger.getParameters(); 57 | Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX); 58 | Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX); 59 | Serial.print(F("Capacity: ")); Serial.println(finger.capacity); 60 | Serial.print(F("Security level: ")); Serial.println(finger.security_level); 61 | Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX); 62 | Serial.print(F("Packet len: ")); Serial.println(finger.packet_len); 63 | Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate); 64 | 65 | finger.getTemplateCount(); 66 | 67 | if (finger.templateCount == 0) { 68 | Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example."); 69 | } 70 | else { 71 | Serial.println("Waiting for valid finger..."); 72 | Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates"); 73 | } 74 | } 75 | 76 | void loop() // run over and over again 77 | { 78 | getFingerprintID(); 79 | delay(50); //don't ned to run this at full speed. 80 | } 81 | 82 | uint8_t getFingerprintID() { 83 | uint8_t p = finger.getImage(); 84 | switch (p) { 85 | case FINGERPRINT_OK: 86 | Serial.println("Image taken"); 87 | break; 88 | case FINGERPRINT_NOFINGER: 89 | Serial.println("No finger detected"); 90 | return p; 91 | case FINGERPRINT_PACKETRECIEVEERR: 92 | Serial.println("Communication error"); 93 | return p; 94 | case FINGERPRINT_IMAGEFAIL: 95 | Serial.println("Imaging error"); 96 | return p; 97 | default: 98 | Serial.println("Unknown error"); 99 | return p; 100 | } 101 | 102 | // OK success! 103 | 104 | p = finger.image2Tz(); 105 | switch (p) { 106 | case FINGERPRINT_OK: 107 | Serial.println("Image converted"); 108 | break; 109 | case FINGERPRINT_IMAGEMESS: 110 | Serial.println("Image too messy"); 111 | return p; 112 | case FINGERPRINT_PACKETRECIEVEERR: 113 | Serial.println("Communication error"); 114 | return p; 115 | case FINGERPRINT_FEATUREFAIL: 116 | Serial.println("Could not find fingerprint features"); 117 | return p; 118 | case FINGERPRINT_INVALIDIMAGE: 119 | Serial.println("Could not find fingerprint features"); 120 | return p; 121 | default: 122 | Serial.println("Unknown error"); 123 | return p; 124 | } 125 | 126 | // OK converted! 127 | p = finger.fingerSearch(); 128 | if (p == FINGERPRINT_OK) { 129 | Serial.println("Found a print match!"); 130 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { 131 | Serial.println("Communication error"); 132 | return p; 133 | } else if (p == FINGERPRINT_NOTFOUND) { 134 | Serial.println("Did not find a match"); 135 | return p; 136 | } else { 137 | Serial.println("Unknown error"); 138 | return p; 139 | } 140 | 141 | // found a match! 142 | Serial.print("Found ID #"); Serial.print(finger.fingerID); 143 | Serial.print(" with confidence of "); Serial.println(finger.confidence); 144 | 145 | return finger.fingerID; 146 | } 147 | 148 | // returns -1 if failed, otherwise returns ID # 149 | int getFingerprintIDez() { 150 | uint8_t p = finger.getImage(); 151 | if (p != FINGERPRINT_OK) return -1; 152 | 153 | p = finger.image2Tz(); 154 | if (p != FINGERPRINT_OK) return -1; 155 | 156 | p = finger.fingerFastSearch(); 157 | if (p != FINGERPRINT_OK) return -1; 158 | 159 | // found a match! 160 | Serial.print("Found ID #"); Serial.print(finger.fingerID); 161 | Serial.print(" with confidence of "); Serial.println(finger.confidence); 162 | return finger.fingerID; 163 | } 164 | -------------------------------------------------------------------------------- /examples/ledcontrol/ledcontrol.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor with LED ring 3 | 4 | These displays use TTL Serial to communicate, 2 pins are required to 5 | interface 6 | Adafruit invests time and resources providing this open source code, 7 | please support Adafruit and open-source hardware by purchasing 8 | products from Adafruit! 9 | 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, all text above must be included in any redistribution 12 | ****************************************************/ 13 | 14 | 15 | #include 16 | 17 | 18 | 19 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 20 | // For UNO and others without hardware serial, we must use software serial... 21 | // pin #2 is IN from sensor (GREEN wire) 22 | // pin #3 is OUT from arduino (WHITE wire) 23 | // Set up the serial port to use softwareserial.. 24 | SoftwareSerial mySerial(2, 3); 25 | 26 | #else 27 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 28 | // #0 is green wire, #1 is white 29 | #define mySerial Serial1 30 | 31 | #endif 32 | 33 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 34 | 35 | void setup() 36 | { 37 | Serial.begin(9600); 38 | while (!Serial); // For Yun/Leo/Micro/Zero/... 39 | delay(100); 40 | Serial.println("\n\nAdafruit finger detect test"); 41 | 42 | // set the data rate for the sensor serial port 43 | finger.begin(57600); 44 | delay(5); 45 | if (finger.verifyPassword()) { 46 | Serial.println("Found fingerprint sensor!"); 47 | } else { 48 | Serial.println("Did not find fingerprint sensor :("); 49 | while (1) { delay(1); } 50 | } 51 | 52 | Serial.println(F("Reading sensor parameters")); 53 | finger.getParameters(); 54 | Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX); 55 | Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX); 56 | Serial.print(F("Capacity: ")); Serial.println(finger.capacity); 57 | Serial.print(F("Security level: ")); Serial.println(finger.security_level); 58 | Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX); 59 | Serial.print(F("Packet len: ")); Serial.println(finger.packet_len); 60 | Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate); 61 | 62 | 63 | } 64 | 65 | void loop() // run over and over again 66 | { 67 | // LED fully on 68 | finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED); 69 | delay(250); 70 | finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE); 71 | delay(250); 72 | finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE); 73 | delay(250); 74 | 75 | // flash red LED 76 | finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10); 77 | delay(2000); 78 | // Breathe blue LED till we say to stop 79 | finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE); 80 | delay(3000); 81 | finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_PURPLE); 82 | delay(2000); 83 | finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_PURPLE); 84 | delay(2000); 85 | } 86 | -------------------------------------------------------------------------------- /examples/show_fingerprint_templates/show_fingerprint_templates.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example sketch for our optical Fingerprint sensor 3 | 4 | Adafruit invests time and resources providing this open source code, 5 | please support Adafruit and open-source hardware by purchasing 6 | products from Adafruit! 7 | 8 | Written by Limor Fried/Ladyada for Adafruit Industries. 9 | BSD license, all text above must be included in any redistribution 10 | ****************************************************/ 11 | 12 | 13 | #include 14 | 15 | #if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__) 16 | // For UNO and others without hardware serial, we must use software serial... 17 | // pin #2 is IN from sensor (GREEN wire) 18 | // pin #3 is OUT from arduino (WHITE wire) 19 | // Set up the serial port to use softwareserial.. 20 | SoftwareSerial mySerial(2, 3); 21 | 22 | #else 23 | // On Leonardo/M0/etc, others with hardware serial, use hardware serial! 24 | // #0 is green wire, #1 is white 25 | #define mySerial Serial1 26 | 27 | #endif 28 | 29 | 30 | Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 31 | 32 | int getFingerprintIDez(); 33 | 34 | void setup() 35 | { 36 | while (!Serial); 37 | Serial.begin(9600); 38 | Serial.println("Fingerprint template extractor"); 39 | 40 | // set the data rate for the sensor serial port 41 | finger.begin(57600); 42 | 43 | if (finger.verifyPassword()) { 44 | Serial.println("Found fingerprint sensor!"); 45 | } else { 46 | Serial.println("Did not find fingerprint sensor :("); 47 | while (1); 48 | } 49 | 50 | // Try to get the templates for fingers 1 through 10 51 | for (int finger = 1; finger < 10; finger++) { 52 | downloadFingerprintTemplate(finger); 53 | } 54 | } 55 | 56 | uint8_t downloadFingerprintTemplate(uint16_t id) 57 | { 58 | Serial.println("------------------------------------"); 59 | Serial.print("Attempting to load #"); Serial.println(id); 60 | uint8_t p = finger.loadModel(id); 61 | switch (p) { 62 | case FINGERPRINT_OK: 63 | Serial.print("Template "); Serial.print(id); Serial.println(" loaded"); 64 | break; 65 | case FINGERPRINT_PACKETRECIEVEERR: 66 | Serial.println("Communication error"); 67 | return p; 68 | default: 69 | Serial.print("Unknown error "); Serial.println(p); 70 | return p; 71 | } 72 | 73 | // OK success! 74 | 75 | Serial.print("Attempting to get #"); Serial.println(id); 76 | p = finger.getModel(); 77 | switch (p) { 78 | case FINGERPRINT_OK: 79 | Serial.print("Template "); Serial.print(id); Serial.println(" transferring:"); 80 | break; 81 | default: 82 | Serial.print("Unknown error "); Serial.println(p); 83 | return p; 84 | } 85 | 86 | // one data packet is 267 bytes. in one data packet, 11 bytes are 'usesless' :D 87 | uint8_t bytesReceived[534]; // 2 data packets 88 | memset(bytesReceived, 0xff, 534); 89 | 90 | uint32_t starttime = millis(); 91 | int i = 0; 92 | while (i < 534 && (millis() - starttime) < 20000) { 93 | if (mySerial.available()) { 94 | bytesReceived[i++] = mySerial.read(); 95 | } 96 | } 97 | Serial.print(i); Serial.println(" bytes read."); 98 | Serial.println("Decoding packet..."); 99 | 100 | uint8_t fingerTemplate[512]; // the real template 101 | memset(fingerTemplate, 0xff, 512); 102 | 103 | // filtering only the data packets 104 | int uindx = 9, index = 0; 105 | memcpy(fingerTemplate + index, bytesReceived + uindx, 256); // first 256 bytes 106 | uindx += 256; // skip data 107 | uindx += 2; // skip checksum 108 | uindx += 9; // skip next header 109 | index += 256; // advance pointer 110 | memcpy(fingerTemplate + index, bytesReceived + uindx, 256); // second 256 bytes 111 | 112 | for (int i = 0; i < 512; ++i) { 113 | //Serial.print("0x"); 114 | printHex(fingerTemplate[i], 2); 115 | //Serial.print(", "); 116 | } 117 | Serial.println("\ndone."); 118 | 119 | return p; 120 | 121 | /* 122 | uint8_t templateBuffer[256]; 123 | memset(templateBuffer, 0xff, 256); //zero out template buffer 124 | int index=0; 125 | uint32_t starttime = millis(); 126 | while ((index < 256) && ((millis() - starttime) < 1000)) 127 | { 128 | if (mySerial.available()) 129 | { 130 | templateBuffer[index] = mySerial.read(); 131 | index++; 132 | } 133 | } 134 | 135 | Serial.print(index); Serial.println(" bytes read"); 136 | 137 | //dump entire templateBuffer. This prints out 16 lines of 16 bytes 138 | for (int count= 0; count < 16; count++) 139 | { 140 | for (int i = 0; i < 16; i++) 141 | { 142 | Serial.print("0x"); 143 | Serial.print(templateBuffer[count*16+i], HEX); 144 | Serial.print(", "); 145 | } 146 | Serial.println(); 147 | }*/ 148 | } 149 | 150 | 151 | 152 | void printHex(int num, int precision) { 153 | char tmp[16]; 154 | char format[128]; 155 | 156 | sprintf(format, "%%.%dX", precision); 157 | 158 | sprintf(tmp, format, num); 159 | Serial.print(tmp); 160 | } 161 | 162 | void loop() 163 | {} 164 | 165 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit Fingerprint Sensor Library 2 | version=2.1.3 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for interfacing to the fingerprint sensor in the Adafruit shop 6 | paragraph=Arduino library for interfacing to the fingerprint sensor in the Adafruit shop 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | --------------------------------------------------------------------------------