LCD 2x16

17 Nov 2009

Hi,

I just got my mbed and it is cool.

I am a newbie so please point me in the right direction.

the following is my code:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3


int main() {
   lcd.cls();
   lcd.locate(2, 0);
   lcd.printf("Test Row1");  
   lcd.locate(3, 1);
   lcd.printf("Test Row2");
      
        }

The Test Row1 prints correctly (col2 row 0).

The problem is the Test Row2 line is printed at col 0 row 2, instead of col 3 row 2.

Can anyone point me in the right direction to get the charachters to start printing at col 3 row 2?

17 Nov 2009 . Edited: 17 Nov 2009

 

locate

virtual void locate( int column,
int row )

Locate to a certian position

Variables

column the column to locate to, from 0..15
row

the row to locate to, from 0..1

 

 

You can only have row 0 or 1, since you only have two lines on your LCD

 

Check this out for more info: http://mbed.org/projects/cookbook/api/TextLCD/trunk/TextLCD#TextLCD.locate

17 Nov 2009 . Edited: 17 Nov 2009

Thanks for the quick reply,

But I think I am using lcd.locate(3,1) correctly --->  ( column 3 in the second row of the lcd)

The problem is the second row is printing at column 0 instead of column 3.

If I am being dense please correct me.

Thanks again.

17 Nov 2009

Very weird I copied your code exactly and it works without a hitch. This is what you want to accomplish? Try using

TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,16,2); // rs, rw, e, d0, d1, d2, d3,

Add 16, and 2 at the end to tell what type of LCD screen you are using, I am using a 20X2.

17 Nov 2009

LCD model# HD44780 (used TextLCD from cookbook to order)

I can't seem to attach a pic I keep getting a http error. here is a link to it:

http://cpinetree.com/LCD/LCD.JPG

Here is some other code I have been playing with:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(p24, p25, p26, p27, p28, p29, p30, 16, 2); // rs, rw, e, d0, d1, d2, d3


int main() {
   lcd.cls();
   lcd.printf("12345678901234567890123456789012");  

   wait(2);

   lcd.cls();
   lcd.locate(0, 0);
   lcd.printf("123456789 10 11-123456789-/-/-/-"); 
 
   lcd.locate(3, 1);
   lcd.printf("Test Row2");

   wait(2);

   lcd.cls();
   lcd.locate(15, 0);
   lcd.printf("123456789-1234567");

   wait(2);

   lcd.cls();
   lcd.locate(2, 0);
   lcd.printf("Test Row1"); 
 
   lcd.locate(3, 1);
   lcd.printf("Test Row2");
   
   
  
          }

the first print line prints a number in every column of both rows.

the locate(15,0);  prints a 1 at coulum16 row1 then continues down to row2 with the rest of the line (23456789-1234567)

but I can not get anything to correctly locate in the second row, short of using spaces in the print statement.

everything seems to work fine in the first row.

I guess I could just code around this, but I wasn't sure if it was a bug or something I was doing incorrectly.

Thanks agin for your help,

17 Nov 2009 . Edited: 17 Nov 2009

Hi,

C P wrote:
I guess I could just code around this, but I wasn't sure if it was a bug or something I was doing incorrectly.

I'd certainly discourage coding around it - much better to identify the problem and squish it at source.

