{"id":34,"date":"2014-01-24T14:57:00","date_gmt":"2014-01-24T14:57:00","guid":{"rendered":"https:\/\/blog.hslracing.com\/3dprinters\/2014\/01\/24\/repetier-and-i2c-lcd-panel\/"},"modified":"2021-06-08T18:46:37","modified_gmt":"2021-06-08T17:46:37","slug":"repetier-and-i2c-lcd-panel","status":"publish","type":"post","link":"https:\/\/blog.hslracing.com\/3dprinters\/2014\/01\/repetier-and-i2c-lcd-panel.html","title":{"rendered":"Repetier and I2C LCD panel"},"content":{"rendered":"<p>I was having yet another bash at persuading my breadboard based hardware to work with the I2C connected LCD display as mentioned in my <a href=\"https:\/\/blog.hslracing.com\/3dprinters\/2012\/10\/10\/panelolu\/\">Panelolu<\/a> post.<\/p>\n<p>I have been bashing my head against a wall with the <a href=\"http:\/\/www.repetier.com\/documentation\/repetier-firmware\/\">Repetier<\/a> firmware for months. Every time I had it use the LCD and uploaded the firmware, the whole board would hang just as it reached the initialisation of the LCD display.<\/p>\n<p>I had tried with the built-in I2C library as well as several other Liquid Crystal libraries, none of which would work with\u00a0<a href=\"http:\/\/www.repetier.com\/documentation\/repetier-firmware\/\">Repetier<\/a>\u00a0once the LCD part was enabled.<\/p>\n<p>I could manage to talk to the\u00a0<a href=\"http:\/\/www.nxp.com\/documents\/data_sheet\/PCF8574.pdf\">PCF8574P\u00a0<\/a>\u00a0I2C chip and obtain the address with the <a href=\"http:\/\/playground.arduino.cc\/Main\/I2cScanner\">Scanner<\/a> program, I could also write my own code to talk to the LCD all of which seemed to work fine, yet no matter what I did the LCD would just not play ball with\u00a0<a href=\"http:\/\/www.repetier.com\/documentation\/repetier-firmware\/\">Repetier<\/a>.<\/p>\n<p>I decided to re-read a bunch of posts about the various Liquid Crystal I2C libraries along with checking the schematics used for each of them, re-check the pin configurations in\u00a0<a href=\"http:\/\/www.repetier.com\/documentation\/repetier-firmware\/\">Repetier<\/a>\u00a0and also how it was wired up on the board.<\/p>\n<p>Eventually I discovered that I had the RS and RW pins backwards in uiconfig.h for\u00a0<a href=\"http:\/\/www.repetier.com\/documentation\/repetier-firmware\/\">Repetier<\/a>\u00a0and after one last compile and upload we had success and the LCD sprang into life. (kind of begs the question how it was working with the other pieces of software though).<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"http:\/\/3.bp.blogspot.com\/-Wi426VPMEfw\/UuJoA4R8ApI\/AAAAAAAAA3o\/2fh1HDPoEcA\/s1600\/Prusa-I3-27.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/3.bp.blogspot.com\/-Wi426VPMEfw\/UuJoA4R8ApI\/AAAAAAAAA3o\/2fh1HDPoEcA\/s1600\/Prusa-I3-27.jpg\" width=\"320\" height=\"249\" border=\"0\" \/><\/a><\/div>\n<p>This is my pin configuration for the LCD in uiconfig.h<\/p>\n<p><span style=\"font-family: Courier New, Courier, monospace;\">\/**<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">What display type do you use?<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">0 = No display<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">1 = LCD Display with 4 bit data bus<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">2 = LCD Display with 8 bit data bus (currently not implemented, fallback to 1)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">3 = LCD Display with I2C connection, 4 bit mode<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">4 = Use the slower LiquiedCrystal library bundled with arduino.\u00a0<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 IMPORTANT: You need to uncomment the LiquidCrystal include in Repetier.pde for it to work.<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0If you have Sanguino and want to use the library, you need to have Arduino 023 or older. (13.04.2012)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">*\/<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_TYPE 3<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><br \/>\n<\/span><span style=\"font-family: Courier New, Courier, monospace;\">\/\/ This is line 2 of the status display at startup<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_VERSION_STRING2 &#8220;Orig. Mendel&#8221;<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><br \/>\n<\/span><span style=\"font-family: Courier New, Courier, monospace;\">\/** Number of columns per row<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><br \/>\n<\/span><span style=\"font-family: Courier New, Courier, monospace;\">Typical values are 16 and 20<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">*\/<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_COLS 16<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/**<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">Rows of your display. 2 or 4<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">*\/<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_ROWS 2<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><br \/>\n<\/span><span style=\"font-family: Courier New, Courier, monospace;\">\/* What type of chip is used for I2C communication<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">0 : PCF8574 or PCF8574A or compatible chips.<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">1 : MCP23017<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">*\/<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_I2C_CHIPTYPE 0<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/\/ 0x40 till 0x4e for PCF8574, 0x40 for the adafruid RGB shield, 0x40 &#8211; 0x4e for MCP23017<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_I2C_ADDRESS 0x40<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/\/ For MCP 23017 define which pins should be output<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_I2C_OUTPUT_PINS 65504<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/\/ Set the output mask that is or&#8217;d over the output data. This is needed to activate<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/\/ a backlight switched over the I2C.\u00a0<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/\/ The adafruit RGB shields enables a light if the bit is not set. Bits 6-8 are used for backlight.<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_I2C_OUTPUT_START_MASK 0<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/\/ For MCP which inputs are with pullup. 31 = pins 0-4 for adafruid rgb shield buttons<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_I2C_PULLUP 31<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/* How fast should the I2C clock go. The PCF8574 work only with the lowest setting 100000.<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">A MCP23017 can run also with 400000 Hz *\/<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_I2C_CLOCKSPEED 100000L<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">\/**<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">Define the pin<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">*\/<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#if UI_DISPLAY_TYPE==3 \/\/ I2C Pin configuration<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_RS_PIN _BV(4)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_RW_PIN _BV(5)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_ENABLE_PIN _BV(6)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D0_PIN _BV(0)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D1_PIN _BV(1)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D2_PIN _BV(2)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D3_PIN _BV(3)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D4_PIN _BV(0)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D5_PIN _BV(1)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D6_PIN _BV(2)<\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\">#define UI_DISPLAY_D7_PIN _BV(3)<\/span><\/p>\n<p>The _BV values are the P0-P7 pins from the\u00a0<a href=\"http:\/\/www.nxp.com\/documents\/data_sheet\/PCF8574.pdf\">PCF8574P<\/a>\u00a0chip &#8211; I only needed P0-P6, D0-D4 are for the low nibble, D5-D8 for the high nibble, you can connect in 8-bit mode if you have enough pins (D0-D7), or you can connect in 4-bit mode (D5-D7), you just pretend that both sets are connected to the same pins and both the low and high nibble data is transferred over these 4 pins.<\/p>\n<p>As mentioned in my <a href=\"http:\/\/zebethyalprusa.blogspot.co.uk\/2012\/03\/firmware-and-making-fumes.html\">Firmware and Making Fumes<\/a> post, I have 10 pins to play with (13 if you include MOSI, MISO and SCK) on the\u00a0<a href=\"http:\/\/reprap.org\/wiki\/Sanguinololu\">sanguinololu<\/a>.<\/p>\n<p>Now I have reduced my LCD pin requirement from 6 to 2, I have a few more to play with, which means I can use the buzzer again, and still have 3 pins spare.<\/p>\n<table>\n<tbody>\n<tr>\n<th>Physical Pin #<\/th>\n<th>Pin Name<\/th>\n<th>Sanguinololu Pin<\/th>\n<th>Arduino Use<\/th>\n<th>My Use<\/th>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>PB6<\/td>\n<td>D7<\/td>\n<td>MISO<\/td>\n<td>SD card MISO<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>PB5<\/td>\n<td>D6<\/td>\n<td>MOSI<\/td>\n<td>SD card MOSI<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>PB7<\/td>\n<td>D5<\/td>\n<td>SCK<\/td>\n<td>SD card SCK<\/td>\n<\/tr>\n<tr>\n<td>40<\/td>\n<td>PA0<\/td>\n<td>A0\/D31<\/td>\n<td>GP I\/O<\/td>\n<td>SD card CS<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>RST<\/td>\n<td>RST<\/td>\n<td>RST<\/td>\n<td>Reset Button<\/td>\n<\/tr>\n<tr>\n<td>38<\/td>\n<td>PA2<\/td>\n<td>A2\/D29<\/td>\n<td>GP I\/O<\/td>\n<td>Encoder 1<\/td>\n<\/tr>\n<tr>\n<td>39<\/td>\n<td>PA1<\/td>\n<td>A1\/D30<\/td>\n<td>GP I\/O<\/td>\n<td>Encoder 2<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>PD2<\/td>\n<td>D10<\/td>\n<td>RX1<\/td>\n<td>Encoder C<\/td>\n<\/tr>\n<tr>\n<td>37<\/td>\n<td>PA3<\/td>\n<td>A3\/D28<\/td>\n<td>GP I\/O<\/td>\n<td>Buzzer<\/td>\n<\/tr>\n<tr>\n<td>22<\/td>\n<td>PC0<\/td>\n<td>D16<\/td>\n<td>SCL<\/td>\n<td>I2C LCD SCL<\/td>\n<\/tr>\n<tr>\n<td>23<\/td>\n<td>PC1<\/td>\n<td>D17<\/td>\n<td>SDA<\/td>\n<td>I2C LCD SDA<\/td>\n<\/tr>\n<tr>\n<td>36<\/td>\n<td>PA4<\/td>\n<td>A4\/D27<\/td>\n<td>GP I\/O<\/td>\n<td>Free<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>PB4<\/td>\n<td>D4<\/td>\n<td>PWM<\/td>\n<td>Free<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>PD3<\/td>\n<td>D11<\/td>\n<td>TX1<\/td>\n<td>Free<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>Whilst at a first glance, this might not seem the most logical layout, it makes more sense if you look at the way the pins are actually laid out on the\u00a0<a href=\"http:\/\/reprap.org\/wiki\/Sanguinololu\">sanguinololu<\/a>.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"http:\/\/4.bp.blogspot.com\/-q8EWYxcfQ-o\/UuKbzQIGfxI\/AAAAAAAAA34\/4B31hviO2nQ\/s1600\/Screen+shot+2014-01-24+at+16.58.16.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/4.bp.blogspot.com\/-q8EWYxcfQ-o\/UuKbzQIGfxI\/AAAAAAAAA34\/4B31hviO2nQ\/s1600\/Screen+shot+2014-01-24+at+16.58.16.png\" width=\"320\" height=\"235\" border=\"0\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<\/div>\n<div>I believe I have mentioned it already, but I am not interested in running any firmware that will not compile against a relatively current version of <a href=\"http:\/\/www.arduino.cc\/\">Arduino<\/a>, (trying to obtain any support for issues with older versions is quite simply a pain), as such I am only interested in firmware that will compile against\u00a0<a href=\"http:\/\/www.arduino.cc\/\">Arduino<\/a>\u00a01.0 or greater (I am currently using 1.0.5).<\/p>\n<p>I have not compiled in the extra code for the rotary encoder or the buzzer yet, but things are looking good for using an <a href=\"http:\/\/www.atmel.com\/devices\/atmega644p.aspx\">ATmega644P<\/a>\u00a0rather than needing the more expensive\u00a0<a href=\"http:\/\/www.atmel.com\/devices\/atmega1284p.aspx\">ATmega1284P<\/a>, as the compiled code is only 47,928 bytes. Previously with the\u00a0<a href=\"http:\/\/reprap.org\/wiki\/Marlin\">Marlin<\/a>\u00a0firmware, after enabling the LCD code, I was beyond the 64Kb limit of the\u00a0<a href=\"http:\/\/www.atmel.com\/devices\/atmega644p.aspx\">ATmega644P<\/a>.<\/p>\n<p>Here is a possible interface board for the panelolu.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"http:\/\/4.bp.blogspot.com\/-qWKt_02kjmU\/UuLs9AXM0aI\/AAAAAAAAA4Q\/yM-wFUL2JsM\/s1600\/Screen+shot+2014-01-24+at+22.44.37.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/4.bp.blogspot.com\/-qWKt_02kjmU\/UuLs9AXM0aI\/AAAAAAAAA4Q\/yM-wFUL2JsM\/s1600\/Screen+shot+2014-01-24+at+22.44.37.png\" width=\"320\" height=\"183\" border=\"0\" \/><\/a><\/div>\n<p>And without the components covering the connections.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"http:\/\/3.bp.blogspot.com\/-j20b7x9aeI8\/UvntHYeDnNI\/AAAAAAAAA6A\/qWn4eWCa8UA\/s1600\/Screen+shot+2014-02-11+at+09.26.56.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/3.bp.blogspot.com\/-j20b7x9aeI8\/UvntHYeDnNI\/AAAAAAAAA6A\/qWn4eWCa8UA\/s1600\/Screen+shot+2014-02-11+at+09.26.56.png\" width=\"320\" height=\"183\" border=\"0\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: left;\">The only real difference from the schematic is that the connections for pins 9 and 11 (P4 and P6) have been swapped in order to make wiring simpler.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I was having yet another bash at persuading my breadboard based hardware to work with the I2C connected LCD display as mentioned in my Panelolu post. I have been bashing my head against a wall with the Repetier firmware for months. Every time I had it use the LCD and uploaded the firmware, the whole&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":[4],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-prusa-i3"],"_links":{"self":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":1,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts\/34\/revisions\/224"}],"wp:attachment":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}