PDA

View Full Version : I2C LCD help needed



kenif
- 12th July 2022, 18:33
During the pandemic I had to lay out boards using the chips to hand, in this case 16F1503.
Not enough pins for a parallel LCDout, so I used I2C LCDs intended for Arduino. How difficult could it be?
I ended up using TTL232 displays, but would like to get the I2C working.

Tried all the snippets on here. Can't find DT's but there is a post with his (possibly modified) library.
Links to PBP3 forum no longer work. I understand I2C and the H27 is really H4E/4F thing.
These are 8x2 using the Ti version of the Phillips T expander.
Anyone with working, commented code?
Thanks.

aerostar
- 13th July 2022, 18:50
Code is modified from Steve Earl have left his code but remmed out stuff I did not use.

Biggest problem is getting the address correct.
Picture is adapter used. (Ebay) LCDs with adapter attached can be ones that the address is fixed.

As it came it was 0x27 Dec 39 but I had to double it for pbp to 0x4e dec 78.
Tried to put the code in code tabs but not all would appear, so I zipped it as picforum.zip

Code is for 12f683 but will/should work with any other pic, just change the ports and pic config

9251

9252

^^^^^^ ZIP File

aerostar
- 15th July 2022, 10:35
Just becareful with lcds that have backpacks already attached, some do not have the SDA SCL pullups on board, hence may not work. I hooked up a lcd with backpack fitted and it would not work until 10Ks were added.

Picture below is the backpack to avoid, apart from the fact you cannot change the address even if you wanted.

9253

kenif
- 16th July 2022, 18:29
Thanks, I'll try this.

> As it came it was 0x27 Dec 39 but I had to double it for pbp to 0x4e dec 78.
$27 is the code not counting the R/W bit. Some people shift this one bit and add the R/W bit making $4E and $4F.
This is clear in the Ti or NXP expander datasheets.

There are pullups on my boards. The signals look clean.

My hardware looks more like this:

9255

richard
- 17th July 2022, 04:57
As it came it was 0x27 Dec 39 but I had to double it for pbp to 0x4e dec 78.
arduino uses a 7bit i2c address , so everything arduino-ish complies with that convention , pbp uses an 8bit i2c address scheme
no big deal just 1 shift left gets there from the 7 bit address.



add the R/W bit making $4E and $4F.
and that is a waste of time and effort, pbp i2c commands set or clear the r/w bit automatically
regardless.

google "pbp ic2 lcd"

you will find dt's version and an alternative for board with wiring variation
there may other variations also
you may need to trace the connections to verify code matches

TrueMetalGeek
- 15th August 2022, 03:29
I've also wanted to use the modern widely available dime-o-dozen LCD's with I2C adapter boards. These things are like $6 all day long on Amazon etc.
I've been searching this forum (and others) for a good 5 years or so. I am stunned that there hasn't been some solid examples posted.

My PIC of choice over the last 10 years has been 16F690
Evidently not that popular and it seems to be going on the verge of being obsolete. But they were nice bang-for-the-buck cheap 20 pin processors. About $2 ea
But I do run out of I/) pins because I often use a 4 bit LCD for debugging or for the project itself.

I wish there was some good sample code to get me started.
I tried a few years ago but was at a dead end.

So I will be watching this post and would like to give it a BUMP for more consideration. :-D

richard
- 22nd August 2022, 06:55
I am stunned that there hasn't been some solid examples posted.

posted 8 years ago
https://support.melabs.com/forum/picbasic-pro-compiler-3-0-and-later/pbp3-picbasic-pro-3-0/773-i2c-pcf8574-20x4-lcd

two versions covering popular variants of i2c backpack [LCD_PCF8574.pbp and LCD_PCF8574a.pbp]

9265

bought one

verified address a0 a1 a2 not grounded therefore $4e
verified lcd data pins on PCF8574 high nibble therefore LCD_PCF8574a.pbp
adjusted Test_LCD_PCF8574.pbp to siut

;----[Setup LCD using PCF8574 Port Expander]------------------------------------
LCD_Addr CON $4e ; A0, A1, A2 tied to ground
INCLUDE "LCD_PCF8574a.pbp" ; Include LCD module for PCF8574
Backlight = 1 ; Turn on LCD Backlight

worked first go



what more could you want


9266