G26 (RX)
と G0 (TX)
です。/**
* @file Unit_Finger_M5StickCPlus.ino
* @author Zovey (liangzhuowei@m5stack.com)
* @brief
* @version 0.1
* @date 2025-07-04
*
* @Hardwares: StickC-Plus2 + Hat Finger
* @Dependent Library:
* M5_FPC1020A: https://github.com/m5stack/M5-FPC1020A
*/
#include <M5Unified.h>
#include "M5_FPC1020A.h"
M5_FPC1020A finger;
uint8_t user_id = 0;
bool add_user_process(uint8_t id, uint8_t permission) ;
bool user_check(void);
void setup() {
M5.begin();
Serial.begin(115200);
M5.Display.setRotation(1);
M5.Display.setTextColor(BLACK);
M5.Display.setTextSize(1);
M5.Display.setFont(&fonts::FreeMonoBold9pt7b);
M5.Display.setCursor(0, 0);
M5.Display.println("Finger Unit init...");
if (!finger.begin(&Serial2, 26, 0, 19200)) {
Serial.println("FPC1020A not found");
while (1) delay(1);
}
M5.Display.fillRect(0, 0, 240, 135, WHITE);
M5.Display.setCursor(0, 0);
M5.Display.println("Finger Unit TEST");
uint8_t userNum = finger.getUserCount();
Serial.print("userNum:");
Serial.println(userNum);
finger.delAllFinger();
M5.Display.println("All User Deleted");
M5.Display.println("Btn.A add a user");
M5.Display.println("Btn.B verify user");
}
uint8_t new_user_id = 1;
void loop() {
M5.update();
if (M5.BtnA.wasPressed()) {
// user id: 1 ~ 0xfff
if (add_user_process(new_user_id, 1)) {
Serial.println("add user success");
M5.Display.println("add user success");
new_user_id++;
}
}
if (M5.BtnB.wasPressed()) {
M5.Display.fillRect(0, 0, 240, 135, WHITE);
M5.Display.setCursor(0, 0);
if(new_user_id == 1) M5.Display.printf("There is no id. Please add the user first!\r\n");
user_check();
}
}
bool add_user_process(uint8_t id, uint8_t permission) {
uint8_t a = 40;
M5.Display.fillRect(0, 0, 240, 135, WHITE);
M5.Display.setCursor(0, 0);
M5.Display.println("add finger process:");
M5.Display.println("put your finger on the sensor");
for (uint8_t i = 0; i < 6; i++) {
while (!finger.addFinger(id, permission, i)) {
Serial.printf("Finger ID: %d Finger Record:%d error\r\n", id, i);
Serial.println("Retry...");
delay(1000);
};
a += 9;
M5.Display.scroll(0, -9);
M5.Display.fillRect(0, a, 240, 135, WHITE);
M5.Display.setCursor(0, a);
M5.Display.printf("add finger count:%d/6\r\n", i + 1);
Serial.printf("Finger ID: %d Finger Record:%d ok\r\n", id, i);
}
M5.Display.printf("Finger ID: %d added\r\n", id);
return true;
}
bool user_check(void){
while((new_user_id > 1)){
uint8_t res = finger.available();
if (res == ACK_SUCCESS) {
M5.Display.println("Success");
Serial.println("Success");
M5.Display.print("User ID: ");
Serial.print("User ID: ");
M5.Display.println(finger.getFingerID());
Serial.println(finger.getFingerID());
M5.Display.print("User Permission: ");
Serial.print("User Permission: ");
M5.Display.println(finger.getFingerPermission());
Serial.println(finger.getFingerPermission());
return true;
} else {
M5.Display.fillRect(0, 0, 240, 135, WHITE);
M5.Display.setCursor(0, 0);
Serial.println("Please put your ID Finger on the sensor");
M5.Display.println("Please put your ID Finger on the sensor");
delay(1000);
}
}
return false;
}
Btn.A
ボタンを押すと指紋登録ページに進み、Btn.B
ボタンを押すと指紋認証ページに進みます。Btn.B
ボタンを押し、指をセンサーに置いて認証が完了するまで待ちます。Success
などの文字が表示されると、認証成功を意味します(この画面は認証成功時のみ切り替わります)。