{"id":3328,"date":"2025-02-15T04:38:39","date_gmt":"2025-02-15T04:38:39","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=3328"},"modified":"2025-02-15T06:05:44","modified_gmt":"2025-02-15T06:05:44","slug":"uart-fingerprint-locker","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=3328","title":{"rendered":"UART : Fingerprint Locker"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-1 wp-block-paragraph\" style=\"color:#5c5c5c\">The universal synchronous asynchronous receiver transmitter (USART) offers a flexible means of Full-duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format. The USART offers a very wide range of baud rates using a programmable baud rate generator.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-2 wp-block-paragraph\" style=\"color:#5c5c5c\">It supports synchronous one-way communication and Half-duplex Single-wire communication, as well as multiprocessor communications. It also supports the LIN (Local Interconnect Network), Smartcard protocol and IrDA (Infrared Data Association) SIR ENDEC specifications and Modem operations (CTS\/RTS). High speed data communication is possible by using the DMA (direct memory access) for multi-buffer configuration. For the basic USART function please read my \ud83d\udc49 <a href=\"https:\/\/iotthinghub.com\/?p=2311\">ATmel section<\/a>. STm32 offer its own Hal library for fully control UASRT protocol. Some basic library as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nHAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout);\nHAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);\nHAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);\nHAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);\nHAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);\nHAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);\nHAL_UART_DMAPause(UART_HandleTypeDef *huart);\nHAL_UART_DMAResume(UART_HandleTypeDef *huart);\nHAL_UART_DMAStop(UART_HandleTypeDef *huart);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-3 wp-block-paragraph\" style=\"color:#5c5c5c\">In this article we will make a fingerprint lock system for squire entry. Please go through my \ud83d\udc49 <a href=\"https:\/\/iotthinghub.com\/?p=2416\"><strong>R307 Fingerprint module article<\/strong><\/a> in ATmel section. For fingerprint sensor I use AS608 biometric sensor works similar as R307 module.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"787\" height=\"388\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/AS608.jpg\" alt=\"\" class=\"wp-image-3338\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/AS608.jpg 787w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/AS608-300x148.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/AS608-768x379.jpg 768w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img decoding=\"async\" width=\"670\" height=\"414\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/pinout-AS608.jpg\" alt=\"\" class=\"wp-image-3341\" style=\"width:316px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/pinout-AS608.jpg 670w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2025\/02\/pinout-AS608-300x185.jpg 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-4 wp-block-paragraph\" style=\"color:#5c5c5c\">It has baud rate range from 9600~57600, but default baud rate is 57600. Both for transmission &amp; receive needs more purity, so we use interrupt function for both Rx &amp; Tx. Initialize USART with 8bit, 1 stop bit &amp; none parity bit with global interrupt enable. For display purpose we use OLED display. We use RTC for time &amp; date. In our while loop we normally wait for any finger placed on biometric sensor. If any finger place on the sensor it will search in the library. If finger found in the library it will display a pass logo to the OLED and a GPIO pin will active for 1min to turn the relay. If finger not found in the library it will display a logo of not recognized &amp; back to the search again. The delay time is 6s for recognition a finger.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-5 wp-block-paragraph\" style=\"color:#5c5c5c\">At first we have to enroll finger and give a ID to that finger. For this purpose let\u2019s use 3 GPIO pin. The setting will be 2:2:2 for access the function.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n#define SELECTION      HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)\n#define ARROW_UP       HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1)\n#define ARROW_DOWN     HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2)\nuint8_t digit_1,digit_2,digit_3\n\nif(!SELECTION){ digit_1++; HAL_Delay(1); if(digit_1==10) digit_1=0;}\nif(!ARROW_UP &amp;&amp; digit_1==2) {digit_2++; HAL_Delay(1);if(digit_2==10) digit_2=0;}\nif(!ARROW_DOWN &amp;&amp; digit_1==2 &amp;&amp; digit_2==2){digit_3++; HAL_Delay(1);if(digit_3==10) digit_3=0;}\nsprintf(display_time,&quot;Setting %d:%d:%d  &quot;,digit_1,digit_2,digit_3);\nOLCD_write_string(7,0,display_time);\n    if(digit_3==2){\n\t\t\tsetting_bit=1;digit_1=0;digit_2=0;digit_3=0;\n\t\t\tOLCD_write_string(7,0,&quot;S. M. Activate  &quot;);\n\t\t\tselectFunc();\n\t\t     }\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-6 wp-block-paragraph\" style=\"color:#5c5c5c\">Here we use GPIOA pin 0,1,2 for setting parameter. When we enter setting those pin are also use for<\/p>\n\n\n\n<ul style=\"color:#252525\" class=\"wp-block-list has-text-color has-link-color wp-elements-7\">\n<li>Selection Function. i.e. Enroll function, Delete\/Enter ID number or Empty library<\/li>\n\n\n\n<li>ARROW up for ID number increment or function selection<\/li>\n\n\n\n<li>ARROW down for ID number decrease or function selection<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n#define ENROLL         1\n#define DELETE_ID      2\n#define EMPETY_FP_LIB  3\nvoid selectFunc(void)\n{\n\tOLCD_write_string(6,0,&quot;Select &lt;- -&gt;  &quot;);\n\tHAL_Delay(100);\nwhile(SELECTION) \/\/ Pin for selection finger\n\t{\n\tif(!ARROW_UP) \/\/ For Up Arrow\n\t   {\n\t\t\tscan++;\n\t\t\tHAL_Delay(200);\n\t\t\tif(scan&gt;=4) scan=1;\n\t\t\tswitch(scan)\n\t\t  {\n\t\t\tcase ENROLL: OLCD_write_string(7,0,&quot;ENROLL UR FINGER&quot;);\n\t\t\tbreak;\n\t\t\tcase DELETE_ID: OLCD_write_string(7,0,&quot;DELETE ID NO    &quot;);\n\t\t\tbreak;\n\t\t\tcase EMPETY_FP_LIB: OLCD_write_string(7,0,&quot;EMPTY LIBRARY   &quot;);\n\t\t\tbreak;\n\t\t  }\n\t   }\n\telse if(!ARROW_DOWN)\n\t   {\n\t\t\tscan--;\n\t\t\tHAL_Delay(200);\n\t\t\tif(scan==0) scan=3;\n\t\t\tswitch(scan)\n\t\t  {\n\t\t\tcase ENROLL: OLCD_write_string(7,0,&quot;ENROLL UR FINGER&quot;);\n\t\t\tbreak;\n\t\t\tcase DELETE_ID: OLCD_write_string(7,0,&quot;DELETE ID NO    &quot;);\n\t\t\tbreak;\n\t\t\tcase EMPETY_FP_LIB: OLCD_write_string(7,0,&quot;EMPTY LIBRARY   &quot;);\n\t\t\tbreak;\n\t\t  }\n\t   }\n\t}\nHAL_Delay(200);\nswitch(scan)\n{\n\tcase ENROLL: enroll();\n\tbreak;\n\tcase DELETE_ID: sendcmd2fp(FP_delete);\n\tbreak;\n\tcase EMPETY_FP_LIB: sendcmd2fp(FP_empty);\n\tbreak;\n}\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-8 wp-block-paragraph\" style=\"color:#5c5c5c\">R307 Fingerprint module article describes how to create those libraries.\u00a0 Example, let\u2019s make a function to verify if the sensor connected or not.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nconst char fp_VfyPwd_Tx&#x5B;16]={0xEF, 0x1,0xFF, 0xFF, 0xFF, 0xFF,0x1, 0x00,0x7, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B };\nchar recive&#x5B;20], rx_char, arr_size;\nHAL_UART_Receive_IT(&amp;huart1,&amp;rx_char,1);\n\twhile(1)\n\t{\n\t  OLCD_write_string(0,0,&quot;Searching...  &quot;);\n\t  arr_size = (sizeof(fp_VfyPwd_Tx)) \/ sizeof((fp_VfyPwd_Tx)&#x5B;0]);\n      HAL_UART_Transmit_IT(&amp;huart1,&amp;fp_VfyPwd_Tx,arr_size);\n\t  HAL_Delay(1000);\n\t  if(recive&#x5B;9]) OLCD_write_string(0,0,&quot;Connect Device&quot;); \/\/ Device not connected\n\t  else   {\n\t\t\tOLCD_write_string(0,0,&quot;Device Found&quot;);\n\t\t\tHAL_Delay(2000);\n\t\t\tclear_display();\n\t\t\tlogo_write(1); \/\/ Finger Print Sensor Logo\n\t\t\tHAL_Delay(5000);\n\t\t\tclear_display();\n\t\t\tbreak;\n\t\t}\n\t}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-9 wp-block-paragraph\" style=\"color:#5c5c5c\">In return function we have-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nextern UART_HandleTypeDef huart1; \nvoid HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)\n{\n  if(huart-&gt;Instance==USART1 )\n  {\n    recive&#x5B;cont++]=rx_char;\n    HAL_UART_Receive_IT(&amp;huart1,&amp;rx_char,1);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-10 wp-block-paragraph\" style=\"color:#5c5c5c\">Here we display a logo in OLED. Display a logo in OLED is to just send a data stream to OLED. Please see my \ud83d\udc49 <a href=\"https:\/\/iotthinghub.com\/?p=2277\"><strong>OLED (SSD1306) interface<\/strong><\/a> article in ATmel section for more information about OLED. To interface any STm32 please see the video tutorial, it will also help you to know about configuration, different header file interface. Since it is a long program we can\u2019t cover in a single article, but the basic was explained here.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"STM32 UART : \ud83e\udec6 Fingerprint Locker \ud83e\udeaa R307\/AS608 Fingerprint Module\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/mTWjk-yidfQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The universal synchronous asynchronous receiver transmitter (USART) offers a flexible means of Full-duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format. The USART offers a very wide range of baud rates using a programmable baud rate generator. It supports synchronous one-way communication and Half-duplex Single-wire communication, as well as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-3328","post","type-post","status-publish","format-standard","hentry","category-stm-arm-tutorials"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/3328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3328"}],"version-history":[{"count":23,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/3328\/revisions"}],"predecessor-version":[{"id":3362,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/3328\/revisions\/3362"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}