0

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()
4
  • which part of the code prevents the fingerprint reader from working? Commented Feb 27 at 17:44
  • 2
    how is everything connected? ... please add a wiring diagram and a clear, well lit picture of the wiring Commented Feb 27 at 17:45
  • Two things: 1. Have you tried a search?; 2. This sounds like something that would use the device tree; have you looked in /boot/firmware/overlays/README?? Commented Feb 27 at 23:30
  • I’m not sure what’s preventing it from working. They work individually. Or, they work two at at a time, i.e the rfid and PIN works together, or the PIN and fingerprint sensor works together. But as soon as I try to run all three, I get a sensor error from the fingerprint thing. Once this happens, the fingerprint sensor won’t even run a minimal loop test until I reboot the pi. I don’t have a wiring diagram. I have just been working it out as I go. I’m no expert In this. I can send a picture though. But I had better wait for day time for the best light. Commented Feb 28 at 18:35

1 Answer 1

0

The DollaTek (and R307) fingerprint scanners can draw more current than the Raspberry Pi's GPIO can provide. I suggest you use an external 5V power supply instead of powering it from the Pi. Also check if you have enabled the serial port. Run the command

sudo raspi-config

Go to Interfacing Options > Serial. Disable login shell access. Enable serial port hardware.

Check available serial ports:

ls -l /dev/serial*

If /dev/serial0 points to /dev/ttyS0 instead of /dev/ttyAMA0, then the correct one might not be in use. I hope that checking and solving these matters will allow the sensor to communicate with your Raspberry Pi. In case you want to make a PCB, you can get some idea about the cost from here: https://www.allpcb.com/blog/pcb-ordering/pcb-cost-per-unit.html

2
  • Please forgive my stupidity - but how do I add an external power source to the sensor? Right now it’s obviously wired to the Pi and drawing power from that. So how do I add extra power to the sensor alone? Commented Mar 7 at 11:50
  • There should be a separate dedicated power supply for the sensor. The power supply's + and - should be connected to the VCC and GND of the sensor respectively. The GND of the sensor and the GND of the Raspberry pi should be shorted together. Commented Mar 21 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.