{"id":184,"date":"2020-01-11T18:17:11","date_gmt":"2020-01-12T01:17:11","guid":{"rendered":"http:\/\/www.wolfpack.xyz\/blog\/?p=184"},"modified":"2020-04-04T03:42:04","modified_gmt":"2020-04-04T09:42:04","slug":"how-i-learned-to-stop-worrying-and-love-i2c","status":"publish","type":"post","link":"http:\/\/www.wolfpack.xyz\/blog\/?p=184","title":{"rendered":"&#8230;how I Learned to Stop Worrying and Love I2C"},"content":{"rendered":"\n<p>Some form of display is often vital on your arduino projects.Let me introduce you to the HD44780 character LCD. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"634\" height=\"476\" src=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/1447-02.jpg?resize=634%2C476\" alt=\"\" class=\"wp-image-185\" srcset=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/1447-02.jpg?w=970 970w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/1447-02.jpg?resize=300%2C225 300w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/1447-02.jpg?resize=768%2C576 768w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/1447-02.jpg?resize=816%2C612 816w\" sizes=\"(max-width: 634px) 100vw, 634px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>It&#8217;s quite a common and cheap display solution that is <em>relatively<\/em> easy to use. It often finds its way into many arduino starter kits for these reasons. Ive used it a few times in my projects but have always been annoyed by one aspect&#8230;. the high amount of pins and the requirement of a resistor for the backlight and a potentiometer for the contrast.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"634\" height=\"350\" src=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?resize=634%2C350\" alt=\"\" class=\"wp-image-186\" srcset=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?resize=1024%2C566 1024w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?resize=300%2C166 300w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?resize=768%2C425 768w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?resize=1536%2C849 1536w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?resize=816%2C451 816w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?w=1845 1845w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/LCD_Base_bb_Fritz.png?w=1268 1268w\" sizes=\"(max-width: 634px) 100vw, 634px\" data-recalc-dims=\"1\" \/><figcaption>The typical wiring setup for the display<\/figcaption><\/figure>\n\n\n\n<p>As you can see the board uses up 6 data pins on your board which can be a pain on the smaller boards I&#8217;ve been using lately. Then I discovered I2C (I squared C).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"634\" height=\"357\" src=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/i2c.png?resize=634%2C357\" alt=\"\" class=\"wp-image-187\" srcset=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/i2c.png?w=700 700w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2020\/01\/i2c.png?resize=300%2C169 300w\" sizes=\"(max-width: 634px) 100vw, 634px\" data-recalc-dims=\"1\" \/><figcaption>I2C is a method of using addresses to run many devices on only 2 data lines.<\/figcaption><\/figure>\n\n\n\n<p>With this we can run these LCD displays with a total of 4 wires. This is handy on boards like the ESP8266 or ESP32 with few pins. I plan on using a I2C compatible display on a project in the near future. I ordered the <a href=\"https:\/\/www.aliexpress.com\/item\/32831845529.html\">larger 4 line version<\/a> in fact. <\/p>\n\n\n\n<p>The code for the  I2C display is quite similar to the regular versions.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;Wire.h&gt; \n#include &lt;LiquidCrystal_I2C.h&gt;\n\nLiquidCrystal_I2C lcd(0x27,16,2);  \/\/ set the LCD address to 0x27 for a 16 columns and 2 row display\n\nvoid setup() {\n  lcd.init();       \/\/initialize lcd screen\n  lcd.backlight();  \/\/ turn on the backlight\n}\n\nvoid loop() {\n  delay(1000);                   \/\/wait for a second\n  lcd.setCursor(0,0);            \/\/ tell the screen to write on the top row\n  lcd.print(&quot;LCD TEST&quot;);         \/\/ tell the screen to write \u201chello, from\u201d on the top row\n  lcd.setCursor(0,1);            \/\/ tell the screen to write on the bottom row\n  lcd.print(&quot;Hello World!&quot;);     \/\/ tell the screen to write &quot;Hello World!&quot; on the bottom row\n}\n\n<\/pre><\/div>\n\n\n<p><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-184\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=184&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-184\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=184&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Some form of display is often vital on your arduino projects.Let me introduce you to the HD44780 character LCD. It&#8217;s quite a common and cheap display solution that is relatively easy to use. It often finds its way into many arduino starter kits for these reasons. Ive used it a few times in my projects [&hellip;]<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-184\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=184&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-184\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=184&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[6,7,13],"tags":[14],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6nSil-2Y","jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/184"}],"collection":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":2,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":209,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/209"}],"wp:attachment":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}