pcDuino指纹识别

标签: 硬件 pcduino 指纹识别 | 发表时间:2014-02-26 01:39 | 作者:杰克祥子
出处:http://www.geekfan.net

前言

指纹,由于其具有终身不变性、唯一性和方便性,已几乎成为生物特征识别的代名词。由于科学技术的日益发展。指纹模块也渐渐深入人们生活中。今天就给大家展示一下如何在 pcDuino上进行指纹识别。

指纹
一:准备工作

pcduino V2  x  1

FM-206系列光学指纹模块  x  1

二:连线和注意事项

0

白线(左数第二根)连接gpio 1

绿线(左数第三根)连接gpio 0

黑线(左数第一根)连接GND

红线(左数第四根)连接 pcduino 上的5v输出

注意:

模块本身自带的线是没有脚的,可能导致接触不良从而实验无法成功,最好如图焊上。

三:实验代码

指纹模块录入代码:

/*****************

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 ();
}

指纹模块识别代码:

/********************

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 ();
}

 

四:编译代码

如果在pcduino上配置好了arduino编译环境可以通过在终端输入

$gcc ***/fingerprin_enroll.cpp -larduino       (***/是你存放代码的路径)

然后手指放在指纹模块上运行a.out文件就行。

没有配置环境的朋友也可以把代码内容拷贝到pcduino自带的IDE来进行编译。

五:实验结果及说明

0 (1)手指放在模块上,运行代码首先会提示一些错误信息。不过没关系。
0 (2)

0 (3)
reply数组存储模块返回的指令。我们可以通过这些指令信息来判断模块是否对我们发送过去的指令有着正确的回应。终端显示“store image successed!”表示指纹已经成功录入。

0 (4)

如果成功找到指纹的话屏幕会打印出“Search finger successed!”

还有对应的ID 和分数。

六:附录

实验过程可能偶尔失败一两次属于正常现象。

附上FM-206指纹模块手册:

Fingerprint user manual英文版

指纹模块手册(中文版)

有兴趣进一步开发的朋友可以研究研究。

pcDuino指纹识别,首发于 极客范 - GeekFan.net

相关 [pcduino 指纹识别] 推荐:

pcDuino指纹识别

- - 极客范 - GeekFan.net
指纹,由于其具有终身不变性、唯一性和方便性,已几乎成为生物特征识别的代名词. 今天就给大家展示一下如何在 pcDuino上进行指纹识别. FM-206系列光学指纹模块  x  1. 白线(左数第二根)连接gpio 1. 绿线(左数第三根)连接gpio 0. 黑线(左数第一根)连接GND. 红线(左数第四根)连接 pcduino 上的5v输出.

iPhone 5S将配指纹识别 Home键变化不大

- - 威锋网新闻- 最新RSS订阅
  随着 9 月 10 日苹果新品发布会的日益临近,有关苹果新一代 iPhone 的爆料也越来越频繁. 威锋网 8 月 20 日消息,来自外媒 9to5Mac 的 Mark Gurman 今天发表了一篇篇幅非常长的报道,分享了其消息人士带来的有关 iPhone 5S 以及 iOS 7 的更多细节.   Gurman 在报道中表示,iPhone 5S 确定将会配备指纹识别功能,指纹扫描仪将内置在 Home 键中.

iPhone 5s指纹识别存在什么安全隐患?

- - cnBeta.COM业界资讯
据悉,在配置了这样一个生物识别模块后,用户将可以通过把手指放在Home键上解锁手机. 而且,当用户需要在iTunes商店购买应用的时候也可以使用这一方式进行确认,并免去了烦琐的密码输入工作. 那么, iPhone 5S的指纹识别技术是否真的足够安全. 对此,《美联社》就这一问题特地请教了谷歌前点击欺诈主管、Shape Security战略副总裁舒曼-高斯麻吉穆德(Shuman Ghosemajumder).

Windows 8.1 新安全特性之一,原生指纹识别支持

- - LiveSino 中文版
就在微软正在召开的 TechEd 2013 北美会议上,其中一场 Session 便是介绍 Windows 8.1 中改进的那些安全特性. 在 TechEd 现场演示中,演讲者 Chris Hallum 真机演示了 Windows 8.1 原生指纹识别的种种使用场景. 在 Windows 8.1 中,指纹识别功能已经原生支持于系统,比如可以指纹锁定某文件夹或应用,也可以快速登录指纹绑定的账户(或远程登录),或是在商店购买内容前的验证 – 微软也正在探索更多使用场景.

苹果发布iOS 7 Beta 4:指纹识别功能得到证实

- - TechWeb 今日焦点 RSS阅读
苹果发布iOS 7 Beta 4:滑动解锁提示增加箭头. 苹果iOS 7 Beta 4新增九宫格输入法 仅支持国行版. 生物测量学验证包文件夹(TechWeb配图).   【TechWeb报道】7月30日消息,据国外媒体报道,苹果今天发布了iOS 7 Beta 4,而新测试版的系统中包含了一个名为“生物测量学包”(Biometric Kit),appleinsider网站称,这个文件包是目前证实新一代iPhone增加了指纹验证功能的最有力的证据.