{"id":204,"date":"2013-09-08T16:12:01","date_gmt":"2013-09-08T23:12:01","guid":{"rendered":"http:\/\/samueldotj.com\/blog\/?p=204"},"modified":"2013-09-08T16:12:24","modified_gmt":"2013-09-08T23:12:24","slug":"i2c-20x4-lcd-module-and-arduino","status":"publish","type":"post","link":"http:\/\/samueldotj.com\/blog\/i2c-20x4-lcd-module-and-arduino\/","title":{"rendered":"I2C 20&#215;4 LCD module and Arduino"},"content":{"rendered":"<p>Recently I was working on a ZigBee project using XBee. Since XBee occupied the Arduino UART port, I decided use a character LCD for debug logs. I got the <a href=\"http:\/\/www.sainsmart.com\/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html\">SainSmart 20&#215;4 LCD module<\/a> with i2c interface. The connections are simple: <\/p>\n<table class=\"gridtable\">\n<tr>\n<th>Arduino<\/th>\n<th>LCD<\/th>\n<\/tr>\n<tr>\n<td>5v<\/td>\n<td>VCC<\/td>\n<\/tr>\n<tr>\n<td>GND<\/td>\n<td>GND<\/td>\n<\/tr>\n<tr>\n<td>SDA<\/td>\n<td>A5\/SDA<\/td>\n<\/tr>\n<tr>\n<td>SCL<\/td>\n<td>A4\/SCL<\/td>\n<\/tr>\n<\/table>\n<p>But I couldnt make it work with sample code provided, after few googling I found that the sample code has a wrong i2c address. Even after using the correct I2C address(0x3f), it didnt work, but I was getting only to horizontal black bars on the screen. <\/p>\n<p>I confirmed the I2C is working by using I2C Explorer. Finally after updating the i2c <a href=\"https:\/\/bitbucket.org\/fmalpartida\/new-liquidcrystal\/wiki\/Home\">library<\/a> and with the following code, it started working. I found this code on a amazon review and modified for my purpose.<\/p>\n<script src=\"https:\/\/gist.github.com\/6489019.js\"><\/script><noscript><pre><code class=\"language-c c\">\/*\n * Sample code for SainSmart IIC\/I2C\/TWI Serial 2004 20x4 LCD Module.\n * License: GPL\n *\/\n\n#include &lt;Wire.h&gt;\n#include &lt;LiquidCrystal_I2C.h&gt;\n\n#define I2C_ADDR\t0x3F\n#define En_pin\t\t2\n#define Rw_pin\t\t1\n#define Rs_pin\t\t0\n#define D4_pin\t\t4\n#define D5_pin\t\t5\n#define D6_pin\t\t6\n#define D7_pin\t\t7\n#define BACKLIGHT_PIN   3\n\nLiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin,\n                      D4_pin, D5_pin, D6_pin, D7_pin);\n\nvoid setup() {\n\tlcd.begin (20, 4);\n\n\t\/\/ Switch on the backlight\n\tlcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);\n\tlcd.setBacklight(LOW);\n\n\t\/\/ Position cursor and write some text\n\tlcd.home();\n\tlcd.print(&quot;Hello World&quot;);\n}\n\nvoid loop() {\n}\n<\/code><\/pre><\/noscript>\n<p><a href=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2013\/09\/LCD2004.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2013\/09\/LCD2004-300x200.jpg\" alt=\"LCD2004\" width=\"300\" height=\"200\" class=\"alignnone size-medium wp-image-216\" srcset=\"http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2013\/09\/LCD2004-300x200.jpg 300w, http:\/\/samueldotj.com\/blog\/wp-content\/uploads\/2013\/09\/LCD2004-1024x682.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was working on a ZigBee project using XBee. Since XBee occupied the Arduino UART port, I decided use a character LCD for debug logs. I got the SainSmart 20&#215;4 LCD module with i2c interface. The connections are simple: Arduino LCD 5v VCC GND GND SDA A5\/SDA SCL A4\/SCL But I couldnt make it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-arduino"],"_links":{"self":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":10,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":224,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions\/224"}],"wp:attachment":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}