I2C LCD Display

Steve2381

Senior Member
Anyone had any experience with these?

http://www.ebay.co.uk/itm/161107072069?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

I picked one up... but info seems a little on the vague side. Searched I2C LCD but didn't really come up with anything.

Found the command set - no idea what most of it means:

###########################################
# Syntax Coloring Map For LiquidCrystal_I2C
###########################################

###########################################
# Datatypes (KEYWORD1)
###########################################

LiquidCrystal_SR KEYWORD1
LiquidCrystal_I2C KEYWORD1
LiquidCrystal_SR3W KEYWORD1
LiquidCrystal KEYWORD1
LCD KEYWORD1

###########################################
# Methods and Functions (KEYWORD2)
###########################################
begin KEYWORD2
clear KEYWORD2
home KEYWORD2
noDisplay KEYWORD2
display KEYWORD2
noBlink KEYWORD2
blink KEYWORD2
noCursor KEYWORD2
cursor KEYWORD2
scrollDisplayLeft KEYWORD2
scrollDisplayRight KEYWORD2
leftToRight KEYWORD2
rightToLeft KEYWORD2
moveCursorLeft KEYWORD2
moveCursorRight KEYWORD2
autoscroll KEYWORD2
noAutoscroll KEYWORD2
createChar KEYWORD2
setCursor KEYWORD2
print KEYWORD2
write KEYWORD2
println KEYWORD2
backlight KEYWORD2
noBacklight KEYWORD2
on KEYWORD2
off KEYWORD2
setBacklightPin KEYWORD2
setBacklight KEYWORD2
###########################################
# Constants (LITERAL1)
###########################################
POSITIVE LITERAL1
NEGATIVE LITERAL1
BACKLIGHT_ON LITERAL1
BACKLIGHT_OFF LITERAL1

Looks like some long evenings!
 

erco

Senior Member

AllyCat

Senior Member
Hi,

Is this going to work similar to the AXE033?
No, I don't think so. That "backpack" is an 8-wire I2C expander. Four of the wires go to a 4-bit data bus ("parallel mode"), the others to Enable, Read, Command and LED (backlight) control lines. The I2C Slave address can be configured by linking a few pads on the front of the backpack, but I believe the default is $4E ($20 - $27, plus the trailing Write bit).

So you need a moderately complex subroutine to write each data byte as two separate nybbles, whilst setting the control lines and pulsing the Enable line. This is the pin mapping that I found on a similar 2 row version:

Code:
Symbol  DB4       = bit4      ; LCD Data Line 4
Symbol  DB5       = bit5      ; LCD Data Line 5
Symbol  DB6       = bit6      ; LCD Data Line 6
Symbol  DB7       = bit7      ; LCD Data Line 7

Symbol  RS        = bit0      ; 0 = Command   1 = Data bit 
Symbol  RD        = bit1      ; 0 = Write     1 = Read
Symbol  E          = bit2      ; 0 = Idle      1 = Active
Symbol  LED       = bit3

Symbol LCD_ADR       = $4E      ; I2C address of LCD
I got a two-row version working from a PICaxe, but the full code is not in a form that I'd like to share at the moment. The initialisation (to the 4-bit bus mode?) was not always reliable. :eek:

Cheers, Alan.
 
Last edited:

Steve2381

Senior Member
Yea... thought it was going to be a challenge. Perhaps its time to add Arduino to my talents list.
I will investigate further
 

Steve2381

Senior Member
Erco - That exact $1.66 board is bolted to the back of the LCD module using a 16 pin header. The display has the 16 pins marked -

VSS, VDD, V0,RS, RW, E, D0,D1,D2,D3,D4,D5,D6,D7,A,K

Its going to be easier to just connect directly to those parallel connections surely (I can never remember which is serial and which is parallel!)

Edit... its just a shame, as I am trying to save as many pins as possible on my 40x2... i2c would have been very handy
 
Last edited:

westaust55

Moderator
@Steve,

there have been a few past threads (not too distant past) about LCD displays with an i2c IO expander chip as the background.
There are a few variants so you need to know exactly which pin does what for you i2c interface and which IO Expander chip is used (Philips or Microchip typically).

