Go Down

Topic: 16x2 RGB LCD and MCP23017 (Read 7253 times) previous topic - next topic


Greetings all!

I'm attempting to connect a 16x2 RGB LCD (from Adafruit) to my Arduino Uno using an MCP23017 I2C port expander. I think I've got the wiring correct, and I'm trying to use the LiquidCrystal_I2C library from F Malpartida, but I'm running into some roadblocks.  I'm able to get the LCD to light up, contrast pot to work, and I can see the MCP23017 if I use the I2C scanner sketch, so I think I've got all of that correct. However, I modified the "hello world" I2C sketch that came with the LiquidCrystal_I2C library to match the correct address for the port expander and the pins for the LCD, but no dice. I'm hoping someone can take a look at my wiring diagram and my sketch and maybe give me an idea of what I'm doing wrong.

Here's the wiring schematic:

And here's the sketch:

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

LiquidCrystal_I2C lcd(
 0x20,  // address (found with I2C scanner)
 4,     // E(nable)
 5,     // R/W
 6,     // RS (Reset)
 3,     // D4
 2,     // D5
 1,     // D6
 0,     // D7
 7,     // Backlight (just put this in)
 NEGATIVE);    // Backlight Polarity

// 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
 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);


The i2c i/o expander code in fm's library currently only works with a PCF8574.
The MCP23017 (expanded version of a MCP23008) uses different registers and a different message interface so
unfortunately the current code in fm's library won't work with that chip.

--- bill


Well that sucks :(

Outside of writing my own library specifically for the MCP23017, is anyone aware of another library that's available that will work with the two? I suppose I could go get a PCF8574 instead but since I've already got a couple 23017's, I'd kind of like to use them instead of I can.


I have an updated experimental pre-release version of fm's library that
has support for the mcp23008.
PM me your email address and we can discuss further offline if
you are interested.

--- bill


I might take you up on that at a later date...for now I'll just order a couple PCF8574's.  Thanks!


Adafruit has a library for the MCP23008, for their I2C LCD backpack. The MCP23008 is basically a MCP23017 with only 8 channels. It should be easy to adapt.

Go Up