Hoping someone can help. I am currently doing a school project using a raspberry pi to allow RFID scanning, then a PIN entry then finally a fingerprint scanner, all fetched from an SQLite database. Eventually it will open a door lock, but for now, I’m just working on the code. But I can’t get the fingerprint scanner to work.
The rfid and PIN works fine. Used the database. Access is granted if correct credentials.
Once I try to add the fingerprint scanner, it’s just doesn’t work. The fingerprint scanner works on its own (outwith the project). I have enrolled several prints. But the moment I try it within the larger code, it states the sensor is not being read. Then even to go back to a simple loop test for the sensor, I have to reboot the pi before it works again.
I’m not sure what I’m doing wrong. I have double checked the correct serial port is in use. Bluetooth is disabled. I’m just lost.
It’s a DollaTek blue fingerprint optical reader I’m using. I also have a R307(similar) but had the same problem. Does it need an additional power source maybe? Any help appreciated.
Code so far (that keeps crashing the sensor):
import RPi.GPIO as GPIO
import time
import i2c_lcd
import sqlite3
import adafruit_fingerprint
import serial
# Define Keypad Pins
ROWS = [5, 6, 13, 19]
COLS = [12, 16, 20, 21]
KEYS = [
['1', '2', '3', 'A'],
['4', '5', '6', 'B'],
['7', '8', '9', 'C'],
['*', '0', '#', 'D']
]
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for row in ROWS:
GPIO.setup(row, GPIO.OUT)
GPIO.output(row, GPIO.HIGH)
for col in COLS:
GPIO.setup(col, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Initialize LCD - Check I2C address (0x27 or 0x3F)
lcd = i2c_lcd.lcd()
# Initialize Fingerprint Sensor
uart = serial.Serial("/dev/serial0", baudrate=57600, timeout=1)
fingerprint = adafruit_fingerprint.Adafruit_Fingerprint(uart)
def read_keypad():
""" Reads the pressed key from the keypad """
for row_index, row in enumerate(ROWS):
GPIO.output(row, GPIO.LOW)
for col_index, col in enumerate(COLS):
if GPIO.input(col) == 0:
time.sleep(0.1) # Debounce
while GPIO.input(col) == 0:
pass # Wait until key is released
GPIO.output(row, GPIO.HIGH)
return KEYS[row_index][col_index]
GPIO.output(row, GPIO.HIGH)
return None
def get_user_from_db(user_pin):
"""Retrieve user information from the database using the PIN"""
try:
conn = sqlite3.connect('users.db')
cursor = conn.cursor()
cursor.execute("SELECT name, fingerprint_id FROM users WHERE pin = ?", (user_pin,))
result = cursor.fetchone()
conn.close()
return result if result else None
except Exception as e:
print(f"Database error: {e}")
return None
def verify_fingerprint(fingerprint_id):
"""Checks if the fingerprint matches the stored ID"""
print("Waiting for fingerprint...")
lcd.lcd_display_string("Place Finger...", 1)
while fingerprint.get_image() != adafruit_fingerprint.OK:
pass # Keep waiting for a valid fingerprint scan
if fingerprint.image_2_tz(1) != adafruit_fingerprint.OK:
return False
if fingerprint.finger_search() != adafruit_fingerprint.OK:
return False
return fingerprint.finger_id == fingerprint_id
try:
while True:
lcd.lcd_clear()
lcd.lcd_display_string("Enter PIN:", 1)
entered_pin = ""
while len(entered_pin) < 4:
key = read_keypad()
if key:
if key.isdigit():
entered_pin += key
lcd.lcd_display_string("*" * len(entered_pin), 2)
time.sleep(0.3)
user = get_user_from_db(entered_pin)
if user:
user_name, fingerprint_id = user
lcd.lcd_clear()
lcd.lcd_display_string(f"Hello, {user_name}!", 1)
time.sleep(2)
lcd.lcd_clear()
lcd.lcd_display_string("Scan Fingerprint", 1)
if verify_fingerprint(fingerprint_id):
lcd.lcd_display_string("Access Granted", 1)
else:
lcd.lcd_display_string("Fingerprint Error", 1)
else:
lcd.lcd_display_string("Invalid PIN", 1)
time.sleep(2)
except KeyboardInterrupt:
GPIO.cleanup()
lcd.lcd_clear()
/boot/firmware/overlays/README??