Try a forum search for the other/past threads as they may help you.
 

Rick100

Senior Member
Edit... its just a shame, as I am trying to save as many pins as possible on my 40x2... i2c would have been very handy
Hello Steve2381,

I don't have your exact display but I've used the 8574 IO expander chip to drive an lcd. Working from the info on this page I have some test code you can try.
http://arduino-info.wikispaces.com/LCD-Blue-I2C#v1
If your display is wired like this one the code should work but not all these boards are wired alike. I've tried it on a breadboard and it works with a 4X20 display. These I2C displays are useable but not as user friendly as a serial display or as fast as a parallel setup. I'm using one with an 08m2 and an I2C RTC board. The RTC board and display share the I2C lines so it doesn't cost any IO pins.

View attachment i2CLCD_08M3.bas

Good luck,
Rick
 

AllyCat

Senior Member
Hi,

Yes, that code works with my very similar version (imported direct from China), also on an 08M2. The pin mapping and Slave Address are the same as I posted in #4, and are as listed in the "Demonstration Sketch" on the 4tronix website (linked from the ebay listing).

The only change I made was to add a BL = 1 at the start of main: to turn on the backlight so I could see the text. ;) Also, the Pause 2 (milliseconds) after the Clear Screen might not always be long enough, but seems to work on mine.

Cheers, Alan.
 

Steve2381

Senior Member
Thanks guys. I will give it a shot and try your suggestions. Even if it doesn't work, it will be a learning curve.
 

Rick100

Senior Member
Thanks Alan for trying the code. My display doesn't have a back-light so I didn't notice the InitLcd routine was overwriting the BL bit. I worked on the program some more today. I removed some unnecessary delays and changed some others so it would work up to 32 MHz. I also changed the pulse enable line code to use one hi2cout command. The result was a slight improvement in speed. I tested it at 4,8,16, and 32 Mhz.
Here's the improved code.

View attachment i2CLCD_08M5.bas
 

Steve2381

Senior Member
OK. Tired and blurry eyed.... excuse if I am being thick.

Just to get this project underway, I have removed the I2C board for now and put that aside for some investigative treatment.

The remaining LCD board - which I believe is this one http://arduinos.ecrater.com.au/p/16996077/2004a-lcd-screen-j204a-character .. appears to be a single parallel display

Excuse the rough coding - its been lifted and altered from another program:

Code:
dirsA = %00000000								;1=Output   0=input
dirsB = %11111111			
dirsC = %00000000		
dirsD = %11000000




symbol lcddata = pinsb							;Display data lines
symbol rs = d.6								;Display register select
symbol enable = d.7							;Display enable pin


Startup_message:

	low rs
	lcddata = 127 : pulsout enable,1				;Pulse the enable pin
	high rs								        ;Switch to data mode
	for b4 = 0 to 15
	lookup b4,("Testing 12345678"),lcddata
	pulsout enable,1
	next

pause 5000
Checked all the connections.... no joy. Any ideas?
 

Rick100

Senior Member
Just some quick thoughts. Put a pause 2000 before Startup_message. Make sure you have the RW line tied low. Change 'lcddata = 127' to 128.
 
Last edited:

westaust55

Moderator
The schematic showing how you have connected the LCD to the PICAXE and full code would help greatly.

From the bits of code I see:
Using a single PICAXE port with 2 control lines on that port so using 4-bit mode.

You do not show any initialization code

Your loop to send out a message is sending complete bytes with a single pulse to latch/transfer the data. This will not work for 4-bit mode. You need to take each (4-bit) Nybble from the byte and transfer one at a time with a data latching pulse.
 

Steve2381

Senior Member
I think I basically then have it all wrong. I connected it the way I connected my last parallel display.
4 bit mode? Is that where it only uses pins D4-D7 on the display and the others are tied low?

Still looking to find a data sheet for this J204A display. I think I will dismantle this breadboard and start again.

I thought that parallel displays always needed all 8 pins connected - D0-D7 on the display.

As for initialisation.... mmm, that is pretty much non existent. Don't remember what I used last time.

