exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

16x2 LCD I2C help

Mon Aug 04, 2014 5:05 am

I have a 1602 lcd screen with PCF8574AP gpio extender. The tutorials I found don't seem to work well with making this lcd I2C compatible. Anyone have any diagrams and code to help me out?

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5619
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: 16x2 LCD I2C help

Mon Aug 04, 2014 3:19 pm

exzile wrote:I have a 1602 lcd screen with PCF8574AP gpio extender. The tutorials I found don't seem to work well with making this lcd I2C compatible. Anyone have any diagrams and code to help me out?
What language? FWIW, I've some 'C' demo-code relating to the I2C backpacks/circuits** I've used or designed. Some links are below:
http://www.cpmspectrepi.webspace.virgin ... plays.html
http://www.cpmspectrepi.webspace.virgin ... erial.html
http://www.cpmspectrepi.webspace.virgin ... e_Backpack
http://www.cpmspectrepi.webspace.virgin ... tware.html
Trev.
** both 4-bit and 8-bit, write only, methods.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Tue Aug 05, 2014 3:09 pm

Writing in python.
I simply just want to hook up the LCD by I2C, but I have no success yet.

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Tue Aug 05, 2014 3:12 pm

I really have this issue with all components. I want to hook many things up by I2C, since I can only have two SPI components. I would like to have an LCD screen, and a few motors, controlled by I2C. Is something like this possible?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 16x2 LCD I2C help

Tue Aug 05, 2014 3:17 pm

You're either going to need to find an existing library for hd44780 LCDs with pcf8574ap as the I2C controller or you'll have to write your own code from scratch and workout your own wiring scheme for the chip to the display.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Wed Aug 06, 2014 4:30 am

I don't know how to program from scratch or even read such a device. Know of any articles or books I can look into to learn how to program hardware like this?

[MOD edit - remove profanity]

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 16x2 LCD I2C help

Wed Aug 06, 2014 3:58 pm

And that, young sir is precisely why the Raspberry Pi is an educational tool. The time to learn something new is upon you. The first lesson is how to ask Dr. Google for help and advice. The second lesson is to learn to moderate your language on a family forum.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 16x2 LCD I2C help

Wed Aug 06, 2014 5:29 pm

exzile wrote:I don't know how to program from scratch or even read such a device. Know of any articles or books I can look into to learn how to program hardware like this?

[MOD edit - remove profanity]
I have edited out the profanity - please consider the other members of the forum before posting.

WRT your question about the LCD and the pcf8574 chip, I designed a breakout board with such a configuration - see this thread
http://www.raspberrypi.org/forums/viewt ... 2&p=478394
The wiring is noted in the program listing.
Hope this helps,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Mon Sep 29, 2014 6:39 pm

Sorry for profanity... when frustration hits!.

I have been doing my research and still have not found anything. If anyone has succeeded with this, please chime in.

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 16x2 LCD I2C help

Mon Sep 29, 2014 6:47 pm

I wrote this code (running in 4-bit mode) to drive an HD44780 on an MCP23S17 (SPI chip) on an Arduino.

Code: Select all

#include <MCP23S17.h>
#include <SPI.h>

// mcp23s17 GPIOB to HD44780 pin map
#define D4 0
#define D5 1
#define D6 2
#define D7 3
#define EN 4
#define RW 5
#define RS 6
#define BL 7

// SCLK = D13, MISO = D12, MOSI = D11, CS = D10
MCP lcd(0);  // A2,A1,A0 == 0b000

void lcdInit() {
  lcd.byteWrite(IODIRB, 0x00);
  lcd.byteWrite(IODIRA, 0xFF);
  delayMicroseconds(50000);
  lcd.byteWrite(GPIOB, (0 << RS, 0 << RW));
  lcd.byteWrite(GPIOB, (0 << EN));
}

void lcdWrite(uint8_t data) {
  lcd.byteWrite(GPIOB, data);
  delayMicroseconds(3);
  lcd.byteWrite(GPIOB, (data | 1 << EN));
  delayMicroseconds(3);
  lcd.byteWrite(GPIOB, (data | 0 << EN));
  delayMicroseconds(31);
}

