Fingerprint sensor data send/read without library

i want to achieve this function without using adafruit fingerprint library:

i want to copy functions from this lib to my code

 
#include <Adafruit_Fingerprint.h>
#define mySerial Serial2
 
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  Serial.begin(9600);
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  Serial.println(F("Reading sensor parameters"));
  finger.getParameters();
  Serial.print(F("Status: 0x")); Serial.println(finger.status_reg, HEX);
  Serial.print(F("Sys ID: 0x")); Serial.println(finger.system_id, HEX);
  Serial.print(F("Capacity: ")); Serial.println(finger.capacity);
  Serial.print(F("Security level: ")); Serial.println(finger.security_level);
  Serial.print(F("Device address: ")); Serial.println(finger.device_addr, HEX);
  Serial.print(F("Packet len: ")); Serial.println(finger.packet_len);
  Serial.print(F("Baud rate: ")); Serial.println(finger.baud_rate);


}

void loop()                     // run over and over again
{
  // LED fully on
  finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
  delay(250);
  finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);
  delay(250);
  finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE);
  delay(250);

  // flash red LED
  finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10);
  delay(2000);
  // Breathe blue LED till we say to stop
  finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE);
  delay(3000);
  finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_PURPLE);
  delay(2000);
  finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_PURPLE);
  delay(2000);
}

so i want a to build a code like this:

#include <HardwareSerial.h>

// Define commands and constants
uint32_t password = 0xFFFFFFFF;  // Replace with your fingerprint sensor password
#define FINGERPRINT_VERIFYPASSWORD 0x13
#define FINGERPRINT_OK 0x00
#define FINGERPRINT_PACKETRECIEVEERR 0x01
#define FINGERPRINT_TEMPLATECOUNT 0x1D //!< Read finger template numbers
#define FINGERPRINT_AURALEDCONFIG 0x35 //!< Aura LED control
#define FINGERPRINT_LEDON 0x50         //!< Turn on the onboard LED
#define FINGERPRINT_LEDOFF 0x51        //!< Turn off the onboard LED

#define FINGERPRINT_LED_BREATHING 0x01   //!< Breathing light
#define FINGERPRINT_LED_FLASHING 0x02    //!< Flashing light
#define FINGERPRINT_LED_ON 0x03          //!< Always on
#define FINGERPRINT_LED_OFF 0x04         //!< Always off
#define FINGERPRINT_LED_GRADUAL_ON 0x05  //!< Gradually on
#define FINGERPRINT_LED_GRADUAL_OFF 0x06 //!< Gradually off
#define FINGERPRINT_LED_RED 0x01         //!< Red LED
#define FINGERPRINT_LED_BLUE 0x02        //!< Blue LED
#define FINGERPRINT_LED_PURPLE 0x03      //!< Purple LEDpassword

#define FINGERPRINT_REG_ADDR_ERROR 0x1A //!< shows register address error
#define FINGERPRINT_WRITE_REG 0x0E      //!< Write system register instruction



void setup() {
  Serial.begin(9600);
  Serial2.begin(57600, SERIAL_8N1, 16, 17);  // 8 data bits, no parity, 1 stop bit
}

void loop() {

  if (verifyPassword(password)) {
    Serial.println("Password verified!");
  } else {
    Serial.println("Password verification failed!");
  }
  delay(1000);
}


// Function to verify the fingerprint sensor's password
boolean verifyPassword() {
 
}

  
// Function to send a command packet to the fingerprint sensor
void sendCommandPacket(){
 
} 
  
void getParameters(){
 
}
void LEDcontrol(){

}

Can u write me an example for

boolean verifyPassword() {

}

void sendCommandPacket(){

}

and ill try to do others

So why not go ahead and copy them ?

tried to make a procedural functions but no success,
i was not able to make this work:

if (verifyPassword(password)) {
Serial.println("Password verified!");
}

The library obviously has a verifyPassword() function. Please post it here

Have you copied it to your sketch ?

i tried like this


bool verifyPassword() {
 uint8_t packet[] = {0xF5, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x07, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x14};
 Serial2.write(packet, sizeof(packet));
 return waitForResponse(0x00);
}

void getParameters() {
 uint8_t packet[] = {0xF5, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x04, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17};
 Serial2.write(packet, sizeof(packet));
 
 if (waitForResponse(0x00)) {
   uint32_t capacity = ((uint32_t)response[11] << 24) | ((uint32_t)response[12] << 16) | ((uint32_t)response[13] << 8) | response[14];
   uint16_t baud_rate = ((uint16_t)response[15] << 8) | response[16];
   uint16_t security_level = ((uint16_t)response[17] << 8) | response[18];
   uint32_t device_addr = ((uint32_t)response[19] << 24) | ((uint32_t)response[20] << 16) | ((uint32_t)response[21] << 8) | response[22];
   uint16_t packet_len = ((uint16_t)response[23] << 8) | response[24];
   
   Serial.print("Capacity: "); Serial.println(capacity);
   Serial.print("Baud rate: "); Serial.println(baud_rate);
   Serial.print("Security level: "); Serial.println(security_level);
   Serial.print("Device address: 0x"); Serial.println(device_addr, HEX);
   Serial.print("Packet length: "); Serial.println(packet_len);
 }
}

bool waitForResponse(uint8_t responseCode) {
 uint32_t startTime = millis();
 while (Serial2.available() < 9) {
   if (millis() - startTime > 1000) {
     Serial.println("Timeout");
     return false;
   }
 }
 
 Serial2.readBytes(response, 9);
 
 if (response[0] != 0xF5 || response[1] != 0x00 || response[8] != responseCode) {
   Serial.println("Received bad data from fingerprint sensor");
   return false;
 }
 
 return true;
}

The verifyPassword() function in the library looks like this

verifyPassword(void) {
  return checkPassword() == FINGERPRINT_OK;
}

which is nothing like yours, so you did not copy it from the library as far as I can see

based on library i try to build a fuction in a procedural way

So when you said

you really meant that you want to write completely new functions. Why is that ?

i want to have a function that send and 1 function that reads data from sensor.

coz i have some commands that adafruit dont have, and i need just 2 commands and dont want to include all library to my code

If you #include a library in your sketch but don't use all of the library functions then the unused ones are not compiled into your sketch

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.