All these small text LCDs tend to be based on only a few different controllers, but they can also be wired up differently inside depending on the number of characters and just their own design choice. This means the display RAM doesn't always map to the same characters. I suspect yours just doesn't quite match the ones this was written for first (so less of a bug, more it doesn't yet support this display).

I therefore propose we create a TextLCD "lineup" - a big list of LCDs people have, so people can then identify theirs from the lineup. We can then aim to make sure all of them have a working library, so you can pick up any text LCD you have lying about and make it work without fuss.

I suspect this lineup should take the form of a photo of the front and back, then notes capturing any model number plus any markings, and then any links to where it came from, what is known about it (driver chip, internal configuration etc), plus any "hunches" or discoveries.

I'd therefore propose hijacking this thread, and ask any of you who have a small text lcd (doesn't have to be 16x2) to post this information (don't worry if yours already works, or duplicates; it would still be very useful to post); take some photos, fill in what the facts you *know*, add any hunches etc. We can then knock up some test programs to identify their configurations, and hopefully get a library running on all of them!

I'll take silence as it being a bad idea/low interest, and a load of posts as a good idea/lots of interest in doing this!!

Simon

17 Nov 2009

Hi,

As promised, here is a simple program hack to get the data ram -> display mappings for text lcds based on an HD44780:

All it does is print an incrementing character at each RAM location. Summary (from the code comments):

// A quick hack to write to all the display RAM locations
// in an HD44780 display, to identify which location maps
// to which character.
//
// Instructions:
//  - Change TextLCD pinout as appropriate so it works
//  - Run, and it should fill the screen with characters
//  - Identify what characters are at the start of each row
//
// To determine what address each line starts at, you subtract the 
// ascii code for '0'(48) from the character at the start of each line
//  - see http://www.asciitable.com/
// 
// e.g.
//   +----------------+
//   |0123456789:;<=>?| first char = '0' (48)
//   |XYZ....         | first char = 'X' (88)
//   +----------------+
//  
// So in this case, the RAM offsets are 0 and 40

So for my lcd, here are the results:

This shows the RAM offsets to be:

  • 0
  • 40

And the LCD has the markings:

  • 162B-D Rev A
  • BANNSAN BS-6
We got them in bulk from the same people who manufacture our mbeds - Chris may know the original source.

Please have a go at running this test program on your LCDs!

Simon

17 Nov 2009 . Edited: 24 Nov 2009

 

I got the same results 0 and X.

sparkfun part# LCD-09052

info sticker on the back of the board:

2009-4-3

ADM1602K-NSW-FBS/3.3V

QC OK

I can not upload photo's so here is a link to front and rear of the lcd.

front:  http://cpinetree.com/LCD/IMG_1393.jpg

rear: http://cpinetree.com/LCD/IMG_1396.jpg

Thanks Simon,

also in doing a better search today, I came across this:

http://mbed.org/forum/topic/18/?page=1#comment-77

but, I can not seem to load the library to make it compile correctly, I'll keep at it when I have the time, it seems this may be where the answer is.

18 Nov 2009 . Edited: 18 Nov 2009

My LCD Results

This shows the RAM offsets to be:

  • 0
  • 40

And the LCD has the markings:

 

  • Topway (The Manufacturer)
  • LMB202D
  • LMB202DFC

 

 

C P wrote:

I can not upload photo's so here is a link to front and rear of the lcd.(sorry that they are poor quality my camera is giving me fits right now)

 

F.Y.I When you use the upload file manager it will let you upload no problem but when you click import image to post, it gives you the wrong URL, if you just rightclick on the image when you view it in the file manager, and click copy image source, and use that URL to post it will work, saves a trip to imageshack.

22 Nov 2009

I have a display that does not work with the locate() function as described in the original post, which is that the locate() does not allow me to set the column on the second row of my display, however it does work on the first column. Simon's test program does not even run on it, I get a blank display.

The display has a HD44780A/HD44100H chipset -go figure. I've had it at least 10years. It's made by Nanox, part number NDM-1602.

22 Nov 2009

Hi Joe,

Can you confirm that in the test program that the pins match your wiring, or have modified the test program appropriately? We should be able to get the test program running (especially if you say you have something working already).

It'd be great to add another to the lineup!

Simon

22 Nov 2009

Uhhh, yeah, oops. Guess I took the simplicity of mbed for granted and in haste forgot to rearrange the pinout.

So it does indeed work. I get '0' and 'X'  in the first columns of row 0 and 1 respectively.

In my experimentation I notice that the text on the second row to wraps over to the first row if the text is longer than 16 chars. Is this a feature of the TextLCD printf() function? I thought the displays had memory for much larger row/column formats such that the lower row/columns formats would just truncate the extra characters and not wrap. I ask this in case it is a clue to a particular modules compatibility with the TextLCD library.

Joe

23 Nov 2009

Hi Joe,

Good news. Can you post up some pictures etc. We'll then add it to the lineup and see if we can design this TextLCD library properly.

btw, the idea of the TextLCD library was that it wraps to the size of the screen, regardless of underlying behaviour of the driver chip. i.e. wrap right and wrap bottom, so all LCDs would have consistent behaviour.

Simon

24 Nov 2009

Some more info, I have ran the below code, all libraries up to date as of today:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,16,2); // rs, rw, e, d0, d1, d2, d3


int main() {
   lcd.cls();
   lcd.locate(2, 0);               // ROW 1
   lcd.printf("Test Row1");  
   lcd.locate(4, 1);               // Row 2
   lcd.printf("Test Row2");
   
   wait(2);   
      
   lcd.cls();
   lcd.locate(2, 0);               // ROW 1
   lcd.printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");  
   lcd.locate(14, 1);               // Row 2
   lcd.printf("??????");   
     
        }
the output looks like this:

