Hi there, I'm programmer but never write arduino.
I try to use fingerprint module with UNO board.
and download adafruit library and example to use
everything seem go fine.
but the problem is enrolling my fingerprint.
I input number ID of my fingerprint to the board via serial
at first I check the value of variable that can receive number correctly
but everytime the ID variable turned to zero before store to the module
let check with source code
or you can download adafruit to check it on your own
I have not change anything.
void loop() // run over and over again
{
Serial.println("Type in the ID # you want to save this finger as...");
uint8_t id = 0;
while (true) {
while (! Serial.available());
char c = Serial.read();
if (! isdigit(c)) break;
id *= 10;
id += c - '0';
}
Serial.print("Enrolling ID #");
Serial.println(id);
while (! getFingerprintEnroll(id) );
}
uint8_t getFingerprintEnroll(uint8_t id) {
uint8_t p = -1;
Serial.println("Waiting for valid finger to enroll");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;
}
}
// OK success!
p = finger.image2Tz(1);
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
in function loop everything ok.
but function getFingerprintEnroll that have
parameter uint8_t id
that have value from calling from loop function
"never" write anything on it.
but the value in it was changed to zero before it store to memory
I have check by function Serial.println(id);
and found the value has been changed at the point
p = finger.getImage();
I try input number 7 it turn to 2 at first this function call.
and turn to zero at another call.
but hey,.. another surprise to me..
I try to make another variable inside the function
uint8_t id_temp = id;
for making backup the value;
before it's changed.
... but this variable has been changed too T_T
both id and id_temp turn to zero value in function
so I try another way..
I change the value to fix number
uint8_t id_temp = 10;
this time.. it's ok
the value unchange it still be "10" till the end of function.
and finally, I fluky found solution..
adding this lines will make the variable value not changed till the end.
Serial.println(id);
Serial.println(id);
Serial.println(id);
Serial.println(id);
Serial.println(id);
it has to be 5 lines,... not less.
4 line not help, just 5 line.
even added to the end of function, it still work.
this make me sick.
I don't know why.