{"id":154,"date":"2019-07-18T20:27:16","date_gmt":"2019-07-18T20:27:16","guid":{"rendered":"https:\/\/tobyslab.com\/?p=154"},"modified":"2019-07-18T20:31:37","modified_gmt":"2019-07-18T20:31:37","slug":"arduino-and-pcf8574-i2c-lcd-display","status":"publish","type":"post","link":"https:\/\/tobyslab.com\/?p=154","title":{"rendered":"Arduino and PCF8574 I2C LCD Display"},"content":{"rendered":"\n<p>I picked up a couple of very low cost 16&#215;2 LCD display modules for a project I am working on. They are based on the <a href=\"http:\/\/www.ti.com\/lit\/ds\/symlink\/pcf8574.pdf\">Texas Instruments PCF8574 Remote 8-Bit I\/O Expander for I2C Bus.<\/a> Since there are a myriad of different LCD libraries for Arduino, I thought I would document my experience and the working configuration I came upon.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"600\" height=\"400\" src=\"https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/lcd_display.jpg\" alt=\"\" class=\"wp-image-156\" srcset=\"https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/lcd_display.jpg 600w, https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/lcd_display-300x200.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption>PCF8574 I2C 16&#215;2 Display<\/figcaption><\/figure>\n\n\n\n<p>The library we need is <a href=\"https:\/\/github.com\/mathertel\/LiquidCrystal_PCF8574\">LiquidCrystal_PCF8574 by Matthias Hertel.<\/a> It is available in the Arduino libraries manager.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"129\" src=\"https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/Screen-Shot-2019-07-18-at-2.50.50-PM-1024x129.png\" alt=\"\" class=\"wp-image-155\" srcset=\"https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/Screen-Shot-2019-07-18-at-2.50.50-PM-1024x129.png 1024w, https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/Screen-Shot-2019-07-18-at-2.50.50-PM-300x38.png 300w, https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/Screen-Shot-2019-07-18-at-2.50.50-PM-768x97.png 768w, https:\/\/tobyslab.com\/wp-content\/uploads\/2019\/07\/Screen-Shot-2019-07-18-at-2.50.50-PM.png 1520w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The demo code from the library works well to demonstrate the capabilities of the display:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;LiquidCrystal_PCF8574.h>\n#include &lt;Wire.h>\n\nLiquidCrystal_PCF8574 lcd(0x27); \/\/ set the LCD address to 0x27 for a 16 chars and 2 line display\n\nint show = -1;\n\nvoid setup()\n{\n  int error;\n\n  Serial.begin(115200);\n  Serial.println(\"LCD...\");\n\n  \/\/ wait on Serial to be available on Leonardo\n  while (!Serial)\n    ;\n\n  Serial.println(\"Dose: check for LCD\");\n\n  \/\/ See http:\/\/playground.arduino.cc\/Main\/I2cScanner how to test for a I2C device.\n  Wire.begin();\n  Wire.beginTransmission(0x27);\n  error = Wire.endTransmission();\n  Serial.print(\"Error: \");\n  Serial.print(error);\n\n  if (error == 0) {\n    Serial.println(\": LCD found.\");\n    show = 0;\n    lcd.begin(16, 2); \/\/ initialize the lcd\n\n  } else {\n    Serial.println(\": LCD not found.\");\n  } \/\/ if\n\n} \/\/ setup()\n\n\nvoid loop()\n{\n  if (show == 0) {\n    lcd.setBacklight(255);\n    lcd.home();\n    lcd.clear();\n    lcd.print(\"Hello LCD\");\n    delay(1000);\n\n    lcd.setBacklight(0);\n    delay(400);\n    lcd.setBacklight(255);\n\n  } else if (show == 1) {\n    lcd.clear();\n    lcd.print(\"Cursor On\");\n    lcd.cursor();\n\n  } else if (show == 2) {\n    lcd.clear();\n    lcd.print(\"Cursor Blink\");\n    lcd.blink();\n\n  } else if (show == 3) {\n    lcd.clear();\n    lcd.print(\"Cursor OFF\");\n    lcd.noBlink();\n    lcd.noCursor();\n\n  } else if (show == 4) {\n    lcd.clear();\n    lcd.print(\"Display Off\");\n    lcd.noDisplay();\n\n  } else if (show == 5) {\n    lcd.clear();\n    lcd.print(\"Display On\");\n    lcd.display();\n\n  } else if (show == 7) {\n    lcd.clear();\n    lcd.setCursor(0, 0);\n    lcd.print(\"*** first line.\");\n    lcd.setCursor(0, 1);\n    lcd.print(\"*** second line.\");\n\n  } else if (show == 8) {\n    lcd.scrollDisplayLeft();\n  } else if (show == 9) {\n    lcd.scrollDisplayLeft();\n  } else if (show == 10) {\n    lcd.scrollDisplayLeft();\n  } else if (show == 11) {\n    lcd.scrollDisplayRight();\n\n  } else if (show == 12) {\n    lcd.clear();\n    lcd.print(\"write-\");\n\n  } else if (show > 12) {\n    lcd.print(show - 13);\n  } \/\/ if\n\n  delay(1400);\n  show = (show + 1) % 16;\n} \/\/ loop()<\/code><\/pre>\n\n\n\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/V7dENnkiBkc\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>I picked up a couple of very low cost 16&#215;2 LCD display modules for a project I am working on. They are based on the Texas Instruments PCF8574 Remote 8-Bit I\/O Expander for I2C Bus. Since there are a myriad of different LCD libraries for Arduino, I thought I would document my experience and the working configuration I came upon. The library we need is LiquidCrystal_PCF8574 by Matthias Hertel. It is available in the Arduino libraries manager. The demo code from the library works well to demonstrate the capabilities of the display:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/154"}],"collection":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":3,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":160,"href":"https:\/\/tobyslab.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/160"}],"wp:attachment":[{"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tobyslab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}