void lcdBakLite(uint8_t state) {
  lcd.byteWrite(GPIOB, (state << BL));
}
void lcdCommand(uint8_t data) {
  lcdWrite(data | 0x80);
  delayMicroseconds(2000);
}
void lcdData(uint8_t data) {
  uint8_t high_nibble, low_nibble;
  high_nibble = (data & 0xf0) >> 4;
  low_nibble = data & 0x0f;
  lcdWrite(high_nibble | 0xC0);
  lcdWrite(low_nibble | 0xC0);
}

void lcdWrite(const char * message) {
  while (*message) {
    lcdData(*message);
    message++;
  }
}

void setup() {
  lcdInit();
  lcdCommand(0x02);

  //  Func set:
  lcdCommand(0x02);
  lcdCommand(0x08);

  lcdCommand(0x00);
  lcdCommand(0x0f);

  lcdCommand(0x00);
  lcdCommand(0x02);

  //  Entry mode, Increment cursor, no display shift:
  lcdCommand(0x00);
  lcdCommand(0x06);
  delayMicroseconds(2500);

  lcdWrite("Hello Arduino!");
}

void loop() {
 delay(5000);
 lcdBakLite(0);
}
it gives you the basic timings to get a simple string displayed. It should be simple to re-write that for an MCP23017 on an I2C bus with the LCD wired the same way to GPIOB.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Tue Sep 30, 2014 2:50 pm

I am using the I2C bus, as my SPI will be filled up.
I am also using python.

It seems that my PCF chip isn't recognized on the PI if I am using 5V.
But if I put on 3.3V, It registers on the I2C.

Any idea the issue? Maybe hardware?

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5619
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: 16x2 LCD I2C help

Tue Sep 30, 2014 10:53 pm

exzile wrote:I am using the I2C bus, as my SPI will be filled up.
I am also using python.
It seems that my PCF chip isn't recognized on the PI if I am using 5V.
But if I put on 3.3V, It registers on the I2C.
Any idea the issue? Maybe hardware?
Whilst some I2C devices will still respond to 3.3V logic-level outputs** when they are powered by 5V, others do not - either use logic-level shifters (as I did in the circuits previously linked to) or, sometimes, dropping the 5V supply to the device to ~4.4V by inserting a diode in series (as suggested by @mahjongg in other threads) may improve matters.
Trev.
**Do not connect 5V outputs to the Pi's GPIO's!!
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13092
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: 16x2 LCD I2C help

Tue Sep 30, 2014 11:56 pm

also make sure there are no I2C pullups to 5V, remove them! The PI already has 1k8 pullups to 3V3, using pullups to 5V may in the long term be detriment to the health of your PI. If the I/O expander runs from 5V, and isn't responding to 3V3 I2C signals, (because ViH is above 3.3 Volt) lower it's VCC to 4.5 or even to 4.0V using a diode or two in series (check the data sheet if the expander can run from 4V). If all that isn't possible you must use two level translators to convert the 3V3 I2C levels to 5V levels! google for "I2C level translator", its a simple circuit with a single FET, and extra pullups, but you need two.

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 1:01 pm

Now the 3.3v isn't being read. I think I fried the PCF chips. I tested a 3.3v tsl lux sensor on the I2C network and it came up when I did the i2cdetect.

I ordered 2 new PCF chips.

I do not have any resistors in series with the PCF chip.

I have never had any experience with using a level shifter. Should I get a couple of these http://www.adafruit.com/products/757
or these
http://www.ebay.com/itm/I2C-TRN-V2-Bidi ... 5d4945e2f2

And I just want to state what I am doing again:
Hooking up a 16x02 LCD display (Adaftruit) to my Raspberry Pi via I2C, using a PCF8574 port expander.

If you guys have a schematic I can see with what I should do to get this working, that would be cool, as I am more of a visual person.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5619
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 2:47 pm

