[vc_row][vc_column width=”1/1″][vc_column_text]
[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1389055482-1-76″][vc_column_text]
- 1 x pcDuino v2
- 1 x FM-206 Optical Fingerprint Module for pcDuino/Arduino
[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1389055482-2-96″][vc_column_text]Wire Diagram:
White -> GPIO 1 of pcDuino
Green -> GPIO 0 of pcDuino
Black -> GND of pcDuino
Red -> 5V of pcDuino
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1389056217570-2-3″][vc_column_text]Enroll code:
/*****************
fingerprint_enroll.cpp
*****************/
#include <core.h>
#include <stdlib.h>
#define FINGERPRINT_TIMEOUT 0xFF
#define FINGERPRINT_BADPACKET 0xFE
#define FINGERPRINT_ACKPACKET 0×07
uint8_t lc = 0;
uint8_t i = 0;
const uint8_t Verify[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×07, 0×13, 0×00, 0×00, 0×00, 0×00, 0×00, 0x1B};
const uint8_t Getimage[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×03, 0×01, 0×00, 0×05};
const uint8_t Img2tz_1[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×04, 0×02, 0×01, 0×00, 0×08};
const uint8_t Img2tz_2[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×04, 0×02, 0×02, 0×00, 0×09};
const uint8_t Match[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×03, 0×03, 0×00, 0×07};
const uint8_t Regmodel[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×03, 0×05, 0×00, 0×09};
void cmd_fun (const uint8_t *p, uint8_t len){
// printf (“cmd_fun have begin!\n”);
// Serial.flush();
for (lc = 0; lc < len; lc++){
Serial.write (*p++);
delay (1);
}
}
uint8_t get_reply (uint8_t packet[], uint16_t timeout){
printf (“\n”);
// printf (“begin get_reply!\n”);
uint8_t reply[20], idx;
uint16_t timer = 0;
idx = 0;
// printf (“begin to loop in get_reply\n”);
while (1){
// printf (“begin to loop in while(1)\n”);
while (!(Serial.available () > 0)){
delay(1);
timer++;
if (timer >= timeout)
return FINGERPRINT_TIMEOUT;
}
// printf (“begin to read something!\n”);
reply[idx] = Serial.read ();
printf(“reply[%x] = %02x “, idx, reply[idx]);
if ((idx == 0) && (reply[0] != 0xEF))
continue;
idx++;
// printf (“idx = %x\n”, idx);
if (idx >= 9){
if ((reply[0] != 0xEF) || (reply[1] != 0×01))
return FINGERPRINT_BADPACKET;
uint16_t len = reply[7];
len <<= 8;
len |= reply[8];
len -= 2;
// printf (“len = %x\n”, len);
if (idx <= (len + 10))
continue;
packet[0] = reply[6];
// printf (“packet[0] = %x\n”, reply[6]);
for (uint8_t i = 0; i < len; i++){
packet[1 + i] = reply[9 + i];
// printf (“packet[%x] = %x”,i + 1,packet[1 + i]);
}
return len;
}
}
}
boolean verify_fun (void){
printf (“verify_fun begin!\n”);
uint8_t packet[] = {};
cmd_fun (Verify, 16);
printf (“packet have send!\n”);
uint8_t len = get_reply (packet,5000);
printf (“len = %x\n”, len);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return true;
}
uint8_t getimage_fun (void){
uint8_t packet[] = {};
cmd_fun (Getimage, 12);
uint8_t len = get_reply (packet, 1000);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t img2tz_1_fun (void){
uint8_t packet[] = {};
cmd_fun (Img2tz_1, 13);
uint8_t len = get_reply (packet, 1000);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t img2tz_2_fun (void){
uint8_t packet[] = {};
cmd_fun (Img2tz_2, 13);
uint8_t len = get_reply (packet, 1000);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t regmodel_fun (void){
uint8_t packet[] = {};
cmd_fun (Regmodel, 12);
uint8_t len = get_reply (packet, 1000);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t store_fun (uint16_t id){
printf (“请输入指纹对应的ID:”);
scanf (“%x”, &id);
printf (“确认指纹ID : %u\n”, id);
uint8_t packet[] = {};
const uint8_t Store[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×06, 0×06, 0×01, id >> 8, id & 0xFF, 0×00, 0x0F};
cmd_fun (Store, 15);
uint8_t len = get_reply (packet, 1000);
if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}
uint8_t fingerprint_enroll (void){
uint8_t p = -1;
p = verify_fun ();
p = getimage_fun ();
if (p == 0×00){
printf (“\n”);
printf (“image_1 taken!\n”);
}
else {
printf (“\n”);
printf (“get image_1 failed!\n”);
getimage_fun();
}
p = img2tz_1_fun ();
if (p == 0×00){
printf (“\n”);
printf (“image_1 converted!\n”);
}
else {
printf (“\n”);
printf (“convert image_1 failed!\n”);
}
printf (“wait for verification again!\n”);
delay(2000);
printf (“it’s starting to verify fingerprint again \n”);
p = getimage_fun ();
if (p == 0×00){
printf (“\n”);
printf (“image_2 taken!\n”);
}
else {
printf (“\n”);
printf (“take image_2 failed!\n”);
}
p = img2tz_2_fun ();
if (p == 0×00){
printf (“\n”);
printf (“image_2 converted!\n”);
}
else {
printf (“\n”);
printf (“convert image_2 failed!\n”);
}
p = regmodel_fun ();
if (p == 0×00){
printf (“\n”);
printf (“match image successed!\n”);
}
else {
printf (“\n”);
printf (“match image failed!\n”);
}
p = store_fun (2);
if (p == 0×00){
printf (“\n”);
printf (“store image successed!\n”);
exit(0);
}
else {
printf (“\n”);
printf (“store image failed!\n”);
}
}
void setup (){
Serial.begin (57600);
printf (“fingertest\n”);
}
void loop () {
fingerprint_enroll ();
}
Recognition code:
/********************
fingerprint_search.cpp
********************/
#include <core.h>
#define FINGERPRINT_TIMEOUT 0xFF
#define FINGERPRINT_BADPACKET 0xFE
#define FINGERPRINT_ACKPACKET 0×07
uint8_t i = 0;
uint8_t lc = 0;
uint16_t fingerID;
uint16_t score;
const uint8_t Verify[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×07, 0×13, 0×00, 0×00, 0×00, 0×00, 0×00, 0x1B};
const uint8_t Getimage[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×03, 0×01, 0×00, 0×05};
const uint8_t Img2tz[] = {0xEF, 0×01, 0xFF, 0xFF, 0xFF, 0xFF, 0×01, 0×00, 0×04, 0×02, 0×01, 0×00, 0×08};
const uint8_t Search[] = {0xEF,0×01,0xFF,0xFF,0xFF,0xFF,0×01,0×00,0×08,0x1B,0×01,0×00,0×00,0×00,0xA3,0×00,0xC8};
void cmd_fun (const uint8_t *p, uint8_t len){
for (lc = 0; lc < len; lc++){
Serial.write (*p++);
// delay (1);
}
// delay (100);
}
uint8_t get_reply (uint8_t packet[], uint16_t timeout){
// printf (“begin get_reply!\n”);
uint8_t reply[300];
uint8_t idx;
uint16_t timer = 0;
idx = 0;
// printf (“begin to loop in get_reply\n”);
while (1){
// printf (“begin to loop in while(1)\n”);
while (!(Serial.available () > 0)){
delay(1);
timer++;
if (timer >= timeout)
return FINGERPRINT_TIMEOUT;
}
// printf (“begin to read something!\n”);
reply[idx] = Serial.read ();
printf(“reply[%x] = %02x “, idx, reply[idx]);
if ((idx == 0) && (reply[0] != 0xEF))
continue;
idx++;
// printf (“idx = %x\n”, idx);
if (idx >= 9){
if ((reply[0] != 0xEF) || (reply[1] != 0×01))
return FINGERPRINT_BADPACKET;
uint16_t len = reply[7];
len <<= 8;
len |= reply[8];
len -= 2;
// printf (“len = %x\n”, len);
if (idx <= (len + 10))
continue;
packet[0] = reply[6];
// printf (“packet[0] = %x\n”, reply[6]);
for (uint8_t i = 0; i < len; i++){
packet[1 + i] = reply[9 + i];
// printf (“packet[%x] = %x”,i + 1,packet[1 + i]);
}
return len;
}
}
}
boolean varify_fun (void){
uint8_t packet[30];
cmd_fun (Verify, 16);
uint8_t len = get_reply (packet, 1000);
if ((packet[1] != FINGERPRINT_ACKPACKET) && (len != 1)){
return false;
}
else {
return true;
}
while (Serial.read() >= 0);
}
uint8_t getimage_fun (void){
uint8_t packet[30];
cmd_fun (Getimage, 12);
uint8_t len = get_reply (packet, 1000);
if ((packet[1] != FINGERPRINT_ACKPACKET) && (len != 1)){
return -1;
}
else {
return packet[1];
}
while (Serial.read() >= 0);
}
uint8_t imgtz_fun (void){
uint8_t packet[30];
cmd_fun (Img2tz, 13);
uint8_t len = get_reply (packet, 1000);
if ((packet[1] != FINGERPRINT_ACKPACKET) && (len != 1)){
return -1;
}
else {
return packet[1];
}
while (Serial.read() >= 0);
}
uint8_t search_fun (void){
uint8_t packet[30];
cmd_fun (Search, 17);
uint8_t len = get_reply(packet, 1000);
if ((packet[0] != FINGERPRINT_ACKPACKET) || (len < 5)){
return -1;
}
else {
fingerID = packet[2];
fingerID <<= 8;
fingerID |= packet[3];
score = packet[4];
score <<= 8;
score |= packet[5];
if ((packet [1] == 0×00) && (fingerID != 0×00)){
printf (“fingerID is %d\n”, fingerID);
printf (“match score is %d\n”, score);
}
return packet[1];
}
}
uint8_t getid_fun (){
uint8_t p = -1;
p = varify_fun ();
if (p == true){
printf (“Varify successed!\n”);
}
else {
printf (“Varify failed!\n”);
// return p;
}
// delay (100);
p = getimage_fun ();
if (p == 0×00){
printf (“Get Image successed!\n”);
}
else {
printf (“Get Image Failed!\n”);
// return p;
}
// delay (100);
p = imgtz_fun ();
if (p == 0×00){
printf (“Converted Image successed!\n”);
}
else {
printf (“Converted Image Failed!\n”);
// return p;
}
// delay (100);
p = search_fun ();
if (p == 0×00){
printf (“Search finger successed!\n”);
exit(0);
}
else if (p == 0×09){
printf (“No finger!\n”);
// return p;
}
else {
printf (“Search finger failed\n”);
// return p;
}
}
void setup (){
Serial.begin (57600);
}
void loop (){
getid_fun ();
}[/vc_column_text][/vc_tab][vc_tab title=”Compile the code” tab_id=”1389056425735-3-4″][vc_column_text]
If the arduino SDK environment is set, we can compile by:
$gcc ***/fingerprin_enroll.cpp -larduino (***/ is the path of the code)
We can then run a.out and press the finger on the sensor.
We can also copy the code to the built-in Arduino IDE and compile.
[/vc_column_text][/vc_tab][vc_tab title=”Results and notes” tab_id=”1389056608829-5-6″][vc_column_text]
When we press finger on the sensor, and run the code:
Arrary ‘reply’ stores the returned messages. We can judge if we got correct return value from these returned messages. If it displays ‘“store image successed!”, that means we record the fingerprint successfully!
We now move on to recognition part:
If it succeeds finding the fingerprint, the screen will print “Search finger successed!” along with the ID and matching score.
[/vc_column_text][/vc_tab][vc_tab title=”Appendix” tab_id=”1389056545214-4-9″][vc_column_text]User manual[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
September 2, 2014 at 5:28 pm
I’m using a Pcduino 3 and the same fingerprint scanner. I put my finger on the scanner and run the exact code you have and all I ever get is the failed messages.