Sparkfun Serial LCD Library

Surprisingly, yes, I saw fit to write “yet another” library for the Sparkfun Serial-Enabled LCD.

Partially, the reason is that when I searched, I got to the playground page about using SoftwareSerial, Serial, etc. And, as such, those implementations wouldn’t do (why load yet another library to just to talk to a one-pin device?!).

Well, as luck would have it - this one is (I hope!) sufficiently different to be worth using grin Because, doing my search a little more thoroughly, I found some libraries - but they all require you to load a serial library of some sort (either software or hardware). And that’s quite an expense for this device!

Considering that one just needs to bang out some bits, like one does with SoftwareSerial, I thought, why not just base it on SoftwareSerial?

So, here’s (yet another) Sparkfun Serial-Enabled LCD Library (SparkSoftLCD) – you can download it here: http://openmoco.org/node/153

Here’s the gist:

  • It’s based on the SoftwareSerial library in the core by mellis
  • it doesn’t have read() or println()
  • it doesn’t need an ‘RX’ pin definition
  • it supports all types of prints SoftwareSerial does
  • Attempts to stay closer to the parallel LCD library
  • new methods:
  • clear()
  • cursorTo(c, r)
  • cursor( type )
  • scroll ( dir )
  • moveCursor (dir )
  • backlight( amount )
  • enable ( on )
  • sendControl( byte )

I’d appreciate any feedback, suggestions, or requests!

Here’s an example script that shows off some basic functionality, adding text while scrolled off-screen, and a “fuse-like” timer that uses a counter and scroll to indicate some impending detonation:

/* 
  Example of using the SparkSoftLCD library for the Arduino
  
  2010 C. A. Church 
     http://openmoco.org/    
*/

  

#include "SparkSoftLCD.h"

  // LCD transmit pin
#define LCD_TX 2

SparkSoftLCD lcd = SparkSoftLCD(LCD_TX);

void setup() { 

   // setup lcd
   
 pinMode(LCD_TX, OUTPUT);
 lcd.begin(9600);
 lcd.clear();
 
   // hidden cursor
 lcd.cursor(0);
 
 show_setup();
 
 delay(1000);
 
}

void loop() {

    lcd.clear();
    
      // block-style blinking cursor
    lcd.cursor(2);
    
    lcd.print("Arming");
    delay(1500);
    
    lcd.clear();
    
      // hidden cursor
    lcd.cursor(0);
    
    lcd.print("16");
    lcd.cursorTo(2,1);
    lcd.print("---------------*");
    
    delay(1000);
    
    for( byte i = 15; i >= 1; i-- ) {
        
        lcd.scroll(false);
        
        // as we scroll left, we need to move our cursor to
        // the right to continue to show our countdown
        //
        // in this way, we achieve the sense that a fuse is getting
        // shorter...
        lcd.cursorTo(1,1 + (16 - i) );
        lcd.print(i, DEC);
        
        delay(1000);
     }
    
      // make last bit disappear
    lcd.scroll(false);
    delay(500);
    lcd.clear();
    lcd.cursorTo(2, 10);
    lcd.print("(boom)");
    
    delay(2000);
    
}



void show_setup() {
  
 lcd.print("I am setting up!");
 
   // send cursor to 2nd row, first column
 lcd.cursorTo(2,1);
 
 delay(500);
 
 for (byte i = 0; i <= 15; i++ ) {
     delay(150);
       // scroll display to the right
     lcd.scroll(true);
 }
 
 delay(1500);
 lcd.print("One more moment");
 
 
 for (byte i = 0; i <= 15; i++ ) {
     delay(150);
       // scroll back to the left, revealing our new text
     lcd.scroll(false);
 }
 
}

!c

I've been testing the sparkfun serial LCD libraries, and none of them are capable of handling floats like serial does, i.e.

float variable=5.1234; Serial.print(variable,4); // prints 5.1234 on the screen

can we (as in the hungry user base) get you to implement floating point prints? It would be much appreciated.

Definitely, in fact, I have a version with it already added. Unfortunately, it's on my home machine and I am out of town for the next few days =(

I'll have it uploaded for you on Friday, and will post back up here when it's ready for download. I apologize for not getting it out sooner, I had every intention to update the release, but got side-tracked on other work!

!c

Great. Your library is probably the best I've run across for the serial LCD so far, and with float capability it certainly will be more than just another library.

Thanks.

Ok, I've updated the download page (and svn repo) with two changes:

1: Added support for printing floats print(float x, byte precision) 2: Added support for 16 or 20 character displays. Need to add width to constructor, see new example at http://openmoco.org/node/153

Thanks for the great feedback! Is there anything else you'd like to see in the library?

!c

Great Library

Makes it a lot easier to use my nice 20*4 Seriel Display :-)

I just quickly tested it, and it works nicely.

Just one detail, 'scroll'. when I scroll the following 20 times right:

Line 1 Line 2 Line 3 Line 4

I would expect to get the same text again, but I got:

Line 3 Line 4 Line 1 Line 2

If I scroll 20 times right, again I get back to the beginning.

Seems a bit strange to me :)

Could you please clarify?

Soren,

There are some limitations with scrolling and the serial lcd firmware. I don't have the 20x4 lcd myself, but it sounds like the behavior is related to the character addresses in the serial lcd firmware (noting that the next addresses after line 1 are line 3, and line 4 after line 2). Someone had a similar problem when trying to print off-screen, and I found a work-around: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272872762

... perhaps the same can be of use, or at least to help explain why its doing it? It seems the "scrolling" capability opened up a lot of edge-cases in the firmware.

!c

Hi Drone

Thanks a lot for clarifying it for me :slight_smile:

An thanks for sharing and updating a great library!

Hi, Can anyone tell me how to connect 16X2 LCD to in serial mode? I want to type text on PC and show up in real time on LCD.

Thanks, Yashar

Oh, great. Cross posted in every thread that has anything to do with serial.

No, no one can tell you how to connect the 4 wires that are on your LCD. You will just have to randomly plug them in and see what happens. Stand back when turning the Arduino on.

There are some limitations with scrolling and the serial lcd firmware. I don’t have the 20x4 lcd myself, but it sounds like the behavior is related to the character addresses in the serial lcd firmware (noting that the next addresses after line 1 are line 3, and line 4 after line 2). Someone had a similar problem when trying to print off-screen, and I found a work-around: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272872762

… perhaps the same can be of use, or at least to help explain why its doing it? It seems the “scrolling” capability opened up a lot of edge-cases in the firmware.

The strange scrolling characteristics as well as the interlacing of lines 1, 3, 2, and 4 are due to the structure of the LCD controller which is limited by the constraints of the technology available several decades ago when the controller was designed. To understand the problem you should first look at the LCD Addressing link at http://web.alfredstate.edu/weimandn where you will find information about the relationship between the LCD controller memory addresses and the locations of the characters on the display.

Remember that the scrolling software is affecting the locations of your data in the LCD memory. How this affects the location on the LCD screen varies depending on the particular device you are using (40x2, 20x4, etc.). These limitations can be corrected in software and some of this has been done in the LiquidCrystal440 library for the parallel interface. Perhaps you can use some of those techniques for your serial library.

Don

Can anyone tell me how to connect 16X2 LCD to in serial mode? I want to type text on PC and show up in real time on LCD.

No, because there is no 'serial mode' for the basic LCD module. All of the serial implementations that I have seen use a dedicated microprocessor between the Arduino and the LCD module and, unlike the parallel interface, there is no standardized interface or instruction set for the various serial LCD implementations.

Don