http://cpinetree.com/LCD/IMG_1393.jpg

Its interesting that the question marks do not print in row2, they start in row1 (wrapping from row2) but the lcd.locate(14,1) uses two of the question marks even though they are not printed in that row.

sorry if I am not explaing this clearly hopefully the picture will say it for me.

25 Nov 2009

Hi,

Given this thread, I thought it was about time to start doing the TextLCD library properly. The plan all along was to have a basic Text Display class from which you could derive implementations, meaning minimal code to implement and getting lots of functionality "for free". The idea here is to make porting to new LCDs very easy, and ensure they have common and consistent behaviour.

Them having the same interface also means you can interchange them easily :)

Here is some first cut code to play with:

TextDisplays

It includes two drivers for now, based on:

A base "TextDisplay" class, and two derived classes, "TextLCD" (a 16x2 display as described here), and "Terminal", which is a driver for a terminal emulator such as Teraterm (i.e. it send characters and escape commands over the serial, allowing it to locate, cls, change colour etc, as well as send characters). I also added a "TextDisplays.h" to be able to include them all in one go (more interesting when there are more drivers, or may be redundant!).

Here is the code running, driving both displays at the same time:

The implementation wraps on the right and bottom, and is independent of the actual wrapping/RAM implementation of the LCD. Whilst not as efficient, it will ensure all text lcds will act exactly the same way, which is a brilliant and uncommon plus.

Please feel free to add a port if you have a different display. Note that more displays (e.g. 4x16, 1x8, other driver chips) can be added by deriving from TextDisplay (or TextLCD if it is similar) and implementing/overwriting just the key functions to setup the display and place a character at a specific location.

Please test on your setups and report the results! With photos!

Simon

25 Nov 2009

I plan to do the same for Graphics LCDs at some point, so please mention if you have any Graphics Displays that you have around which could form part of the testing/porting experiments. We should create a lineup of them too.

Simon

25 Nov 2009

I've ordered one of these (DOGL128-6, mono 128x64) and am also thinking about getting an S65 one (132x176x64K).

25 Nov 2009

Hi Igor,

If you get one of the second LCDs, can you also find a datasheet. It'd be good to know what interface and driver chip it uses to get an idea of what model will map on to it.

Other ones I have so far are:

  • Nokia LCD128x128 from Sparkfun
  • QVGA LCD from Embedded Artists

But any others to help determine a good architecture would be welcome!

Simon

25 Nov 2009

I've got a Sharp LM24014H (240x64) graphical LCD kicking around that I'd like to use for something...

www.earthlcd.com/zlcd/downloads/lm24014h.pdf

06 Dec 2009

I hesitate to post this as I am a complete beginner at C and programming microcontrollers. I have been struggling to get locate() to work as expected. Looking at the definition of locate() in TextLCD.h this includes:

  _row = row;
      _column = column;
      int address = 0x80 + (_row * 40) + _column; // memory starts at 0x80, and is 40 chars long per row
      writeCommand(address);

Looking at the HD44780U datasheet this says:

"However, when N is 0 (1-line display), AAAAAAA can be 00H to 4FH. When N is 1 (2-line display), AAAAAAA can be 00H to 27H for the first line, and 40H to 67H for the second line."

After editing my local copy of TextLCD.h to the following my locate() works as expected:

 _row = row;
      _column = column;
      int address = 0x80 + (_row * 0x40) + _column; // memory starts at 0x80, and is 40 chars long per row
      writeCommand(address);

I think the HD44780U may hide this gap (between 40 and 0x40) in the memory map if you allow it to handle the increment of the AC between each write.

Please don't hesitate to let me know if this is wrong.

06 Dec 2009

Nigel,

You get a gold star, this has driven me crazy from the day I got my mbed. THANK YOU!!

This fix solved my problem also, see below for my lcd info:

sparkfun part# LCD-09052

info sticker on the back of the board:

2009-4-3

ADM1602K-NSW-FBS/3.3V

08 Dec 2009 . Edited: 09 Dec 2009

My Winstar WH1602A LCD module arrived in the mail this morning from elexol. It cost $20 AUD (with some other items for $13 freight).

After a bit of playing, I realised that the pins go 15,16,1,2,...,13,14. (15 = A, 16 = K). After I noticed this I did some shuffling, and it's working perfectly now.

Battery: LCD's Vin is connected to 5-6v (Vin of the mbed), the Vo (contrast adjustment) grounded via 3x 1k8 resistors in series (5k4 ohms).

It's too faint when connected to USB (Vin is around 4v), but fine when Vo is grounded. Any ideas on keeping it the right contrast? (Vout at 3.3v is too faint)