I will investigate further
 

westaust55

Moderator
Yes, 4-bit mode only uses D4 to D7
See link I gave at post 16

Sorry just looked again Andy eyes are playing up. You have the two control lines on port D not B so. 8-bit mode is tentatively connected.
But you must still initialize the display first.
 

Steve2381

Senior Member
Use this initialisation code from the link (I had this ... but it must have got lost when I copy/pasted the code from another program)...

Code:
dirsA = %00000000								;1=Output   0=input
dirsB = %11111111			
dirsC = %00000000		
dirsD = %11000000


symbol lcddata = pinsb							;Display data lines
symbol rs = d.6								;Display register select
symbol enable = d.7							;Display enable pin

pause 2000


start:
	low rs								'instruction mode
	output enable							'set enable pin as output
	
	lcddata = %00111011 : pulsout enable,16			'Function Set: 8-bit, 2 lines, font 11
	lcddata = %00000001 : pulsout enable,608			'Clear display
	lcddata = %00001100 : pulsout enable,608			'Display on/off control: Display on, cursor off, blink off
	lcddata = %00000110 : pulsout enable,16			'Entry mode set: Increment, cursor shift
Still doesn't do anything.
 

Steve2381

Senior Member
Got it.....

lcddata = 127 : pulsout enable,1 ;Pulse the enable pin.

Should be:

lcddata = 128 : pulsout enable,1 ;Pulse the enable pin

The simplest things! Thanks for your advice guys
 

Steve2381

Senior Member
Is it madly complicated to explain the initialisation code? What I mean by that is I don't quite understand how it 'sets' up the font etc

My display is 4 lines, so I imagine I need to initialise it for 4 lines.... not the 2 lines it currently is being told.

I think I need the data sheet for this J204A display. Off Googling I go....

Edit:

OK.. I found an appallingly badly translated data sheet that I 'think' is the correct one. Not much help to me....

http://www.wayengineer.com/download/SAMSUNGpdf/YX-2004A.zip

Time to send random code and note the results
 
Last edited:

Rick100

Senior Member
Even though your display has 4 physical lines it only has 2 logical lines. Heres a good link that explains the addressing.
http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html
Here's a link explaining the initialization.
http://web.alfredstate.edu/weimandn/lcd/lcd_initialization/lcd_initialization_index.html

The instructions used are explained on this page under instruction set.
http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller

To interpret the instructions it helps to display them in binary. The leftmost '1' will determine the instruction. So a '1' in bit 7 with RS and RW set to 0 will set the DDRAM address to the value of the lower bits. The next time you write to the display with RS = 1 the character will show up at that address.
So to set the cursor to the top left position write a 128 (binary 10000000) to the display with RS = 0.

Don't get hung up on the exact data sheet. If you already have it displaying something, you'll probably be OK with the data in the above links.

Good luck,
Rick
 

AllyCat

Senior Member
Hi,

AFAIK, this extract is from hippy's original code on which most other (PICaxe) versions seem to be based:
Code:
      Eeprom 0,( $33 )    ; %0011---- %0011----   8-bit / 8-bit
      Eeprom 1,( $32 )    ; %0011---- %0010----   8-bit / 4-bit

      ' Byte commands - To configure the LCD

      Eeprom 2,( $28 )    ; %00101000 %001LNF00   Display Format
      Eeprom 3,( $0C )    ; %00001100 %00001DCB   Display On
      Eeprom 4,( $06 )    ; %00000110 %000001IS   Cursor Move

                          ; L : 0 = 4-bit Mode    1 = 8-bit Mode
                          ; N : 0 = 1 Line        1 = 2 Lines
                          ; F : 0 = 5x7 Pixels    1 = N/A
                          ; D : 0 = Display Off   1 = Display On
                          ; C : 0 = Cursor Off    1 = Cursor On
                          ; B : 0 = Cursor Steady 1 = Cursor Flash
                          ; I : 0 = Dec Cursor    1 = Inc Cursor
                          ; S : 0 = Cursor Move   1 = Display Shift

      Eeprom 5,( $01 )    ; Clear Screen
