UART is a hardware communication protocol that is used to transfer data between two devices via only two wires. One wire is for transmitting data (Tx) and another for receiving (RX). It is asynchronous, as it has no clock signal wire like other protocols (i.e., I2C, SPI)
For UART, the baud rate needs to be set the same on both the transmitting and receiving devices for successful communication. The baud rate is the rate at which information is transferred to a communication channel. In our case, the sensor can be set to run at different baud rates, but the default is 115200.
We can thus capture the signals at a 115200 baud rate. that are being transmitted via the RX, TX lines, and find out what is being transferred and received during an operation. The TX pin of the sensor sends data to the computer, and vice versa.
To learn more about UART communication, check out this link from Analog Devices: LINK
Connect the Sensor With the ComputerTo trap the communication, I used a USB to TTL by Reyax technology, module set at 3.3V and the software that comes with the sensor. This way, the sensor can directly send and receive data to the computer via serial communication (this is required by the Chinese software)
The connections are:
Sensor ---> USB-to-TTL
- 3V3 ---> 3.3V
- TX ---> RX
- RX ---> TX
- GND ---> GND
- VIN ---> 3.3V
The VIN button is connected to keep the sensor awake; otherwise, it will move to sleep mode.
After connecting the sensor, we will set up the software that comes with the sensor and perform some basic tasks in the next steps.
Using the "Chinese" Software for testingThe software is very neat, connects to the sensor easily, and has a lot of features.
Just select the proper COM port, set the baud rate to 115200, and hit connect. If the connection is not successful, an error prompt will appear. Check the connection and COM port.
I have added several images above to show how to use the software. Some useful notes:
- To enroll a new finger, select a unique ID. To find the stored IDs, press the "Get Enrolled ID list" button.
- Use a minimum of 2 enroll count while enrolling a new finger for reliable detection.
- Enabling the 'show image' takes a significantly longer time to process each fingerprint.
- An error while connecting with the sensor usually means the wrong COM port was selected.
Software link: LINK
Using the Logic Analyzer to CaptureI used a cheap Saleae logic analyzer to record the data transmission at a baud rate of 115200. The Logic software provides useful options to directly analyze and visualize data in formats like bin, hex, decimal, etc.
Software link: https://saleae.com/downloads
Connections:
Analyzer ---> Sensor
- CH1 ---> RX
- CH2 ---> TX
The logic analyzer does not require a ground connection, as the analyzer, sensor, and USB-to-TTL are all connected to the same computer. This connection allows us to see what the software is sending (white graph) and what the sensor is sending (brown graph) simultaneously.
To use the Logic software:
- Open the software.
- Connect the logic analyzer using USB port.
- From the device settings, set the speed to around 200 kS/s (200 kilo Samples per second)
- Press "R" to start recording the capture. You will see the graph update when you use the fingerprint software.
To analyze data, we need to know that the sensor takes in 26 packets of data from the software at a baud rate of 115200, 8 bits per transfer, 1-stop bit, no parity bit, and the least significant bit is sent first. Don't worry, these are usually default parameters in all commercial devices :). but these info are useful while analyzing data from the Saleae software, as shown in the second last picture above.
Analyzing and Writing Python ScriptsAnalyzing the data was not an easy task. Let's look at an example of enrolling a fingerprint. The first image above shows the whole communication that takes place between the software and the sensor. Each of these lines contains 26 packets of data. These packets are what we need!
I carefully wrote the whole data transmission byte by byte at every point of the enrollment process, and finally came up with 25 different packets of data. I fed this info to AI and asked it to write code to replicate this data.
The enrollment process is probably the hardest, and it works as follows:
- Begin enrollment ID: 0x46
- Get Finger Image ID: 0x20
- Get finger present/released ID:0x21
- Generate template into buffer ID:0x60
- Merge templates ID:0x61
- Save templates ID:0x40
- End transmission ID:0x24
In this same way, I captured and noted the other basic operations of the fingerprint sensor and used AI to generate code snippets.
Finally the Python ScriptsIn all the scripts:
- It defines the library, port, begins serial communication, and sets the baud rates.
- Defines a function "cmd" that generates the 26 packet of data with a given command.
- The 'cmd' function can also wait and receive the sensor data.
- After each data transmission prints relevant information.
Find the attached codes from the code section of this article.
You can find details about this code from my GitHub: LINK




Comments