{"id":3057,"date":"2020-03-01T22:54:27","date_gmt":"2020-03-01T13:54:27","guid":{"rendered":"https:\/\/programresource.net\/?p=3057"},"modified":"2020-03-01T22:54:30","modified_gmt":"2020-03-01T13:54:30","slug":"show-qr-code-on-oled-display-with-arduino","status":"publish","type":"post","link":"https:\/\/programresource.net\/en\/2020\/03\/01\/3057.html","title":{"rendered":"Show QR code on OLED display with Arduino"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/programresource.net\/images\/2020\/03\/P_20200301_223035_vHDR_Auto-1024x578.jpg\" alt=\"\" class=\"wp-image-3054\" srcset=\"https:\/\/programresource.net\/images\/2020\/03\/P_20200301_223035_vHDR_Auto-1024x578.jpg 1024w, https:\/\/programresource.net\/images\/2020\/03\/P_20200301_223035_vHDR_Auto-300x169.jpg 300w, https:\/\/programresource.net\/images\/2020\/03\/P_20200301_223035_vHDR_Auto-768x433.jpg 768w, https:\/\/programresource.net\/images\/2020\/03\/P_20200301_223035_vHDR_Auto.jpg 1381w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>There&#8217;s QR code library for Arduino released 3 years ago.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/ricmoo\/qrcode\/\">https:\/\/github.com\/ricmoo\/qrcode\/<\/a><\/p>\n\n\n\n<p>Well made library, works with less memory of Arduino while supporting QR code versions and error correction levels.<\/p>\n\n\n\n<p>You can easily create QR code data with above library and show code to OLED display with u8glib library.<\/p>\n\n\n\n<p>Below is sample sketch for showing QR code with &#8220;https:\/\/programresource.net&#8221; text data to OLED display, with inverted B\/W on left \/ right half of screen. Very short and simple sketch which does amazing work.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n#include &quot;qrcode.h&quot; \/\/https:\/\/github.com\/ricmoo\/qrcode\/\n#include &quot;U8glib.h&quot;\n\nU8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);   \/\/ I2C \/ TWI\n\nvoid display_qrcode(char *text) {\t\n\tQRCode qrcode;\n\tuint8_t qrcodeData&#91;qrcode_getBufferSize(4)]; \/\/Version 4 114 byte 33x33 res QR code\n\tqrcode_initText(&amp;qrcode, qrcodeData, 4, ECC_LOW, text);\n\n\tu8g.firstPage();\n\tdo {\n\t\tu8g.setColorIndex(0);\n\t\tu8g.drawBox(0, 0, 64, 64);\n\t\tu8g.setColorIndex(1);\n\t\tfor (uint8_t y = 0; y &lt; qrcode.size; y++) {\n\t\t\tfor (uint8_t x = 0; x &lt; qrcode.size; x++) {\n\t\t\t\tif (qrcode_getModule(&amp;qrcode, x, y))\n\t\t\t\t\tu8g.drawBox(15 + x, 15 + y, 1, 1);\n\t\t\t}\n\t\t}\n\t\t\n\t\tu8g.setColorIndex(1);\n\t\tu8g.drawBox(64, 0, 64, 64);\n\t\tu8g.setColorIndex(0);\n\t\tfor (uint8_t y = 0; y &lt; qrcode.size; y++) {\n\t\t\tfor (uint8_t x = 0; x &lt; qrcode.size; x++) {\n\t\t\t\tif (qrcode_getModule(&amp;qrcode, x, y))\n\t\t\t\t\tu8g.drawBox(79 + x, 15 + y, 1, 1);\n\t\t\t}\n\t\t}\n\t} while ( u8g.nextPage() );\n}\n\nvoid setup() {\n\tu8g.begin();\n\tdisplay_qrcode(&quot;https:\/\/programresource.net&quot;);\n}\n\nvoid loop() {\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>There&#8217;s QR code library for Arduino released 3 years ago. https:\/\/github.com\/ricmoo\/qrcode\/ Well made library, works with less memory of Arduino while supporting QR code versions and error correction levels. You can easily create QR code data with above library and show code to OLED display with u8glib library. Below is sample sketch for showing QR code with &#8220;https:\/\/programresource.net&#8221; text data to OLED display, with inverted B\/W on left \/ right half of screen. Very short and simple sketch which does amazing work.<\/p>\n","protected":false},"author":2,"featured_media":3055,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[866,868],"tags":[862,895,931],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/programresource.net\/images\/2020\/03\/P_20200301_223035_vHDR_Auto.jpg","jetpack_shortlink":"https:\/\/wp.me\/p3pJyQ-Nj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3057"}],"collection":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/comments?post=3057"}],"version-history":[{"count":1,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3057\/revisions"}],"predecessor-version":[{"id":3058,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3057\/revisions\/3058"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media\/3055"}],"wp:attachment":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media?parent=3057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/categories?post=3057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/tags?post=3057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}