12 Replies Latest reply on Nov 2, 2014 9:49 AM by pulled_pork

    Galileo LiquidCrystal Library Fixes

    Mikal.Hart

      I've been studying the issues that people have been having trying to get the LiquidCrystal (LCD) library working and have developed a replacement that addresses them.  There are two issues that have been reported:

       

      1. The library and examples don't work as shipped, but you can sort of get around the problem by reinitializing the LiquidCrystal object with a clumsy init() sequence.

      Re: Problems getting LCD to work with Galileo

      Re: How to make an LCD shield work on the galileo board using arduino sketch

      Root cause: Global LiquidCrystal() constructors call pinMode() and digitalWrite(), which are (apparently) not available at sketch initialization time.

      Solution: Defer calls to pinMode() and digitalWrite() to the begin() method, which is typically called after the sketch has started.

       

      2. When it does work, it is quite slow.  For example, it takes 3 seconds to display "Hello, World" on my 8x2 display.

      Root cause: LiquidCrystal methods depend heavily on Arduino pinMode() and digitalWrite(), which are known to be slow on Galileo (especially pinMode()).  However, the library code can be optimized to call pinMode() only once at begin() time, and not every time a character is drawn.

      (Partial) Solution: Optimize the critical path, avoiding unnecessary calls to pinMode.  This basically triples the speed of my LCD refresh (although it's still noticeably slower than running the same sketch on an Arduino Uno).

       

      To install, simply do this:

      1. Copy the Arduino LiquidCrystal library from its default location at .../libraries/LiquidCrystal to the Galileo-specific library location at .../hardware/arduino/x86/libraries/LiquidCrystal.

      2. Replace the LiquidCrystal.cpp file in the "src" subfolder in the NEW (x86) location with the version attached.

      1. Download the latest archive at Releases · mikalhart/galileo-LiquidCrystal · GitHub

      2. Unzip to the Galileo-specific library area at ../hardware/arduino/x86/libraries/LiquidCrystal.  (Make sure to rename the root folder to LiquidCrystal, because Arduino doesn't like dashes in library names.)

      3. Exit the Arduino IDE software and restart it.

       

      You should now be able to run LCD sketches without the clumsy workarounds suggested by me and others:Re: Problems getting LCD to work with Galileo

      You should also notice some speed improvement.

       

      Note that I am not on the Galileo team, so this is in no way an official statement or release.

       

      Message was edited by: Mikal Hart

        • 1. Re: Galileo LiquidCrystal Library Fixes
          Clayton Hofrock

          This is great. Thanks for doing this.

           

          Hopefully this can be incorporated in the next release? Assuming that it has not already been fixed.

          • 2. Re: Galileo LiquidCrystal Library Fixes
            AlexT_Intel

            Very nice summary, thumbs up!

            • 3. Re: Galileo LiquidCrystal Library Fixes
              rmm200

              I have the totally unwarranted feeling that it will be a good long time before the Arduino 1.5.3 package is updated, and that most library fixes will have to come from the user community.

               

              Can someone please come up with a way to archive these library fixes, so we don't lose them, and they are all in one place?

              • 4. Re: Galileo LiquidCrystal Library Fixes
                Mikal.Hart

                rmm200,

                 

                That's a good idea.  I have some other Galileo library mods coming, so I'm building a GitHub archive for each of them to allow for easier collaboration.  The LiquidCrystal archive is here:

                 

                mikalhart/galileo-LiquidCrystal · GitHub

                • 5. Re: Galileo LiquidCrystal Library Fixes
                  Pubudu Goonetilleke

                  Hi,

                  I am looking for i2c library for Galileo board to interface LCD. Do you have that ?

                  thanks,

                  Pubudu

                  • 6. Re: Galileo LiquidCrystal Library Fixes
                    kona

                    Hi Pubudu,

                     

                    If you are still facing issues with I2c, please follow the instructions from [SOLVED] I2C LCD - Setup instructions for 16x2 - Arduino Forum

                     

                    Regards,

                    Raghu Kona

                    • 7. Re: Galileo LiquidCrystal Library Fixes
                      JonM

                      Mikal,

                       

                      Awesome.  This works nicely with the OSEPP 16x2 LCD Display & Keyboard Shield.  For anyone interested, to run a simple test with the OSEPP LCD the display uses the following pin out:

                       

                      // select the pins used on the LCD panel

                      LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

                       

                      Also, if the OSEPP LCD Shield is plugged directly to the Galileo using the Arduino headers, be warned that the pins on the display are short and there is a protruding pin from the on board Display Pot that lines up directly to the top of the Galileo Ethernet connector.  If the OSEPP LCD is pressed all the way down on the Galileo, this pin will short out to the Ethernet connector causing badness to happen such as resetting the Galileo.  Adding a set of Arduino headers to the bottom of the LCD cures this.

                       

                      Cheers,

                       

                      Jon

                      • 8. Re: Galileo LiquidCrystal Library Fixes
                        KenColey

                        I have an LCD shield that is almost identical to the OSEPP version mentioned above.  It also has some interference issues with the Ethernet housing.  I places so non-conductive material around the ethernet shell (metal) to insulate it.

                        However, when the LCD shield is installed, the board does not come up.  If I take the LCD shield off, the Galileo board works just fine.  I am trying to determine if the board is bad or not compatible.  I purchased my shield from OddWires.

                         

                        Thanks for any assistance,

                         

                        Ken

                        • 9. Re: Galileo LiquidCrystal Library Fixes
                          Pubudu Goonetilleke

                          I tried using the library and I am getting compiler errors  as follows :

                           

                          LiquidCrystal.cpp: In member function 'virtual void LiquidCrystal::setBacklight(uint8_t)':

                          LiquidCrystal.cpp:173:10: error: expected primary-expression before ')' token

                          LiquidCrystal.cpp:173:46: error: 'NOT_ON_TIMER' was not declared in this scope

                           

                          The error is with following function in (Bold) LiquidCrystal.cpp

                           

                          void LiquidCrystal::setBacklight ( uint8_t value )

                          {

                             // Check if there is a pin assigned to the backlight

                             // ---------------------------------------------------

                             if ( _backlightPin != LCD_NOBACKLIGHT )

                             {

                                // Check if the pin is associated to a timer, i.e. PWM

                                // ---------------------------------------------------

                                if(digitalPinToTimer(_backlightPin) != NOT_ON_TIMER)          //   Changed NOT_ON_TIMER since it is causing errors.

                                {

                                   // Check for control polarity inversion

                                   // ---------------------------------------------------

                                   if ( _polarity == POSITIVE )

                                   {

                                      analogWrite ( _backlightPin, value );

                                   }

                                   else

                                   {

                                      analogWrite ( _backlightPin, 255 - value );

                                   }

                                }

                                // Not a PWM pin, set the backlight pin for POSI or NEG

                                // polarity

                                // --------------------------------------------------------

                                else if (((value > 0) && (_polarity == POSITIVE)) ||

                                         ((value == 0) && (_polarity == NEGATIVE)))

                                {

                                   digitalWrite( _backlightPin, HIGH);

                                }

                                else

                                {

                                   digitalWrite( _backlightPin, LOW);

                                }

                             }

                          }

                           

                          > i2c scanner is working fine and it detects the i2c address of my LCD.

                           

                          Any help ?

                           

                          thanks,

                          Pubudu

                          • 10. Re: Galileo LiquidCrystal Library Fixes
                            gustafn

                            Dear Pubudu,

                             

                            It looks to me as if you used a wrong library. The version of mikalhart from github works perfectly. The whole directory contains the constant "LCD_NOBACKLIGHT" as shown in your snippet.

                             

                            The LiquidCrystal library works as well nicely when compiled directly on the Galileo (see [Tutorial] Templates for compiling sketches on the Galileo (esp. eglibc)), i've just now updated the Makefile to add an example how to use the extra libraries from the example sections in the IDE.

                            • 11. Re: Galileo LiquidCrystal Library Fixes
                              joaocandre

                              Can there be any improvement to the LCD refresh rate by using SPI or I2C? I don't have much pins to spare in my current application, but LCD output is slow as it is, don't want to degrade it any more.

                              • 12. Re: Galileo LiquidCrystal Library Fixes
                                pulled_pork

                                Hello:

                                 

                                I have a few DFRobot LCD KeyPad and they have been working well on my Gen 2 boards using the original LiquidCrystal library files. But when I put these LCD shields on Gen 1 boards, they do not boot at all. This is something that you must have seen and your library fix is addressing I assume. Does your replacement LCD library files work with Gen 2 as well? or that has not been tested? Since we are getting more Gen 2 boards soon and there are only two Gen 1 are on hand, I wonder if it is worth while to change the library for Gen 1 while Gen 2 prefers the original library. Any comment would be greatly appreciated. Thanks.

                                 

                                Regards,

                                Pulled_Pork