@ Baby,
You could use a combination of the upchar and store function.
Don't have any code for it but have a look at the datasheet: http://www.adafruit.com/datasheets/ZFM% ... ualV15.pdf
Regs,
J
Fingerprint question
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- areyouserial
- Posts: 26
- Joined: Mon Jul 20, 2015 7:06 pm
Re: Fingerprint question
1. Based on mediatek's description here: http://labs.mediatek.com/forums/posts/list/64.page , the LinkIt One's core is NOT Atmel AVR architecture, it is ARM7EJS.brianrho wrote:The printed stuff makes no sense. There is no confirmation code of 140 or 66 and the module cannot send commands to the MCU, so a response packet-type of '1' is not possible. Your LINKIT ONE isnt using an AVR MCU, right? I cant help but wonder if the commented #include <util/delay.h> is responsible for the problems. It may be that the delay(1000) at the top of the .cpp file is ineffective or if the hardwareserial requires the delay file to function properly. On your PC, can you find delay.h at this location: C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\util ?
If you can find it, then enter this location, with delay.h at the end, in the #include statement you removed earlier and run the code again. If you cant find it, search your arduino installation folder (use the search bar) for delay.h or search the Linkit ONE sdk folder for an equivalent and then include it. Also, does the module's red LED flash whenever it's printing Unknown Error? Or does it happen only after you've placed your finger?
2. When I uncomment the "#include <util/delay.h>" line in the Adafruit_Fingerprint.cpp file (That folder tree is Machintosh HD-> Users -> Machintosh -> Documents -> Arduino -> libraries -> Adafruit-Hardware-Serial-Fingerprint-Sensor-Library- -> Adafruit_Fingerprint.cpp), the following error message is generated in the Arduino IDE like so:
Code: Select all
Using library Hardware Serial Adafruit Fingerprint Sensor Library in folder: /Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master
/Users/Machintosh/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -O2 -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=arm7tdmi-s -DF_CPU=84000000L -DARDUINO=10604 -DARDUINO_MTK_ONE -DARDUINO_ARCH_ARM -D__COMPILER_GCC__ -D__LINKIT_ONE__ -D__LINKIT_ONE_RELEASE__ -mthumb -DUSB_VID=0x0E8D -DUSB_PID=0x0023 -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="LinkIt ONE" -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/system/libmtk -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/system/libmtk/include -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/cores/arduino -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/variants/linkit_one -I/Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master /var/folders/cd/37v_tz896jncjr0ltn8r6q2r0000gn/T/build5204224558748441997.tmp/enroll_test_8_5_15.cpp -o /var/folders/cd/37v_tz896jncjr0ltn8r6q2r0000gn/T/build5204224558748441997.tmp/enroll_test_8_5_15.cpp.o
/Users/Machintosh/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -O2 -fvisibility=hidden -fpic -mthumb -mlittle-endian -nostdlib -fno-non-call-exceptions -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=arm7tdmi-s -DF_CPU=84000000L -DARDUINO=10604 -DARDUINO_MTK_ONE -DARDUINO_ARCH_ARM -D__COMPILER_GCC__ -D__LINKIT_ONE__ -D__LINKIT_ONE_RELEASE__ -mthumb -DUSB_VID=0x0E8D -DUSB_PID=0x0023 -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="LinkIt ONE" -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/system/libmtk -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/system/libmtk/include -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/cores/arduino -I/Users/Machintosh/Library/Arduino15/packages/LinkIt/hardware/arm/1.1.11/variants/linkit_one -I/Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master -I/Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master/utility /Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master/Adafruit_Fingerprint.cpp -o /var/folders/cd/37v_tz896jncjr0ltn8r6q2r0000gn/T/build5204224558748441997.tmp/Hardware Serial Adafruit Fingerprint Sensor Library/Adafruit_Fingerprint.cpp.o
/Users/Machintosh/Documents/Arduino/libraries/Adafruit-Hardware-Serial-Fingerprint-Sensor-Library-master/Adafruit_Fingerprint.cpp:26:24: fatal error: util/delay.h: No such file or directory
#include <util/delay.h>
^
compilation terminated.
Error compiling.
Code: Select all
/***************************************************
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
****************************************************/
/////
/////commented out the util/delay.h because file not found but when uncomment, the error (file not found) shows up even though the delay.h file is in the arduino sketch
///// D.N. 8/5/15
/////
/////added in two lines at 67: "Serial.println(len)" and 68: "Serial.println(packet[0])" for testing
///// D.N 8/8/15
#include "Adafruit_Fingerprint.h"
#include <util/delay.h>
Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *ss) {
thePassword = 0;
theAddress = 0xFFFFFFFF;
mySerial = ss;
}
void Adafruit_Fingerprint::begin(uint16_t baudrate) {
delay(1000); // one second delay to let the sensor 'boot up'
mySerial->begin(baudrate);
}
boolean Adafruit_Fingerprint::verifyPassword(void) {
uint8_t packet[] = {FINGERPRINT_VERIFYPASSWORD,
(thePassword >> 24), (thePassword >> 16),
(thePassword >> 8), thePassword};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 7, packet);
uint8_t len = getReply(packet);
if ((len == 1) && (packet[0] == FINGERPRINT_ACKPACKET) && (packet[1] == FINGERPRINT_OK))
return true;
/*
Serial.print("\nGot packet type "); Serial.print(packet[0]);
for (uint8_t i=1; i<len+1;i++) {
Serial.print(" 0x");
Serial.print(packet[i], HEX);
}
*/
return false;
}
uint8_t Adafruit_Fingerprint::getImage(void) {
uint8_t packet[] = {FINGERPRINT_GETIMAGE};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, 3, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET)){
Serial.println(len);
Serial.println(packet[0]);
Serial.println(packet[1]);
return -1;
}
return packet[1];
}
uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
uint8_t packet[] = {FINGERPRINT_IMAGE2TZ, slot};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t Adafruit_Fingerprint::createModel(void) {
uint8_t packet[] = {FINGERPRINT_REGMODEL};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
uint8_t packet[] = {FINGERPRINT_STORE, 0x01, id >> 8, id & 0xFF};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
//read a fingerprint template from flash into Char Buffer 1
uint8_t Adafruit_Fingerprint::loadModel(uint16_t id) {
uint8_t packet[] = {FINGERPRINT_LOAD, 0x01, id >> 8, id & 0xFF};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
//transfer a fingerprint template from Char Buffer 1 to host computer
uint8_t Adafruit_Fingerprint::getModel(void) {
uint8_t packet[] = {FINGERPRINT_UPLOAD, 0x01};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t Adafruit_Fingerprint::deleteModel(uint16_t id) {
uint8_t packet[] = {FINGERPRINT_DELETE, id >> 8, id & 0xFF, 0x00, 0x01};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
uint8_t packet[] = {FINGERPRINT_EMPTY};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
fingerID = 0xFFFF;
confidence = 0xFFFF;
// high speed search of slot #1 starting at page 0x0000 and page #0x00A3
uint8_t packet[] = {FINGERPRINT_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
fingerID = packet[2];
fingerID <<= 8;
fingerID |= packet[3];
confidence = packet[4];
confidence <<= 8;
confidence |= packet[5];
return packet[1];
}
uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
templateCount = 0xFFFF;
// get number of templates in memory
uint8_t packet[] = {FINGERPRINT_TEMPLATECOUNT};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
templateCount = packet[2];
templateCount <<= 8;
templateCount |= packet[3];
return packet[1];
}
void Adafruit_Fingerprint::writePacket(uint32_t addr, uint8_t packettype,
uint16_t len, uint8_t *packet) {
#ifdef FINGERPRINT_DEBUG
Serial.print("---> 0x");
Serial.print((uint8_t)(FINGERPRINT_STARTCODE >> 8), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)FINGERPRINT_STARTCODE, HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr >> 24), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr >> 16), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr >> 8), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(addr), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)packettype, HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(len >> 8), HEX);
Serial.print(" 0x");
Serial.print((uint8_t)(len), HEX);
#endif
#if ARDUINO >= 100
mySerial->write((uint8_t)(FINGERPRINT_STARTCODE >> 8));
mySerial->write((uint8_t)FINGERPRINT_STARTCODE);
mySerial->write((uint8_t)(addr >> 24));
mySerial->write((uint8_t)(addr >> 16));
mySerial->write((uint8_t)(addr >> 8));
mySerial->write((uint8_t)(addr));
mySerial->write((uint8_t)packettype);
mySerial->write((uint8_t)(len >> 8));
mySerial->write((uint8_t)(len));
#else
mySerial->print((uint8_t)(FINGERPRINT_STARTCODE >> 8), BYTE);
mySerial->print((uint8_t)FINGERPRINT_STARTCODE, BYTE);
mySerial->print((uint8_t)(addr >> 24), BYTE);
mySerial->print((uint8_t)(addr >> 16), BYTE);
mySerial->print((uint8_t)(addr >> 8), BYTE);
mySerial->print((uint8_t)(addr), BYTE);
mySerial->print((uint8_t)packettype, BYTE);
mySerial->print((uint8_t)(len >> 8), BYTE);
mySerial->print((uint8_t)(len), BYTE);
#endif
uint16_t sum = (len>>8) + (len&0xFF) + packettype;
for (uint8_t i=0; i< len-2; i++) {
#if ARDUINO >= 100
mySerial->write((uint8_t)(packet[i]));
#else
mySerial->print((uint8_t)(packet[i]), BYTE);
#endif
#ifdef FINGERPRINT_DEBUG
Serial.print(" 0x"); Serial.print(packet[i], HEX);
#endif
sum += packet[i];
}
#ifdef FINGERPRINT_DEBUG
//Serial.print("Checksum = 0x"); Serial.println(sum);
Serial.print(" 0x"); Serial.print((uint8_t)(sum>>8), HEX);
Serial.print(" 0x"); Serial.println((uint8_t)(sum), HEX);
#endif
#if ARDUINO >= 100
mySerial->write((uint8_t)(sum>>8));
mySerial->write((uint8_t)sum);
#else
mySerial->print((uint8_t)(sum>>8), BYTE);
mySerial->print((uint8_t)sum, BYTE);
#endif
}
uint8_t Adafruit_Fingerprint::getReply(uint8_t packet[], uint16_t timeout) {
uint8_t reply[20], idx;
uint16_t timer=0;
idx = 0;
#ifdef FINGERPRINT_DEBUG
Serial.print("<--- ");
#endif
while (true) {
while (!mySerial->available()) {
delay(1);
timer++;
if (timer >= timeout) return FINGERPRINT_TIMEOUT;
}
// something to read!
reply[idx] = mySerial->read();
#ifdef FINGERPRINT_DEBUG
Serial.print(" 0x"); Serial.print(reply[idx], HEX);
#endif
if ((idx == 0) && (reply[0] != (FINGERPRINT_STARTCODE >> 8)))
continue;
idx++;
// check packet!
if (idx >= 9) {
if ((reply[0] != (FINGERPRINT_STARTCODE >> 8)) ||
(reply[1] != (FINGERPRINT_STARTCODE & 0xFF)))
return FINGERPRINT_BADPACKET;
uint8_t packettype = reply[6];
//Serial.print("Packet type"); Serial.println(packettype);
uint16_t len = reply[7];
len <<= 8;
len |= reply[8];
len -= 2;
//Serial.print("Packet len"); Serial.println(len);
if (idx <= (len+10)) continue;
packet[0] = packettype;
for (uint8_t i=0; i<len; i++) {
packet[1+i] = reply[9+i];
}
#ifdef FINGERPRINT_DEBUG
Serial.println();
#endif
return len;
}
}
}
a. delay_basic.h which reads:
Code: Select all
/* Copyright (c) 2002, Marek Michalkiewicz
Copyright (c) 2007 Joerg Wunsch
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* $Id$ */
#ifndef _UTIL_DELAY_BASIC_H_
#define _UTIL_DELAY_BASIC_H_ 1
#include <inttypes.h>
#if !defined(__DOXYGEN__)
static inline void _delay_loop_1(uint8_t __count) __attribute__((always_inline));
static inline void _delay_loop_2(uint16_t __count) __attribute__((always_inline));
#endif
/** \file */
/** \defgroup util_delay_basic <util/delay_basic.h>: Basic busy-wait delay loops
\code
#include <util/delay_basic.h>
\endcode
The functions in this header file implement simple delay loops
that perform a busy-waiting. They are typically used to
facilitate short delays in the program execution. They are
implemented as count-down loops with a well-known CPU cycle
count per loop iteration. As such, no other processing can
occur simultaneously. It should be kept in mind that the
functions described here do not disable interrupts.
In general, for long delays, the use of hardware timers is
much preferrable, as they free the CPU, and allow for
concurrent processing of other events while the timer is
running. However, in particular for very short delays, the
overhead of setting up a hardware timer is too much compared
to the overall delay time.
Two inline functions are provided for the actual delay algorithms.
*/
/** \ingroup util_delay_basic
Delay loop using an 8-bit counter \c __count, so up to 256
iterations are possible. (The value 256 would have to be passed
as 0.) The loop executes three CPU cycles per iteration, not
including the overhead the compiler needs to setup the counter
register.
Thus, at a CPU speed of 1 MHz, delays of up to 768 microseconds
can be achieved.
*/
void
_delay_loop_1(uint8_t __count)
{
__asm__ volatile (
"1: dec %0" "\n\t"
"brne 1b"
: "=r" (__count)
: "0" (__count)
);
}
/** \ingroup util_delay_basic
Delay loop using a 16-bit counter \c __count, so up to 65536
iterations are possible. (The value 65536 would have to be
passed as 0.) The loop executes four CPU cycles per iteration,
not including the overhead the compiler requires to setup the
counter register pair.
Thus, at a CPU speed of 1 MHz, delays of up to about 262.1
milliseconds can be achieved.
*/
void
_delay_loop_2(uint16_t __count)
{
__asm__ volatile (
"1: sbiw %0,1" "\n\t"
"brne 1b"
: "=w" (__count)
: "0" (__count)
);
}
#endif /* _UTIL_DELAY_BASIC_H_ */
Code: Select all
/* Copyright (c) 2002, Marek Michalkiewicz
Copyright (c) 2004,2005,2007 Joerg Wunsch
Copyright (c) 2007 Florin-Viorel Petrov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* $Id$ */
#ifndef _UTIL_DELAY_H_
#define _UTIL_DELAY_H_ 1
#ifndef __HAS_DELAY_CYCLES
#define __HAS_DELAY_CYCLES 1
#endif
#include <inttypes.h>
#include <util/delay_basic.h>
#include <math.h>
/** \file */
/** \defgroup util_delay <util/delay.h>: Convenience functions for busy-wait delay loops
\code
#define F_CPU 1000000UL // 1 MHz
//#define F_CPU 14.7456E6
#include <util/delay.h>
\endcode
\note As an alternative method, it is possible to pass the
F_CPU macro down to the compiler from the Makefile.
Obviously, in that case, no \c \#define statement should be
used.
The functions in this header file are wrappers around the basic
busy-wait functions from <util/delay_basic.h>. They are meant as
convenience functions where actual time values can be specified
rather than a number of cycles to wait for. The idea behind is
that compile-time constant expressions will be eliminated by
compiler optimization so floating-point expressions can be used
to calculate the number of delay cycles needed based on the CPU
frequency passed by the macro F_CPU.
\note In order for these functions to work as intended, compiler
optimizations <em>must</em> be enabled, and the delay time
<em>must</em> be an expression that is a known constant at
compile-time. If these requirements are not met, the resulting
delay will be much longer (and basically unpredictable), and
applications that otherwise do not use floating-point calculations
will experience severe code bloat by the floating-point library
routines linked into the application.
The functions available allow the specification of microsecond, and
millisecond delays directly, using the application-supplied macro
F_CPU as the CPU clock frequency (in Hertz).
*/
#if !defined(__DOXYGEN__)
static inline void _delay_us(double __us) __attribute__((always_inline));
static inline void _delay_ms(double __ms) __attribute__((always_inline));
#endif
#ifndef F_CPU
/* prevent compiler error by supplying a default */
# warning "F_CPU not defined for <util/delay.h>"
# define F_CPU 1000000UL
#endif
#ifndef __OPTIMIZE__
# warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
#endif
#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
!defined(__DELAY_BACKWARD_COMPATIBLE__) && \
__STDC_HOSTED__
# include <math.h>
#endif
/**
\ingroup util_delay
Perform a delay of \c __ms milliseconds, using _delay_loop_2().
The macro F_CPU is supposed to be defined to a
constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 262.14 ms / F_CPU in MHz.
When the user request delay which exceed the maximum possible one,
_delay_ms() provides a decreased resolution functionality. In this
mode _delay_ms() will work with a resolution of 1/10 ms, providing
delays up to 6.5535 seconds (independent from CPU frequency). The
user will not be informed about decreased resolution.
If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
support, maximal possible delay is 4294967.295 ms/ F_CPU in MHz. For
values greater than the maximal possible delay, overflows results in
no delay i.e., 0ms.
Conversion of __us into clock cycles may not always result in integer.
By default, the clock cycles rounded up to next integer. This ensures that
the user gets atleast __us microseconds of delay.
Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__
to round down and round to closest integer.
Note: The new implementation of _delay_ms(double __ms) with
__builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
Also, the backward compatible
algorithm will be chosen if the code is compiled in a <em>freestanding
environment</em> (GCC option \c -ffreestanding), as the math functions
required for rounding are not available to the compiler then.
*/
void
_delay_ms(double __ms)
{
double __tmp ;
#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
!defined(__DELAY_BACKWARD_COMPATIBLE__) && \
__STDC_HOSTED__
uint32_t __ticks_dc;
extern void __builtin_avr_delay_cycles(unsigned long);
__tmp = ((F_CPU) / 1e3) * __ms;
#if defined(__DELAY_ROUND_DOWN__)
__ticks_dc = (uint32_t)fabs(__tmp);
#elif defined(__DELAY_ROUND_CLOSEST__)
__ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
#else
uint16_t __ticks;
__tmp = ((F_CPU) / 4e3) * __ms;
if (__tmp < 1.0)
__ticks = 1;
else if (__tmp > 65535)
{
// __ticks = requested delay in 1/10 ms
__ticks = (uint16_t) (__ms * 10.0);
while(__ticks)
{
// wait 1/10 ms
_delay_loop_2(((F_CPU) / 4e3) / 10);
__ticks --;
}
return;
}
else
__ticks = (uint16_t)__tmp;
_delay_loop_2(__ticks);
#endif
}
/**
\ingroup util_delay
Perform a delay of \c __us microseconds, using _delay_loop_1().
The macro F_CPU is supposed to be defined to a
constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 768 us / F_CPU in MHz.
If the user requests a delay greater than the maximal possible one,
_delay_us() will automatically call _delay_ms() instead. The user
will not be informed about this case.
If the avr-gcc toolchain has __builtin_avr_delay_cycles(unsigned long)
support, maximal possible delay is 4294967.295 us/ F_CPU in MHz. For
values greater than the maximal possible delay, overflow results in
no delay i.e., 0us.
Conversion of __us into clock cycles may not always result in integer.
By default, the clock cycles rounded up to next integer. This ensures that
the user gets atleast __us microseconds of delay.
Alternatively, user can define __DELAY_ROUND_DOWN__ and __DELAY_ROUND_CLOSEST__
to round down and round to closest integer.
Note: The new implementation of _delay_us(double __us) with
__builtin_avr_delay_cycles(unsigned long) support is not backward compatible.
User can define __DELAY_BACKWARD_COMPATIBLE__ to get a backward compatible delay.
Also, the backward compatible
algorithm will be chosen if the code is compiled in a <em>freestanding
environment</em> (GCC option \c -ffreestanding), as the math functions
required for rounding are not available to the compiler then.
*/
void
_delay_us(double __us)
{
double __tmp ;
#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
!defined(__DELAY_BACKWARD_COMPATIBLE__) && \
__STDC_HOSTED__
uint32_t __ticks_dc;
extern void __builtin_avr_delay_cycles(unsigned long);
__tmp = ((F_CPU) / 1e6) * __us;
#if defined(__DELAY_ROUND_DOWN__)
__ticks_dc = (uint32_t)fabs(__tmp);
#elif defined(__DELAY_ROUND_CLOSEST__)
__ticks_dc = (uint32_t)(fabs(__tmp)+0.5);
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
#else
uint8_t __ticks;
double __tmp2 ;
__tmp = ((F_CPU) / 3e6) * __us;
__tmp2 = ((F_CPU) / 4e6) * __us;
if (__tmp < 1.0)
__ticks = 1;
else if (__tmp2 > 65535)
{
_delay_ms(__us / 1000.0);
}
else if (__tmp > 255)
{
uint16_t __ticks=(uint16_t)__tmp2;
_delay_loop_2(__ticks);
return;
}
else
__ticks = (uint8_t)__tmp;
_delay_loop_1(__ticks);
#endif
}
#endif /* _UTIL_DELAY_H_ */
i. first the sketch is uploaded and the only two lights on are the "power" light and the "L" light which i presume stands for LED
ii. upon opening the serial monitor at 9600 baud, it prompts me to enter an ID # to associate with an upcoming fingerprint
iii. once I enter a letter or a number, monitor says "Waiting for valid finger to enroll"
iv. at this point the board has the green power led on, the L light is green, the Tx is a solid red, and the Rx is blinking rapidly before placing a fingerprint
v. once a fingerprint is placed, both Tx and Rx lights are off (only remaining lights are the green power and green L lights) and the serial monitor says:
Image taken
Unknown error2
Type in the ID # you want to save this finger as...
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Fingerprint question
Have you got a regular Arduino you can try this with? Just to make sure the sensor is working properly...
- areyouserial
- Posts: 26
- Joined: Mon Jul 20, 2015 7:06 pm
Re: Fingerprint question
Yes, I thought about that and I have a spark fun red board (it works on that so I'm dumbfounded why it won't work on the linkit one). I had to uninstall all the adafruit fingerprint hardware serial libraries arduino ide then reinstall the ide with the software serial library. I'll redo that and show you what I get. This time, I'll do it on a windows machine.
I even re-soldered the wires to ensure that the connections were sound and put on extra female to male wires to avoid the metal pins from touching each other.
I even re-soldered the wires to ensure that the connections were sound and put on extra female to male wires to avoid the metal pins from touching each other.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Fingerprint question
I really can't say what the problem with the linkit board is. I've never seen one.
- areyouserial
- Posts: 26
- Joined: Mon Jul 20, 2015 7:06 pm
Re: Fingerprint question
Then is this a level shifter problem like below?
http://www.seeedstudio.com/forum/viewto ... =42&t=5752
http://www.seeedstudio.com/forum/viewto ... =42&t=5752
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Fingerprint question
I don't know. I kind of doubt it, but it can't hurt to try. You'll need a bidirectional level shifter:
https://www.adafruit.com/product/1875
https://www.adafruit.com/product/1875
- areyouserial
- Posts: 26
- Joined: Mon Jul 20, 2015 7:06 pm
Re: Fingerprint question
I believe it is a power limitation vs the arduino uno or sparkfun red board (which can handle 7-15V). And we are back to tesla and electricity. I need to reassess what boards can handle the output and necessary power pull I want in my invention. Need to go find a few books to read.
- brianrho
- Posts: 19
- Joined: Fri Jul 31, 2015 11:36 am
Re: Fingerprint question
Before, i was speaking about the fingerprint module's red LED. Does it flash when it says "Waiting for a fingerprint" and "Unknown Error"? If it doesnt, then it means the sensor really isnt ready to scan fingers. Have you tried including the delay.h that u found? Something like:
#include <Applications/Arduino/Contents/Java/hardware/tools/avr/avr/include/util/delay.h>
Use the full path address.
If this doesnt work, then in place of the delay(1000) in the vfyPassword() method in the library, place a for loop that counts from i=1 to i=2000000, with nothing in the body of the loop. Perhaps this will give the module enough time to initialize (assuming that's the problem).
#include <Applications/Arduino/Contents/Java/hardware/tools/avr/avr/include/util/delay.h>
Use the full path address.
If this doesnt work, then in place of the delay(1000) in the vfyPassword() method in the library, place a for loop that counts from i=1 to i=2000000, with nothing in the body of the loop. Perhaps this will give the module enough time to initialize (assuming that's the problem).
- areyouserial
- Posts: 26
- Joined: Mon Jul 20, 2015 7:06 pm
Re: Fingerprint question
Hi Brian and Rick,
I got fed up with the LinkIt One board and switched to a complete arduino/adafruit set up for my project. I ran tests on the adafruit fingerprint in the following three scenarios (all three boards could blink):
1. Windows 10, 1.6.5 arduino IDE, adafruit fingerprint module, arduino uno r3, SFG demo (windows fingerprint software), baud rate 9600 on arduino serial monitor, baud rate on sfg demo was 57600
a. When we plug the usb from the arduino to the fingerprint When we tested the fingerprint software, we got are far as device
First, we connected the uno and fingerprint module combo to the windows pc, the red light flashed once to indicate that power was being applied to the unit. Upon opening the windows fingerprint software for the fingerprint module, we were able to click on the "open device (O)" and selected the appropriate COM port, and the message in the software was "Open Device Success!". When we click "enroll" on the windows software GUI, the entire GUI freezes requiring a force quit.
b. Then we tried debugging using the arduino ide and serial monitor, the serial monitor said: "fingerprint sensor not found :("
2. Mac OS X 10.10.3, Arduino IDE 1.6.5, adafruit fingerprint module, sparkfun red board (from inventors kit), baud rate on arduino serial monitor was 9600
The fingerprint flashed red once when connected the Mac PC indicated power connection was good. However, when uploading the "enroll sketch" using the adafruit fingerprint sensor library, the serial monitor output was "Did not find fingerprint sensor :(
".
3. Mac OS X 10.10.3, Arduino IDE 1.6.5, adafruit fingerprint module, arduino uno r3, baud rate on arduino serial monitor was 9600 (57600 generates question marks)
The fingerprint flashed once indicating power. The sketch successfully uploaded but the arduino serial monitor said:
ALL three scenarios were using the following arduino code:
The arduino code below was used in all three scenarios:
At this point, this is a fingerprint module problem I believe.
I got fed up with the LinkIt One board and switched to a complete arduino/adafruit set up for my project. I ran tests on the adafruit fingerprint in the following three scenarios (all three boards could blink):
1. Windows 10, 1.6.5 arduino IDE, adafruit fingerprint module, arduino uno r3, SFG demo (windows fingerprint software), baud rate 9600 on arduino serial monitor, baud rate on sfg demo was 57600
a. When we plug the usb from the arduino to the fingerprint When we tested the fingerprint software, we got are far as device
First, we connected the uno and fingerprint module combo to the windows pc, the red light flashed once to indicate that power was being applied to the unit. Upon opening the windows fingerprint software for the fingerprint module, we were able to click on the "open device (O)" and selected the appropriate COM port, and the message in the software was "Open Device Success!". When we click "enroll" on the windows software GUI, the entire GUI freezes requiring a force quit.
b. Then we tried debugging using the arduino ide and serial monitor, the serial monitor said: "fingerprint sensor not found :("
2. Mac OS X 10.10.3, Arduino IDE 1.6.5, adafruit fingerprint module, sparkfun red board (from inventors kit), baud rate on arduino serial monitor was 9600
The fingerprint flashed red once when connected the Mac PC indicated power connection was good. However, when uploading the "enroll sketch" using the adafruit fingerprint sensor library, the serial monitor output was "Did not find fingerprint sensor :(
".
3. Mac OS X 10.10.3, Arduino IDE 1.6.5, adafruit fingerprint module, arduino uno r3, baud rate on arduino serial monitor was 9600 (57600 generates question marks)
The fingerprint flashed once indicating power. The sketch successfully uploaded but the arduino serial monitor said:
ALL three scenarios were using the following arduino code:
Code: Select all
fingertest
Did not find fingerprint sensor :(
Code: Select all
/***************************************************
This is an example sketch for our optical Fingerprint sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> http://www.adafruit.com/products/751
These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
uint8_t getFingerprintEnroll(int id);
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup()
{
Serial.begin(9600);
Serial.println("fingertest");
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1);
}
}
void loop() // run over and over again
{
Serial.println("Type in the ID # you want to save this finger as...");
int id = 0;
while (true) {
while (! Serial.available());
char c = Serial.read();
if (! isdigit(c)) break;
id *= 10;
id += c - '0';
}
Serial.print("Enrolling ID #");
Serial.println(id);
while (! getFingerprintEnroll(id) );
}
uint8_t getFingerprintEnroll(int id) {
int p = -1;
Serial.println("Waiting for valid finger to enroll");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;
}
}
// OK success!
p = finger.image2Tz(1);
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
Serial.println("Remove finger");
delay(2000);
p = 0;
while (p != FINGERPRINT_NOFINGER) {
p = finger.getImage();
}
p = -1;
Serial.println("Place same finger again");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;
}
}
// OK success!
p = finger.image2Tz(2);
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.createModel();
if (p == FINGERPRINT_OK) {
Serial.println("Prints matched!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
Serial.println("Fingerprints did not match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
Serial.print("ID "); Serial.println(id);
p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
Serial.println("Stored!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
Serial.println("Could not store in that location");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
Serial.println("Error writing to flash");
return p;
} else {
Serial.println("Unknown error");
return p;
}
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Fingerprint question
In scenario 3, you had the green wire connected to pin 2 and the white to pin 3?
If I recall correctly, you have soldered headers or solid code jumper wires to the fingerprint wires, right?
If the SFGDemo successfully opened the sensor, even if it crashed later, that suggests that the sensor is communicating properly.
If I recall correctly, you have soldered headers or solid code jumper wires to the fingerprint wires, right?
If the SFGDemo successfully opened the sensor, even if it crashed later, that suggests that the sensor is communicating properly.
- areyouserial
- Posts: 26
- Joined: Mon Jul 20, 2015 7:06 pm
Re: Fingerprint question
The pins were in pins 0 and 1 so upon switching them with the uno, all went well on the OS X platform.adafruit_support_rick wrote:In scenario 3, you had the green wire connected to pin 2 and the white to pin 3?
If I recall correctly, you have soldered headers or solid code jumper wires to the fingerprint wires, right?
If the SFGDemo successfully opened the sensor, even if it crashed later, that suggests that the sensor is communicating properly.
I'm currently now working with the Arduino Due due to i2c, and slave select limitations on the others board. Is Don Jeronimo's and Rick's (https://github.com/adafruit/Adafruit-Fi ... Sensor-Due) still the best open source stuff out for the adafruit fingerprint with the Arduino Due?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Fingerprint question
It's the only library we support here.
- brianrho
- Posts: 19
- Joined: Fri Jul 31, 2015 11:36 am
Re: Fingerprint question
Use
right before both return statements in the verifyPassword() method, enclosing them in braces where needed.
Code: Select all
Serial.println(len);
Serial.println(packet[0]);
Serial.println(packet[1]);
- ram16690
- Posts: 4
- Joined: Mon Jun 22, 2015 12:02 am
Re: Fingerprint question
HI help me out..
I am connecting r305 fingerprint module with arduino using adafruit library with esp8266 wifi module..
my problem is when the fingerprint module doesn't get any input it goes to sleep and when i open the serial monitor in arduino ide it wakes up again..
is there a solution or any hint..
cheers..
I am connecting r305 fingerprint module with arduino using adafruit library with esp8266 wifi module..
my problem is when the fingerprint module doesn't get any input it goes to sleep and when i open the serial monitor in arduino ide it wakes up again..
is there a solution or any hint..
cheers..
Please be positive and constructive with your questions and comments.