The 8-bit to 4-bit command is the "difficult" part; it needs to be sent several times to ensure that the LCD always ends in 4-bit mode regardless of its initial state.

Then, it's just three bytes to setup the display and the cursor. There is no command for 4 rows of text; row 3 is an "extension" of line 1, and 4 an extension of row 2, i.e. if you write past column 20 then the characters are written into the extension row (e.g. column 21 becomes column 1, etc..

Cheers, Alan.
 

RonnS

Member
oh fine , i think this helps me to clear my oled problem too, i have used the winstar WS0010 datasheet but the second Display-line dont wont work
 

Steve2381

Senior Member
Got this all worked out I think. Basically there are not too many settings to adjust anyway.

One question, and as soon as you tell me the answer I will realise I probably knew already.. what is the 608 at the end of this line achieving?

lcddata = %00001100 : pulsout enable,608
 

Rick100

Senior Member
Is it just me, or does all this I2C nonsense make a serial LCD look like it's worth paying a bit extra for? :)

Here in the states last year, Radio Shack has had numerous clearance sales, closing out valuable goodies at amazing prices. They blew out Parallax serial LCDs for $5 (long gone now):
I think he took the i2c backpack off and is working on a parallel interface now. It only slightly harder and a little slower to use the i2c interface than a 4 bit parallel interface. It definitely not as easy as using the serial displays. I saw your original post about the Radio Shack sale and picked up 3 of the Parallax displays and a lot of other goodies. Thanks for the info.

If you want a good example of 8 bit parallel lcd code, look at the AXE133 firmware here:
http://www.picaxe.com/Hardware/Add-on-Modules/Budget-Serial-LCD-Module/

Look at the "Standard LCD Module Initialisation" for the initialization code.
 

westaust55

Moderator
Is it just me, or does all this I2C nonsense make a serial LCD look like it's worth paying a bit extra for? :)

Here in the states last year, Radio Shack has had numerous clearance sales, closing out valuable goodies at amazing prices. They blew out Parallax serial LCDs for $5 (long gone now): http://forums.parallax.com/showthread.php/149327-RadioShack-Pushes-to-Clear-Inventory?p=1210166&viewfull=1#post1210166
Serial is generally the easiest - just use the SEROUT command.
However, some folks buy LCD modules with say default baud rates of 9600 bps and have grief then end up here with questions. There quite a few such threads for the Sparkfun LCD with serial backpack that defaults to 9600 bps.

Parallel interfaces are relatively easy as the vast majority use a controller that is Compatible with the Hitachi chip and the LCD connections are fairly standardized so there plenty of do home ration for PICAXE and other microcontrollers.
Again that does not stop some folks coming to grief.

I2C interfaces areas common and one obstacle is many are bought from EBay with negligible documentation. There are various i2c interface chips utilized and there is the option for designers to assign different i2c chip pins to different LCD purposes so that code which will work for one may not work for the next.
Again in recent months there have been several threads on this forum where help has been sought.

It comes down to people trying to save dollars/euro/pounds (or other sheckle of the realm) and having limited experience.

Having experience and by reading the datasheets one can pretty much guarantee success.
I have even built LCD interfaces using 1-wire chips and 2-wire shift register base methods.
But everyone must start somewhere - on day 1 you an not a "guru".
 
Last edited:

Steve2381

Senior Member
I binned the I2C module (for now). Just don't have the time available for hours of fiddling and programming to make it work.
I will however have a go. Basically I got the I2C LCD display because it was 4x20, blue with white lettering (which I needed) and a good price.
Its just in parallel mode, I have to be a bit more careful of my pin usage.
 

Steve2381

Senior Member
LCD all working fine.... but stupid question ahead

Snippet of my code:

gosub clear4
low rs
lcddata =212 : pulsout enable,1
high rs
lcddata countloop
pulsout enable,1

How do I get the second to last line to send (and show) the actual value of 'countloop' to the display, and not display the ascii character for that number.
 

srnet

Senior Member
Lookup the bintoascii command in the manual

Converts a binary value into ASCII characters (3 for a byte) which you need to send to the display seperatly.
 
Top