-
3 Attachment(s)
Interfacing with Arduino I2C LCD
I bought one of these Arduino I2C 20x4 LCD modules.
I got the LCD module in today. It has a slightly different back board, but that's not a bad thing. They extended the A0, A1 & A2 slave address pins out to solder/short PCB pads. This will affect the advertised address from 7 bit address of 0x27 (A0:A2 all "1"s) to a 7 bit address of 0x20 (A0:A2 all "0"s). Shorting the jumper pads ties the pin(s) to +5V. At least the modules slave addresses can be easy to change and set... that's a good thing! I was expecting to get stuck with a fixed slave address.
Again, the web site is wrong about the advertised module address - it is 0x20 as shipped, not 0x27, at least for the module they sent me.
Past that, it's using a basic I2C bi-directional I/O expander IC - PCF8574T.
Addressing the module is pretty strait forward, though the data byte being sent needs to be constructed as follows:
LCD runs in 4 bit mode - DB4 : DB7 are data bits - DB0 : DB3 are not connected at all.
Data Byte sent via I2C:
bit7 = B/L LED (0=on; 1=off)
bit6 = RS (Register Select)
bit5 = R/W (Read/Write)
bit4 = E (Enable)
bit3 = DB7 data
bit2 = DB6 data
bit1 = DB5 data
bit0 = DB4 data
All the normal commands are available under HD44780 datasheet, including 2-way communication with module.
BTW, the soldering was very good when I got it. Due to my test probe use to confirm the hookup, it looks worse then when I got it.
-
Re: Interfacing with Arduino I2C LCD
Do you want to share your PBP code? Or is this just an advertisement?
-
Re: Interfacing with Arduino I2C LCD
Wow, really? :rolleyes:
Seems what I've shared is at least relevant considering this question has been asked before... in light of the answers offered.
This is the documentation section, right?
My code is embarrassing. I'm sure anyone can read what I've posted and come up with much better code then I did. Frankly I'm not up for the criticism about how I wrote it... seeing your comments, I'm glad I didn't post it.
-
Re: Interfacing with Arduino I2C LCD
Quote:
Frankly I'm not up for the criticism about how I wrote it... seeing your comments, I'm glad I didn't post it.
Norohs,
so what was the point of your post?? Seems reasonable to me to want to see your code.
I've been around here a while and have not ever noticed "criticism" regarding someone elses code. Constructive help, yes. Suggestion on how to improve, yes.
If someone posts here with a real intent to learn and ask for help... they always get it.
You, on your third post, have managed to be rude and condecending to someone here who has over 5 thousand posts to their credit.
No the sheer number of posts does not grant someone special status. But why would you assume someone is going to criticize your code??
Strange way to start a life in a fourm :confused:
-
Re: Interfacing with Arduino I2C LCD
Quote:
Originally Posted by
Heckler
You, on your third post, have managed to be rude and condecending to someone here who has over 5 thousand posts to their credit.
None of which have been critical or condescending.
-
Re: Interfacing with Arduino I2C LCD
Quote:
Originally Posted by
dhouston
None of which have been critical or condescending.
Agreed +1.
-
Re: Interfacing with Arduino I2C LCD
Norohs,
If you have seen any of my code you will see that I am the last on to criticize others code. You original post seemed like it could have been an advertisement, if it was it should be moved to another section.
Being it was to show a project working, then posting your code could help someone. Do not worry about what your code looks like or how inefficient you think it is. As long as it works. Sometimes that is all someone needs.
-
Re: Interfacing with Arduino I2C LCD
Quote:
it should be moved to another section.
Feel free to move it.
-
Re: Interfacing with Arduino I2C LCD
Code:
'ARDUINO IIC LCD GY-LCD-V1
'PIC 12F629
'PRINTS " HELLO RCG!_"
Define OSC 20
DEFINE I2C_SLOW 1
CMCON = $7
OPTION_REG.7 = 0
C VAR GPIO.1
D VAR GPIO.0
ADDR VAR BYTE
ADDR = $40
CMD VAR BYTE
LCD_CMD VAR BYTE
E VAR LCD_CMD.BIT4
RS VAR LCD_CMD.BIT6
E=0:RS=0
LCD_CMD = 0
PAUSE 1000
LCD_CMD = $2
GOSUB LCDWRITE
GOSUB LCDWRITE
LCD_CMD = $8
GOSUB LCDWRITE
LCD_CMD = $0
GOSUB LCDWRITE
LCD_CMD = $E
GOSUB LCDWRITE
LCD_CMD = $0
GOSUB LCDWRITE
LCD_CMD = $6
GOSUB LCDWRITE
RS=1
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $48
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $45
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $4C
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $4C
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $4F
GOSUB LCDWRITE
LCD_CMD = $42
GOSUB LCDWRITE
LCD_CMD = $40
GOSUB LCDWRITE
LCD_CMD = $45
GOSUB LCDWRITE
LCD_CMD = $42
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $43
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $47
GOSUB LCDWRITE
LCD_CMD = $42
GOSUB LCDWRITE
LCD_CMD = $41
GOSUB LCDWRITE
RETURN
LCDWRITE:
I2CWRITE D,C,ADDR,[LCD_CMD]
E=1
I2CWRITE D,C,ADDR,[LCD_CMD]
E=0
I2CWRITE D,C,ADDR,[LCD_CMD]
RETURN
END
-
Re: Interfacing with Arduino I2C LCD
Has anyone done this?
I have downloaded the Aduino LCD libraries and there are differences between them and the above code.
-
Re: Interfacing with Arduino I2C LCD
Just curious where RETURN right before LCDWRITE subroutine returns to?
Don't have one to test.
Robert
-
Re: Interfacing with Arduino I2C LCD
Quote:
Originally Posted by
Demon
Just curious where RETURN right before LCDWRITE subroutine returns to?
Don't have one to test.
Robert
From what I have read the code is correct in that it will print to the LCD on a one shot basis then return to nowhere.
Return to nowhere?
Does anyone have one to test?
Having used serial LCDs which were easy to use by sending ascii commands and data using serout2 these look very difficult. I just wonder why make something difficult when there is an easier way.
I have done more research and I believe that all Arduino I2C LCDs are not the same. I guess it depends on the manufacturers implementation and the chips used on the backpack.
-
Re: Interfacing with Arduino I2C LCD
So I'm not missing a label then, the code just isn't terminated "properly".
I kept going through it thinking I was missing something obvious.
Robert
-
Re: Interfacing with Arduino I2C LCD
Quote:
Originally Posted by
Demon
I kept going through it thinking I was missing something obvious.
Robert
Not that I can see but then I always wonder if I am missing something whether it is obvious or not.
Code:
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $48
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $45
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $4C
GOSUB LCDWRITE
I have been trying to work out what the $44 do because they are not printed on the screen.
-
Re: Interfacing with Arduino I2C LCD
Can't find info on $44, and can't see what's in this zip on my phone:
https://bitbucket.org/fmalpartida/ne...stal/downloads
I'd be curious to see all the stuff in version 1.2.1.
Robert
-
Re: Interfacing with Arduino I2C LCD
Quote:
Originally Posted by
Demon
Compare this code with Darrel's the one obvious issue is that the LCD is in 4 bit mode which requires the upper nibble and lower nibble to be sent separately. One other concern is that of setting the RS bit for data mode which is done once after initialisation. Does this not need doing every time a data nibble is sent?
-
Re: Interfacing with Arduino I2C LCD
Is it pure coincidence that all the upper nibbles are $4?
-
Re: Interfacing with Arduino I2C LCD
I believe this may be my first post to this forum...
Has anyone figured more of this out? I finally got my I2C serial adapter for the 1602 LCD to do something at least.
It was indeed very helpful to see the original code posted. Somehow my default address is $40.
When I use the code provided, I do get the display to light up and display "HELLO RCG! but when I try to change the initials to DHD, using the hex codes for D = $44, H=$48, and D=$44, I get THD in the display.
I am also looking for a bit more help with the control characters, and why the LCDWRITE routine needs 3 i2cwrite commands.
Thanks from noob Dave
-
Re: Interfacing with Arduino I2C LCD
-
Re: Interfacing with Arduino I2C LCD
-
Re: Interfacing with Arduino I2C LCD
Great, thank you. Lots of information in those posts.
-
Re: Interfacing with Arduino I2C LCD
Hmm, I am still having difficulty with this even after reading the above referenced threads.
I am working with PBP 3.0.7.0 and a pic 12F629. I am able to get the code writen by norohs (above) to work but I am having difficulty figuring it all out so that I can modify it for my own use.
Basically, I'd like to send some data and or ascii from my 12F629 to my LCD1602 via the I2C "adapter".
Can someone give me a bit more guidance?
-
Re: Interfacing with Arduino I2C LCD
you might get something from this
http://support.melabs.com/threads/1075-I2C-to-LCD
or tell us more on what your trying to achieve and post your code (in code tags)
-
Re: Interfacing with Arduino I2C LCD
I also found this code written by norohs difficult to work out and eventually I decided that it works more by accident than design and that there has to be a better way of doing this. This is what I worked out.
The LCD works in four bit mode which makes every byte sent a four bit control nibble plus a nibble of data. To send a byte of data two bytes have to be sent consisting of a control nibble plus high data nibble then control nibble plus low data nibble.
To send "H" which is $48
requires two LCDWRITE instructions
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $48
GOSUB LCDWRITE
In each instruction the first 4 after the $ sets the R/W bit to write and $48 is made up from the 4 and 8 in red.
and "D" would be
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
and to print "DHD" would be
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $48
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
Looking at the LCDWRITE
LCDWRITE:
I2CWRITE D,C,ADDR,[LCD_CMD]
E=1
I2CWRITE D,C,ADDR,[LCD_CMD]
E=0
I2CWRITE D,C,ADDR,[LCD_CMD]
RETURN
each command is sent three times with E=0 then E=1 then E=0 which I think is an error, the first line is not needed.
LCDWRITE:
E=1
I2CWRITE D,C,ADDR,[LCD_CMD]
E=0
I2CWRITE D,C,ADDR,[LCD_CMD]
RETURN
but you can test this.
Why send it twice? On the LCD with the E bit set to 1 the data is loaded into a buffer and E has to change from 1 to 0 for the data to be transferred to the screen which is why the second instruction is required.
I decided to look for a better solution as I was not totally confident that the above was correct.
Darrel Taylor came to the rescue here
http://support.melabs.com/threads/98...F8574-20x4-LCD
As you can see from this not all Arduino LCDs are wired the same. The control and data nibbles can be either data/control or control/data.
johncouture worked this out for us in the thread above.
-
Re: Interfacing with Arduino I2C LCD
EarlyBird2, your reply has helped me understand this a bit more. I was able to get the norohs code to work without the initial I2CWRITE command as you suggested.
Darrel Taylor's program seems to be a work of art but I think with the INCLUDE, it's just too big for my 12F629 as I am getting, "Unable to fit variable" errors.
I have been able to use the lcdout command to write data to my LCD1602. My goal is to do the same with the i2cwrite command.
I will try to get a better understanding of how to send the control commands by studying Darrel's code.
I think what I am trying to figure out is...
Hey, you need to initialize the LCD to nibble / 4 bit mode by sending I2CWRITE commands with code $xx, ...
then to turn on the backlight you need to I2CWRITE $yy (mabe needs 2 commands for high and low nibbles)
to send data you need to I2CWRITE highNibble, then I2CWRITE lowNibble...
I will reread the thread you referenced, http://support.melabs.com/threads/98...F8574-20x4-LCD
-
Re: Interfacing with Arduino I2C LCD
Quote:
Darrel Taylor's program seems to be a work of art but I think with the INCLUDE, it's just too big for my 12F629 as I am getting, "Unable to fit variable" errors.
I did not realise you were using a pic12f the dt code won't work on those chips because
Quote:
ARRAYWRITE is not supported on 12-bit core PIC MCUs due to RAM and stack
constraints
-
Re: Interfacing with Arduino I2C LCD
I believe Darrel Taylor was using a 12F1822. Doesn't that have the same "bit core" as my 12F629?
According to the Microchip datasheet on the 12F1822,
"This family of devices contains an enhanced mid-range 8-bit CPU core"
-
Re: Interfacing with Arduino I2C LCD
The PIC numbering system was getting me confused so I spoke to an engineer at Microchip and this is what I was told...
The 12 in the 12F629 means it is an 8 pin chip. (I didn't ask why 12 means 8 or why they just didn't just call it an 8Fxxx)
The 6 after the F means that it has a 14 bit memory core, since anything other (? # > 5) has a 14 bit memory core.
A 12F5xx chip would be an 8 pin chip with a 12 bit memory core...
So it does not seem to a 12-bit core problem but rather an overall memory problem.
The 12F629 has 1k x 14 memory (there's that 14 bit core again), where as
the 12F1822 has 2K 14 memory.
I ordered some 12F1822s to see if I can get Darrel's program working.
-
Re: Interfacing with Arduino I2C LCD
Here is the thread in which I believe Darrel was using a 12F1822.
Post #3
http://support.melabs.com/threads/98...F8574-20x4-LCD
-
Re: Interfacing with Arduino I2C LCD
Hmmm, unfortunately, I just figured out that my Silver version of PBP3.0 doesn't support the 12F1822...
-
Re: Interfacing with Arduino I2C LCD
a pic12f1xxx is an enhanced midrange device . they have twice the stack capacity of a 12f6xx device , apart from more memory etc ....
-
Re: Interfacing with Arduino I2C LCD
Thanks to everyone that helped out.
I have gotten a modified version of Darrel's code to run on a 12F683 which has 2K of memory. :D
I am using an LCD 1602 and I don't see any Jumping Jacks.
Code:
; Filename : 632-I2C-LCD for 12F683.pbp
; Author : Darrel Taylor
; Created : Mon Feb 24 2014
; : May 27, 2015 adapted for the 12F683
; Processor : PIC12F683
; Compiler : PicBasic Pro 3.0.7.x or higher
; Description : Uses PCF8574 Port expander to interface with HD44780 LCD
;
;----[Oscillator Setup]---------------------------------------------------------
define OSC 20
define I2C_SLOW 1
;----[Aliases]------------------------------------------------------------------
SDA VAR GPIO.0 ; I2C Data pin
SCL VAR GPIO.1 ; I2C Clock Pin
;----[Initialize Hardware]------------------------------------------------------
ANSEL = 0 ; Make Analog inputs digital
';----[Setup LCD using PCF8574 Port Expander]------------------------------------
LCD_Addr CON $40 ; A0, A1, A2 grounded
true con 1
false con 0
INCLUDE "LCD_PCF8574.pbp" ; Init LCD using I2C and PCF8574
;----[Variables]----------------------------------------------------------------
LoopCount VAR BYTE
CustChar VAR BYTE
;----[Program Start]------------------------------------------------------------
Backlight = 0 ; Turn on LCD Backlight
LoopCount = 0
ARRAYWRITE LCD_Buff,[" LCD PCF8574"] : LCD_WriteBuff
;----[Custom Characters]-(Jumping Jacks)----------------------------------------
ARRAYWRITE LCD_Buff,[$FE,$40,$00,$04,$0A,$04,$0E,$15,$0A,$11]:LCD_WriteBuff ' #0
ARRAYWRITE LCD_Buff,[$FE,$48,$00,$04,$0A,$04,$1F,$04,$0A,$0A]:LCD_WriteBuff ' #1
ARRAYWRITE LCD_Buff,[$FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]:LCD_WriteBuff ' #2
;----[Main Program Loop]--------------------------------------------------------
Main:
ARRAYWRITE LCD_Buff,[$FE,$C0,"Count = ",DEC LoopCount," "] : LCD_WriteBuff
PAUSE 200
LoopCount = LoopCount + 1
CustChar = LoopCount//3 ; Jumping Jacks Sequence
ARRAYWRITE LCD_Buff,[$FE,$9D,CustChar] : LCD_WriteBuff
GOTO Main
-
Re: Interfacing with Arduino I2C LCD
Commented out the lines...
ARRAYWRITE LCD_Buff,[" LCD PCF8574"] : LCD_WriteBuff
and
ARRAYWRITE LCD_Buff,[$FE,$C0,"Count = ",DEC LoopCount," "] : LCD_WriteBuff
Changed the $9D to a $C0 in
ARRAYWRITE LCD_Buff,[$FE,$C0,CustChar] : LCD_WriteBuff ' $C0 was $9D
and now the little guy is doing Jumping Jacks in the lower left hand corner.
Thanks again!
-
Re: Interfacing with Arduino I2C LCD
I am trying to make this code work with a 16F629A and all I get is a blinking back light with the modified code below.I am probably missing something simple?
Thanks,
; Filename : Test_LCD_PCF8574.pbp
; Author : Darrel Taylor
; Created : Mon Feb 24 2014
; Processor : 16F629A
; Compiler : PicBasic Pro 3.0.6.x or higher
; Description : Uses PCF8574 Port expander to interface with HD44780 LCD
;
;----[16f629A Hardware Configuration]-------------------------------------------
#config
__config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_ON & _BODEN_OFF
#endconfig
;----[Aliases]------------------------------------------------------------------
SDA var porta.7
SCL var porta.6
;----[Initialize Hardware]------------------------------------------------------
CMCON = 7 'CHANGES PORTA TO DIGITAL
;----[Setup LCD using PCF8574 Port Expander]------------------------------------
LCD_Addr CON $7E
INCLUDE "LCD_PCF8574.pbp" ; Include LCD module for PCF8574
;----[Variables]----------------------------------------------------------------
LoopCount VAR BYTE
CustChar VAR BYTE
;----[Program Start]------------------------------------------------------------
Backlight = 0 ; Turn on LCD Backlight
ARRAYWRITE LCD_Buff,[" LCD PCF8574"] : LCD_WriteBuff
LoopCount= 0
;----[Custom Characters]-(Jumping Jacks)----------------------------------------
ARRAYWRITE LCD_Buff,[$FE,$40,$00,$04,$0A,$04,$0E,$15,$0A,$11]:LCD_WriteBuff ' #0
ARRAYWRITE LCD_Buff,[$FE,$48,$00,$04,$0A,$04,$1F,$04,$0A,$0A]:LCD_WriteBuff ' #1
ARRAYWRITE LCD_Buff,[$FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]:LCD_WriteBuff ' #2
;----[Main Program Loop]--------------------------------------------------------
Main:
ARRAYWRITE LCD_Buff,[$FE,$C0,"Count = ",DEC LoopCount," "] : LCD_WriteBuff
PAUSE 200
LoopCount = LoopCount + 1
CustChar = LoopCount//3 ; Jumping Jacks Sequence
ARRAYWRITE LCD_Buff,[$FE,$C0,CustChar] : LCD_WriteBuff
GOTO Main
-
Re: Interfacing with Arduino I2C LCD
I did delete these two lines
ARRAYWRITE LCD_Buff,[" LCD PCF8574"] : LCD_WriteBuff
ARRAYWRITE LCD_Buff,[$FE,$C0,"Count = ",DEC LoopCount," "] : LCD_WriteBuff
and Change this line
ARRAYWRITE LCD_Buff,[$FE,$C0,CustChar] : LCD_WriteBuff ' $C0 was $9D
-
Re: Interfacing with Arduino I2C LCD
16F629A ?
might you mean 12f629 ?
if so you need to set the " lcd " pins to digital
-
Re: Interfacing with Arduino I2C LCD
Sorry, I should have said 16F628A. I did set my pins as digital? I want to display data from my program but that seems far away at this point?? I cut the program down to the below lines and I get a custom character and a blinking cursor the backlight stays on. I guess that is progress ?
Thank You!
;----[16f628A Hardware Configuration]-------------------------------------------
#config
__config _INTOSC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_ON & _BODEN_OFF
#endconfig
SDA var porta.7
SCL var porta.6
;----[Initialize Hardware]------------------------------------------------------
CMCON = 7 'CHANGES PORTA TO DIGITAL
;----[Setup LCD using PCF8574 Port Expander]------------------------------------
LCD_Addr CON $7E
INCLUDE "LCD_PCF8574.pbp" ; Include LCD module for PCF8574
ARRAYWRITE LCD_Buff,[$FE,$50,$04,$0A,$15,$0E,$04,$0A,$0A,$00]:LCD_WriteBuff ' #2
Main:
GOTO Main
-
Re: Interfacing with Arduino I2C LCD
there is more info here . note the slightly differing versions of the include
INCLUDE "LCD_PCF8574.pbp" ; Include LCD module for PCF8574
INCLUDE "LCD_PCF8574a.pbp" ; Include LCD module for PCF8574
http://support.melabs.com/threads/10...hlight=PCF8574
http://support.melabs.com/threads/10...hlight=PCF8574
ps
LCD_Addr CON $7E is way different to addr used in above threads
-
Re: Interfacing with Arduino I2C LCD
Richard thank you for your help.
I have read most of the threads but will read them again. I will find and download both version of the include. On Arduino this is the Initialization for my display the 3F turns into 7E when you shift the bits one to the left.
"LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)"
I have used serial lcd displays in the past with no issues. So far I am not a fan of this i2c version. I think someone is missing a market for easy to use i2c displays?
Thanks again!
-
Re: Interfacing with Arduino I2C LCD
Quote:
"LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)"
interpreted as [( 7bit_addr, EN, RW, RS, D4, D5, D6, D7, Backlight, POLARITY) ]
the PCF8574 datasheet indicates the 7bit addr range is 0x20--0x27
0x3f is not valid afaik.
default with a0:2 open = 7bit_addr of 0x27 , pbp addr would be $4e