{"id":2754,"date":"2024-08-17T09:06:17","date_gmt":"2024-08-17T09:06:17","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=2754"},"modified":"2024-08-17T11:33:36","modified_gmt":"2024-08-17T11:33:36","slug":"display-control-lcd-i2c","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=2754","title":{"rendered":"Display Control LCD (I2C)"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-c12d8c8893f0770373feb3eae26114b5 wp-block-paragraph\" style=\"color:#5c5c5c\">We already learn LCD interfacing in previous article. LCD Display requires lots of digital I\/O pin and the circuit requires more space. In market I<sup>2<\/sup>C LCD display are available and the interfacing is not so difficult. You just need to know the hardware interface and the I<sup>2<\/sup>C IC which is connected with that LCD. Usually in maximum I<sup>2<\/sup>C LCD module use PFC8574A or PFC8574. Both the device has different I<sup>2<\/sup>C address. Let\u2019s first look at the internal connection and the changes that need to be changed.<\/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=\"738\" height=\"359\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-Device.jpg\" alt=\"\" class=\"wp-image-2755\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-Device.jpg 738w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-Device-300x146.jpg 300w\" sizes=\"(max-width: 738px) 100vw, 738px\" \/><\/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 size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/PCF8574-LCD-Driver-1024x640.jpg\" alt=\"\" class=\"wp-image-2756\" style=\"width:398px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/PCF8574-LCD-Driver-1024x640.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/PCF8574-LCD-Driver-300x187.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/PCF8574-LCD-Driver-768x480.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/PCF8574-LCD-Driver-1536x959.jpg 1536w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/PCF8574-LCD-Driver.jpg 1641w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-743289995a0a083eb3247f2e26c5a75f wp-block-paragraph\" style=\"color:#5c5c5c\">Now it\u2019s time to interface the module with STM32 HAL I<sup>2<\/sup>C library. First enable the I<sup>2<\/sup>C feature. It automatically call the default settings, you don\u2019t need to change any parameters.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img decoding=\"async\" width=\"944\" height=\"612\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-4.jpg\" alt=\"\" class=\"wp-image-2759\" style=\"width:634px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-4.jpg 944w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-4-300x194.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/function-4-768x498.jpg 768w\" sizes=\"(max-width: 944px) 100vw, 944px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-6d38b73315720434ef03f3207b5b1be8 wp-block-paragraph\" style=\"color:#5c5c5c\">The generated HAL I<sup>2<\/sup>C library has different functions. Like-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nHAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);\nHAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);\nHAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);\nHAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);\nHAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);\nHAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size);\n\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-eac921c39e176a632e58e966329a7107 wp-block-paragraph\" style=\"color:#5c5c5c\">Since we just transmit data to the I<sup>2<\/sup>C LCD driver, we just deal with one function-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nHAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-32145aee6b9c23e5cfd28f9b267db7f0 wp-block-paragraph\" style=\"color:#5c5c5c\">Here, hi2c is hi2c1 or hi2c2<\/p>\n\n\n\n<ul style=\"color:#5c5c5c\" class=\"wp-block-list has-text-color has-link-color wp-elements-b4cb3ef05d7b102fb7f650bd398e1ea5\">\n<li>DevAddress is the 7 bit physical address + 1 bit R\/W<\/li>\n\n\n\n<li>pData pointer to data buffer<\/li>\n\n\n\n<li>Size amount of data to be sent<\/li>\n\n\n\n<li>Timeout Timeout duration<\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-46beee2ded265e6840af11b682e8dc63 wp-block-paragraph\" style=\"color:#5c5c5c\">All the user function that we developed in previous article remain same expect 2 functions.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-a9a6c98a4993a9ec3605bac360471d23 wp-block-paragraph\" style=\"color:#5c5c5c\">LCD command write 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  Address 0x27  \/\/ if PCF8574   \n  \/\/#define  Address 0x3F  \/\/ if PCF8574A\nvoid LCD_cmd(unsigned char cmd)\n {\n    unsigned char data&#x5B;3];\n\tdata&#x5B;0]=cmd;\n\tdata&#x5B;1]=cmd|0b00001100; \/\/ EN = 1 and Backlight ON(Pin \u2013P3)\n    HAL_I2C_Master_Transmit(&amp;hi2cx,(Address&lt;&lt;1)|0,data,2,100); \/\/ x is 1\/2 etc\n\tHAL_Delay(2);\n\tdata&#x5B;0]=cmd|0b00001000; \/\/EN = 0 and Backlight ON\n    HAL_I2C_Master_Transmit(&amp;hi2cx,(Address&lt;&lt;1)|0,data,1,100); \/\/ x is 1\/2 etc\n} \n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-069567142383bf1526acc8d306bd5c84 wp-block-paragraph\" style=\"color:#5c5c5c\">LCD character write function-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvoid LCD_write(unsigned char data)\n {\n    unsigned char display&#x5B;3];\n\tdisplay&#x5B;0]=data;\n\tdisplay&#x5B;1]=data|0b00001101; \/\/ EN = 1, R\/S=1 and Backlight ON\n    HAL_I2C_Master_Transmit(&amp;hi2cx,(Address&lt;&lt;1)|0,display,2,100); \/\/ x is 1\/2 etc\n\tHAL_Delay(2);\n\tdisplay&#x5B;0]=data|0b00001001; \/\/ EN = 0, R\/S=1 and Backlight ON\n    HAL_I2C_Master_Transmit(&amp;hi2cx,(Address&lt;&lt;1)|0,display,1,100); \/\/ x is 1\/2 etc\n }\n\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-fb96c30cb4fc63af2d408245136e7e8e wp-block-paragraph\" style=\"color:#5c5c5c\">If you are using I<sup>2<\/sup>C1 or I<sup>2<\/sup>C2 please use the following external variable otherwise error occour-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nextern I2C_HandleTypeDef hi2c1; or extern I2C_HandleTypeDef hi2c2;\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-dba19b2ea9909b72ed340965a03a4d0e wp-block-paragraph\" style=\"color:#5c5c5c\">The main program while(1) function remain the same 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=\"\">\n        LCD_write_custom(1,1,0);\n\t\tLCD_write_custom(2,1,1);\n\t\tLCD_write_custom(2,2,2);\n\t\tLCD_write_custom(1,2,4);\n\t\tLCD_write_custom(5,2,3);\n\t\tLCD_write_string(6,2,&quot;IoTthingHuB&quot;);\n\t\tLCD_write_string(5,1,&quot;        www&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;       www.&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;      www.i&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;     www.io&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;    www.iot&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;   www.iott&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;  www.iotth&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot; www.iotthi&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;www.iotthin&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;ww.iotthing&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;w.iotthingh&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;.iotthinghu&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;iotthinghub&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;otthinghub.&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;tthinghub.c&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;thinghub.co&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;hinghub.com&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;inghub.com &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;nghub.com  &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;ghub.com   &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;hub.com    &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;ub.com     &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;b.com      &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;.com       &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;com        &quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;om        w&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;m        ww&quot;);HAL_Delay(500);\n\t\tLCD_write_string(5,1,&quot;        www&quot;);HAL_Delay(500);\n\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-c17ab12e256b1c48108bad26f9647d4f wp-block-paragraph\" style=\"color:#5c5c5c\">For display custom character into LCD display please the Build your own custom character article.<\/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<p class=\"has-text-color has-link-color wp-elements-a899f6278c85968b68fd9141db1781f5 wp-block-paragraph\" style=\"color:#5c5c5c\"><strong>After connect LCD with STmicrocontroller sometime the LCD display shown no contents, in this case vary the variable resistance slowly until the display show characters. The contract adjust is very essential in LCD display so care should be taken. Some time the display may hang reset the mcu then try.<\/strong><\/p>\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 size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"269\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-LCD-connection.jpg\" alt=\"\" class=\"wp-image-2781\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-LCD-connection.jpg 786w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-LCD-connection-300x103.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-LCD-connection-768x263.jpg 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure>\n<\/div>\n<\/div>\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\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-LCD-STM32F0308.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--50)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/I2C-LCD-STM32F0308.rar\">I2C LCD STM32F0308.rar<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We already learn LCD interfacing in previous article. LCD Display requires lots of digital I\/O pin and the circuit requires more space. In market I2C LCD display are available and the interfacing is not so difficult. You just need to know the hardware interface and the I2C IC which is connected with that LCD. Usually [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-2754","post","type-post","status-publish","format-standard","hentry","category-arm-standards-peripherals"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2754","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=2754"}],"version-history":[{"count":17,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2754\/revisions"}],"predecessor-version":[{"id":2786,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2754\/revisions\/2786"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}