{"id":2789,"date":"2024-09-06T11:41:54","date_gmt":"2024-09-06T11:41:54","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=2789"},"modified":"2024-09-13T17:19:06","modified_gmt":"2024-09-13T17:19:06","slug":"oled-with-stm32","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=2789","title":{"rendered":"OLED with STM32"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-f2a07cbd8e105aeff2a2de0710926dbb wp-block-paragraph\" style=\"color:#5c5c5c\">Before interface OLED with STM32 microcontroller please go through my OLED section in <a href=\"https:\/\/iotthinghub.com\/?p=2277\" data-type=\"page\" data-id=\"25\" target=\"_blank\" rel=\"noreferrer noopener\">OLED (SSD1306) interfacing<\/a>. In this article we interface the low cost 0.91 Inch small OLED. In our previous article we discuss about I<sup>2<\/sup>C protocol and I<sup>2<\/sup>C LCD driver. STmcu works on 3.3V &amp; I<sup>2<\/sup>C LCD works 5V so need DC power level shifter. OLED perfectly works on 3.3V, this is one major advantage of using OLED.<\/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 aligncenter size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"986\" height=\"729\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-I2C-Setting.jpg\" alt=\"\" class=\"wp-image-2798\" style=\"width:365px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-I2C-Setting.jpg 986w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-I2C-Setting-300x222.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-I2C-Setting-768x568.jpg 768w\" sizes=\"(max-width: 986px) 100vw, 986px\" \/><\/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-full\"><img decoding=\"async\" width=\"772\" height=\"266\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/91Inch-OLED-STM32.jpg\" alt=\"\" class=\"wp-image-2801\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/91Inch-OLED-STM32.jpg 772w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/91Inch-OLED-STM32-300x103.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/91Inch-OLED-STM32-768x265.jpg 768w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">OLED device address: 0x3C &nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For command mode value is 0x80 and for data mode value is 0x40. The user function as follow-<\/p>\n<\/div>\n<\/div>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nuint8_t data_stream&#x5B;3];\nextern I2C_HandleTypeDef hi2c2; \/\/I2C definition\nvoid sendcommand(uint8_t com){\ndata_stream&#x5B;0]=OLED_COMMAND;\ndata_stream&#x5B;1]=com;\nHAL_I2C_Master_Transmit(&amp;hi2c2,SLAVE_ADDR_ACC&lt;&lt;1,data_stream,2,100); \n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvoid SendChar(uint8_t data){\ndata_stream&#x5B;0]=OLED_DATA;\ndata_stream&#x5B;1]=data\nHAL_I2C_Master_Transmit(&amp;hi2c2,SLAVE_ADDR_ACC&lt;&lt;1,data_stream,2,100);  \n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-50beb826724988f193719497fc3fb948 wp-block-paragraph\" style=\"color:#5c5c5c\">Here we used hi2c2 for I<sup>2<\/sup>C number 2. Change I<sup>2<\/sup>C according to your desire. The pixel location function remain the same as-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvoid setXY(unsigned char row, unsigned char col)\n{\n  sendcommand(0xb0+row);                \/\/set page address\n  sendcommand(0x00+(8*col&amp;0x0f));       \/\/set low col address\n  sendcommand(0x10+((8*col&gt;&gt;4)&amp;0x0f));  \/\/set high col address\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-333a8ddde9b690037c01c499f8e0ea7f wp-block-paragraph\" style=\"color:#5c5c5c\">Since the display is very small and to visualized the front we use 2 pages to display a single character. For example writing \u2018B\u2019 will be-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n{0x0,0xfc,0xfc,0x8c,0x8c,0xfc,0x78,0x0,0x0,0x3f,0x3f,0x31,0x31,0x3f,0x1e,0x0}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-1391458c2f199584247bd78d33a0b0d0 wp-block-paragraph\" style=\"color:#5c5c5c\">So same changes in the void OLCD_write_string(int X, int Y, char *string) function 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=\"\">\nconst char ASCCI&#x5B;]&#x5B;16]= {0x0,0xfc,0xfc,0x8c,0x8c,0xfc,0x78,0x0,0x0,0x3f,0x3f,0x31,0x31,0x3f,0x1e,0x0};\nvoid OLCD_write_string(int X, int Y, char *string)\n{\n  uint8_t position=0;\n  while(*string)\n  {\n    setXY(X,Y+position);\n    for(uint8_t j=0;j&lt;8;j++)\n    SendChar((char)ASCCI&#x5B;*string-0x20]&#x5B;j]);\n    setXY(X+1,Y+position);\n    for(uint8_t j=8;j&lt;16;j++)\n    SendChar((char)ASCCI&#x5B;*string-0x20]&#x5B;j]);\n    *string++;\n    position++;\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color wp-elements-d7d3295e83ca1a49d1957ae0884b0c9b wp-block-paragraph\" style=\"color:#5c5c5c\">Let\u2019s start with OLED with initializing with the following command and after initialize the OLED clear all the pixels by sending 0 to the pixel.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\nvolatile uint8_t OLED_init&#x5B;] = {0xAE,0xA6,0xAE,0xD5,0x80,0xA8,0x3F,0xD3,0x00,0x40,0x8D,0x14,0x20,0x00,0xA1,0xC8,0xDA,0x12,0x81,0xCF,0xD9,0xF1,0xDB,0x40,0xA4,0xA6,0x2E,0x20,0x00,0xAF};\nvoid init_OLED(void)\n{\n\tfor(char i=0;i&lt;=sizeof(OLED_init);i++)\n\tsendcommand(OLED_init&#x5B;i]);\n}\n<\/pre><\/div>\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-36d1d59c31d80f08caa375546b8d4b21 wp-block-paragraph\" style=\"color:#5c5c5c\">Download the driver file and let\u2019s start with OLED.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\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 has-custom-font-size has-small-font-size\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-Driver.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)\">.91&#8243; OLED Driver<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/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=\"STM OLED\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/nPNSFh1DiHA?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\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<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 has-custom-font-size has-small-font-size\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-STM32F0308CC.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\">\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-7f7f2caa3e7f2f5a37b76b199e2ed2db wp-block-paragraph\" style=\"color:#252525\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/09\/OLED-STM32F0308CC.rar\">OLED STM32F0308CC.rar<\/a><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before interface OLED with STM32 microcontroller please go through my OLED section in OLED (SSD1306) interfacing. In this article we interface the low cost 0.91 Inch small OLED. In our previous article we discuss about I2C protocol and I2C LCD driver. STmcu works on 3.3V &amp; I2C LCD works 5V so need DC power level [&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-2789","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\/2789","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=2789"}],"version-history":[{"count":20,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2789\/revisions"}],"predecessor-version":[{"id":2946,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/2789\/revisions\/2946"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}