{"id":48,"date":"2008-10-17T19:33:44","date_gmt":"2008-10-17T19:33:44","guid":{"rendered":"http:\/\/blog.danplanet.com\/wordpress\/?p=48"},"modified":"2008-10-17T19:33:44","modified_gmt":"2008-10-17T19:33:44","slug":"driving-a-4-bit-lcd-with-an-arduino","status":"publish","type":"post","link":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/","title":{"rendered":"Driving a 4-Bit LCD with an Arduino"},"content":{"rendered":"<p>I received my <a href=\"http:\/\/arduino.cc\" mce_href=\"http:\/\/arduino.cc\">Arduino<\/a>  Diecimilia today.&nbsp; Man, what a cool little device.&nbsp; I ordered it last weekend with the intent of using it to learn about programming microcontrollers, in hopes of making some neat toys.&nbsp; One of the first things I wanted to be able to do right away was drive an LCD display.&nbsp; This is very important because I feel that all devices should have LCD displays.&nbsp; All of them.&nbsp; Nowadays, I look down on printers without LCD displays (and network cards for that matter) with utter disgust.<\/p>\n<p>Anyway, I went to <a href=\"http:\/\/www.surplusgizmos.com\" mce_href=\"http:\/\/www.surplusgizmos.com\">SurplusGizmos<\/a>  and found myself a nice and cheap 16&#215;2 backlit LCD display.&nbsp; It uses the KS0066 controller chip, which is supposedly compatible with the legendary Hitachi HD44780 command set.&nbsp; Because I couldn&#8217;t wait for the Arduino to come, I tested it first with a parallel port and <a href=\"http:\/\/lcdproc.omnipotent.net\/\" mce_href=\"http:\/\/lcdproc.omnipotent.net\/\">lcdproc<\/a>.<\/p>\n<p>When the Arduino came today, I was ready to try the LCD with it.&nbsp; Using the integrated LiquidCrystal library, I was able to drive it in 4- and 8-bit mode.&nbsp; However, in 4-bit mode, the LCD seemed to have trouble keeping up, as long strings would get garbled pretty badly.&nbsp; It worked fine in 8-bit mode, so I figured this was likely due to the controller switching upper\/lower nibbles too quickly.<\/p>\n<p>So, in a bit of shameful C++ fu, I created a derivative library that just subclasses the existing one and puts a 2ms delay after each write operation.&nbsp; This seems to completely clear up the problem, and I can happily have four digitial IO lines back as a result.<\/p>\n<p>The code is extremely simple, so I&#8217;ll just post it here for the taking.&nbsp; The header is:<\/p>\n<div style=\"font-family: Courier New,Courier,mono; margin-left: 40px;\">#include &#8220;..\/LiquidCrystal\/LiquidCrystal.h&#8221;<\/p>\n<p>class Slow4BitLCD : public LiquidCrystal {<br \/>&nbsp; public:<br \/>&nbsp;&nbsp;&nbsp; Slow4BitLCD(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);<br \/>&nbsp;&nbsp;&nbsp; void write(uint8_t);<br \/>};<\/div>\n<p>&#8230;and the implementation is:<\/p>\n<div style=\"font-family: Courier New,Courier,mono; margin-left: 40px;\">#include &lt;inttypes.h&gt;<br \/>#include &#8220;WProgram.h&#8221;<\/p>\n<p>#include &lt;Slow4BitLCD.h&gt;<br \/>#include &#8220;..\/LiquidCrystal\/LiquidCrystal.h&#8221;<\/p>\n<p>Slow4BitLCD::Slow4BitLCD(uint8_t rs, uint8_t rw, uint8_t en, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)<br \/>&nbsp; : LiquidCrystal::LiquidCrystal(rs, rw, en, d0, d1, d2, d3)<br \/>{}<\/p>\n<p>void Slow4BitLCD::write(uint8_t value) {<br \/>&nbsp; LiquidCrystal::write(value);<br \/>&nbsp; delayMicroseconds(2000);<br \/>}<\/div>\n<p>Create an Arduino library called &#8220;Slow4BitLCD&#8221; and put those two files in (with .h and .cpp extensions, respectively) and you should be in business.<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I received my Arduino Diecimilia today.&nbsp; Man, what a cool little device.&nbsp; I ordered it last weekend with the intent of using it to learn about programming microcontrollers, in hopes of making some neat toys.&nbsp; One of the first things &hellip; <a href=\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-hardware"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Driving a 4-Bit LCD with an Arduino - Right Angles<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Driving a 4-Bit LCD with an Arduino - Right Angles\" \/>\n<meta property=\"og:description\" content=\"I received my Arduino Diecimilia today.&nbsp; Man, what a cool little device.&nbsp; I ordered it last weekend with the intent of using it to learn about programming microcontrollers, in hopes of making some neat toys.&nbsp; One of the first things &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\" \/>\n<meta property=\"og:site_name\" content=\"Right Angles\" \/>\n<meta property=\"article:published_time\" content=\"2008-10-17T19:33:44+00:00\" \/>\n<meta name=\"author\" content=\"Dan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\"},\"author\":{\"name\":\"Dan\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"headline\":\"Driving a 4-Bit LCD with an Arduino\",\"datePublished\":\"2008-10-17T19:33:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\"},\"wordCount\":433,\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"articleSection\":[\"Hardware\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\",\"url\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\",\"name\":\"Driving a 4-Bit LCD with an Arduino - Right Angles\",\"isPartOf\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\"},\"datePublished\":\"2008-10-17T19:33:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.danplanet.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Driving a 4-Bit LCD with an Arduino\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#website\",\"url\":\"https:\/\/www.danplanet.com\/blog\/\",\"name\":\"Right Angles\",\"description\":\"If they&#039;re not right...they&#039;re wrong\",\"publisher\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c\",\"name\":\"Dan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g\",\"caption\":\"Dan\"},\"logo\":{\"@id\":\"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.danplanet.com\/blog\/author\/dan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Driving a 4-Bit LCD with an Arduino - Right Angles","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/","og_locale":"en_US","og_type":"article","og_title":"Driving a 4-Bit LCD with an Arduino - Right Angles","og_description":"I received my Arduino Diecimilia today.&nbsp; Man, what a cool little device.&nbsp; I ordered it last weekend with the intent of using it to learn about programming microcontrollers, in hopes of making some neat toys.&nbsp; One of the first things &hellip; Continue reading &rarr;","og_url":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/","og_site_name":"Right Angles","article_published_time":"2008-10-17T19:33:44+00:00","author":"Dan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/#article","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/"},"author":{"name":"Dan","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"headline":"Driving a 4-Bit LCD with an Arduino","datePublished":"2008-10-17T19:33:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/"},"wordCount":433,"publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"articleSection":["Hardware"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/","url":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/","name":"Driving a 4-Bit LCD with an Arduino - Right Angles","isPartOf":{"@id":"https:\/\/www.danplanet.com\/blog\/#website"},"datePublished":"2008-10-17T19:33:44+00:00","breadcrumb":{"@id":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.danplanet.com\/blog\/2008\/10\/17\/driving-a-4-bit-lcd-with-an-arduino\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.danplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Driving a 4-Bit LCD with an Arduino"}]},{"@type":"WebSite","@id":"https:\/\/www.danplanet.com\/blog\/#website","url":"https:\/\/www.danplanet.com\/blog\/","name":"Right Angles","description":"If they&#039;re not right...they&#039;re wrong","publisher":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.danplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/0f6920aa6d63cae437bf8b122200287c","name":"Dan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9b73782704be64dd8c030087af2d1ae0c1dc488cad69093ff0366dbaad2de673?s=96&d=mm&r=g","caption":"Dan"},"logo":{"@id":"https:\/\/www.danplanet.com\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.danplanet.com\/blog\/author\/dan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":0,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}