Go Down

Topic: Question about connecting an LCD via PCF8574 (Read 4576 times) previous topic - next topic

Luftlandeapotheker

Good evening everybody!

I'm quite new with the Arduino and I have a question on connecting a display via I2C.
I made myself a PCB with an PCF8574 to connect a 16*2 LCD-Display. Unfortunately, the example "Hello world" does not work.

The problem is, that my board has different connections than other boards.
The Pins from the PCF8574 are connected as follows:
P0 ---> RS
P1 ---> Enable
P2 ---> R/W
P3 ---> Backlight via a Transitor
P4 ---> DB4
P5 ---> DB5
P6 ---> DB6
P7 ---> DB7

The addressing works, I have tested it with a port scanner and I can swith the backlight on an off.
The display also works, I have tested it in serial mode.
I'm using the LiquidCrystal_I2C-Library, there I can define RS,Enable and R/W.

But is there a also a possibility to change the allocation of the Pins DB4 to DB7 in the libary?

Thanks for your help!
Greetings
Matthias

johnwasser

I guess you would have to modify the LiquidCrystal_I2C::send() function to re-map the bits before sending them.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

fm

Check the "New LiquidCrystal" library out. You will be able to configure the pins when you create the "variable" to control the LCD.

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

You also have wiring diagrams and some examples.
   

Luftlandeapotheker

Thanks for the link!
That seems to be a lot of work for me until I get that in my mind..
For now I took the easy way and etched a new PCB with the "correct" connecions. I'll try how the "New LiquidCrystal" library works.


fm

It shouldn't be that hard to get it going with my library.

Hi have taken the pin-out that you've posted and created a lcd object (variable) and only changing the that in the example that comes with the library "HelloWorld_i2c".

I am assuming that you are using the PCF8574 so it's base address is 0x20. If it doesn't work used 0x38 which is for the PCF8574A.

Give this code a shot, just need to download the library and replace the stock Arduino library with it. Make a backup of the stock library somewhere that is not in the Arduino library folder.
Code: [Select]

#include <Wire.h>
#include <LiquidCrystal_I2C.h>



#define BACKLIGHT_PIN     13

//LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address

//LiquidCrystal_I2C lcd(0x38, BACKLIGHT_PIN, POSITIVE);  // Set the LCD I2C address

// Constructor with backlight control
//   LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
//                     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
//                     uint8_t backlighPin, t_backlighPol pol);
LiquidCrystal_I2C lcd ( 0x20, 1, 2, 0,
                        4, 5, 6, 7,
                        3, POSITIVE );


// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
   
};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );
 
  lcd.begin(16,2);               // initialize the lcd

   for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();                   // go home
  lcd.print("Hello, ARDUINO "); 
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print (" FORUM - fm   ");
  delay ( 1000 );
}

void loop()
{
   lcd.home ();
   // Do a little animation by writing to the same location
   for ( int i = 0; i < 2; i++ )
   {
      for ( int j = 0; j < 16; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
   }
   delay (200);
}


This is the line I've added:
Code: [Select]

// Constructor with backlight control
//   LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
//                     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
//                     uint8_t backlighPin, t_backlighPol pol);
LiquidCrystal_I2C lcd ( 0x20, 1, 2, 0,
                        4, 5, 6, 7,
                        3, POSITIVE );


and commented out this one:
Code: [Select]

LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address
   

soldierkam

You can use modified version of LiquidCrystal_I2C (see attachment).
I changed a few defines and method LiquidCrystal_I2C::send

Go Up