09 Dec 2009

Alex,

when conected to USB power you can age about 4.5v - 5v of mben pin 39 (VU)

if you conect your contrast pin (check data sheet if not known) on the LCD to VU and it should be darker

09 Dec 2009

I'm hoping to have it roughly the same contrast across both battery and USB power - VU goes to a pretty low voltage when run with only USB power, so it's not really an option.

I hope this clarifies things :)

07 Jan 2010 . Edited: 07 Jan 2010

Hi, i´m using an 20*4 LCD but have some problems with locate function .

Here are the results

First test went ok:

#include "mbed.h"
#include "TextLCD.h"


TextLCD lcd(p24, p25, p26, p27, p28, p29, p30, 20, 4); // rs, rw, e, d0, d1, d2, d3 , 20*4 LCD

int main() {

  lcd.locate(0,0);
    lcd.printf("1234567890");

    lcd.locate(0,1);
    lcd.printf("1234567890");

}

 

 

Second test Have some problems with the locate function, it seems that does not work for a 20*4 lcd

 

#include "mbed.h"
#include "TextLCD.h"


TextLCD lcd(p24, p25, p26, p27, p28, p29, p30, 20, 4); // rs, rw, e, d0, d1, d2, d3 , 20*4 LCD

int main() {

  lcd.locate(0,0);
    lcd.printf("1234567890");

    lcd.locate(0,1);
    lcd.printf("1234567890");
   
    lcd.locate(0,2);
    lcd.printf("1234567890");
   

}

 

 

Third test, It seems that locate well the column 19 but the text does not continue in next line 

 

#include "mbed.h"
#include "TextLCD.h"


TextLCD lcd(p24, p25, p26, p27, p28, p29, p30, 20, 4); // rs, rw, e, d0, d1, d2, d3 , 20*4 LCD

int main() {

  lcd.locate(0,0);
    lcd.printf("1234567890");

    lcd.locate(0,1);
    lcd.printf("1234567890");
   
    lcd.locate(19,1);
    lcd.printf("123");
   

}

 

 

Fourth test the test will work ok for a 20*2 lcd, for example if  the text start as column 16 when it reach the end at 20 it will go fine to next line and continue the text

 

#include "mbed.h"
#include "TextLCD.h"


TextLCD lcd(p24, p25, p26, p27, p28, p29, p30, 20, 4); // rs, rw, e, d0, d1, d2, d3 , 20*4 LCD

int main() {

  lcd.locate(16,0);
    lcd.printf("1234567890");
}

 

 

It seem this library as a problem for 4 line lcd, it works great for 20*2 lcd but not with 20*4

 

It will be nice the experts to fix that

Please tell me if i´m doing something wrong

 

 

 

 

 

 

 

 

19 Jan 2010 . Edited: 19 Jan 2010

Hi, i've this LCD from Sparkfun http://www.sparkfun.com/commerce/product_info.php?products_id=709 and it comes with http://www.sparkfun.com/commerce/product_info.php?products_id=258 incorporated, so i only need 3 pins.

In Arduino i was using the next code, but i don't know translate it to Mbed compiler. Please help me.

void setup()
{
  Serial.begin(9600);
  backlightOn();
}

void loop()
{
  selectLineOne();
  delay(100);
  Serial.print("CyberHades.com");
  delay(1000);
  clearLCD();
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(128, BYTE);    //position
}

void clearLCD(){
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(0x01, BYTE);   //clear command.
}

void backlightOn(){  //turns on the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(157, BYTE);    //light level.
}
19 Jan 2010

I have the same module, it turns a standard LCD to a serial enabled LCD screen. What you are doing is just sending serial data via the tx and rx pins.

Here is a project that sets the bootsplash of the LCD on this exact module. Try it out and I will try and port your code.

http://mbed.org/users/unixblackhole/programs/5yrov

19 Jan 2010

Havn't tested it, but this should work: Sparkfun-SerLCD

19 Jan 2010

 

Vlad Cazan wrote:

Havn't tested it, but this should work: Sparkfun-SerLCD

Hi Vlad, thanks,  the lcd don't work still with your code, but your idea i think it's good. I will go on trying and share my code with you.

 

 

19 Jan 2010

 

Outl4w - wrote:

Hi Vlad, thanks,  the lcd don't work still with your code, but your idea i think it's good. I will go on trying and share my code with you.

 

Make sure you connect the TX pin to the RX pin on the mbed, and the RX to the TX on the mbed, not TX>TX, RX>RX