[quote="exzile]
...
And I just want to state what I am doing again:
Hooking up a 16x02 LCD display (Adaftruit) to my Raspberry Pi via I2C, using a PCF8574 port expander.
If you guys have a schematic I can see with what I should do to get this working, that would be cool, as I am more of a visual person.[/quote]
I.E., probably similar to what I did here:
http://www.cpmspectrepi.webspace.virgin ... erial.html
or, perhaps, more like the circuit of the I2C backpacks here:
http://www.cpmspectrepi.webspace.virgin ... D_Backpack
with some more info. here:
http://www.cpmspectrepi.webspace.virgin ... _Interface
The first is an 8-bit parallel interface, using some GPIO pins for the "control signals" and I2C for the 8-bit data. The I2C backpacks use I2C for both the control signals and 4-bit data. (The control chip in the display supports both methods)
Schematics and examples of logic-level shifters/translators are also shown.
Trev.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 5:47 pm

so if I build the back pack "LCD Backpack I2C/Serial Interface" from the link you gave me, I can hook that up that up to the LCD and finally see it in the I2Cdetect?

Or

What if I buy this http://www.dx.com/p/funduino-iic-i2c-16 ... Cw9oWd0x9A
Than could I just hook it up with out the work of building one myself?

Also would I still need to use a level shifter?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 5:57 pm

That should just work from the I2C bus with nothing else needed (apart from some programming).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 6:12 pm

DougieLawson wrote:That should just work from the I2C bus with nothing else needed (apart from some programming).
What exactly are you referencing to?

I am trying to keep this the simplest I can. Has no one hooked up this LCD to a Pi and had it working yet?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 6:51 pm

exzile wrote:
DougieLawson wrote:That should just work from the I2C bus with nothing else needed (apart from some programming).
What exactly are you referencing to?

I am trying to keep this the simplest I can. Has no one hooked up this LCD to a Pi and had it working yet?
The item you've found on DX has a I2C interface on the underside. I2C shouldn't need level shifters. I doubt anyone else has ever tried one.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 7:51 pm

OK so that DX one should be plug and play ready I take it from your response.
I will pick that one up.

Have any of you ever connected the 1602 LCD screens by I2C personally? Without a backpack?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 9:04 pm

My LCD has an SPI interface with an MCP23S17 chip as a GPIO driver.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 9:31 pm

There is a 16x2 LCD with I2C interface advertised for sale by Ryanteck Ltd.

The webpage I have linked to includes a reference to some code which the author says works with the module he is selling.

I have bought one of these modules from this site and tested it OK with an Arduino in I2C mode. I have not tested it with an RPi, but if the device is like the one you own you might find the code useful.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5619
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: 16x2 LCD I2C help

Wed Oct 01, 2014 9:35 pm

exzile wrote:
DougieLawson wrote:That should just work from the I2C bus with nothing else needed (apart from some programming).
What exactly are you referencing to?
I am trying to keep this the simplest I can. Has no one hooked up this LCD to a Pi and had it working yet?
The simplest LCD backpack that requires "minimal programming" is this one, AFAIK:
http://www.cpmspectrepi.webspace.virgin ... ackpack_V2 **
(although it does require a level-shifter for I2C, IIRC).
I suspect the one you're referring to uses this type of backpack (hardwired to the back of the display):
http://www.cpmspectrepi.webspace.virgin ... D_Backpack which uses the 4-bit interface protocol.
Trev.
** More info. here: http://www.hobbytronics.co.uk/lcd/i2clcd-backpack-v2
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, 2xB2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, and a A+) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

exzile
Posts: 132
Joined: Sun Jul 20, 2014 5:33 am

Re: 16x2 LCD I2C help

Thu Oct 02, 2014 1:13 pm

Thanks for the help guys.

Is there a complete guide that has all the components
  • I need and a schematic to get it working?
    I see the backpack guide but it does not involve the level shifter. Was hoping to get everything complete.

    I would use the SPI, but that bus is fully occupied.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: 16x2 LCD I2C help

Fri Oct 03, 2014 7:35 am

I have now tried the 16x2 LCD with I2C interface advertised for sale by Ryanteck Ltd. on my RPi running Raspbian.

It works using the code linked from that page.

The only thing I needed to add was a 4-way female-female jumper lead between the module and the RPi GPIO header.

The display module seems to be a standard HD44780 16x2 display with 16-pin connector. Pre-soldered to those 16 pins is an additional board labelled "YwRobot Arduino LCM1602 IIC V1". This presents a 4-pin I2C interface to the outside world. The only active component on the board seems to be a chip labelled PCF85741.

That seems to be a simple way to meet your requirement.

Return to “Interfacing (DSI, CSI, I2C, etc.)”