
What language? FWIW, I've some 'C' demo-code relating to the I2C backpacks/circuits** I've used or designed. Some links are below: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?
I have edited out the profanity - please consider the other members of the forum before posting.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]
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);
}
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.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?


What exactly are you referencing to?DougieLawson wrote:That should just work from the I2C bus with nothing else needed (apart from some programming).
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.exzile wrote:What exactly are you referencing to?DougieLawson wrote:That should just work from the I2C bus with nothing else needed (apart from some programming).
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:exzile wrote:What exactly are you referencing to?DougieLawson wrote:That should just work from the I2C bus with nothing else needed (apart from some programming).
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?